Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minimal inlining of x^Val{p} for p=0,1,2,3 and x::Number #20648

Merged
merged 7 commits into from
Feb 18, 2017

Conversation

stevengj
Copy link
Member

@stevengj stevengj commented Feb 17, 2017

This PR does very basic inlining of x^Val{p} for p=0,1,2,3 and x::Number (a much more restrictive version of #20637).

It should fix the performance regression of #20530.

It also dispatches ^(x,p) = internal_pow(x,p) and defines internal_pow(x, Val{p}) as suggested by @timholy, in order to avoid dispatch ambiguities for code that specializes ^ on the first argument.

@stevengj
Copy link
Member Author

@nanosoldier runbenchmarks(ALL, vs = ":master")

@kshyatt kshyatt added maths Mathematical functions performance Must go faster labels Feb 17, 2017
@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels

@stevengj
Copy link
Member Author

Running the benchmarks one more time to see whether the two regressions were noise:

@nanosoldier runbenchmarks(ALL, vs = ":master")

@@ -76,6 +76,8 @@ Language changes
* Experimental feature: `x^n` for integer literals `n` (e.g. `x^3`
or `x^-3`) is now lowered to `x^Val{n}`, to enable compile-time
specialization for literal integer exponents ([#20530]).
`x^p` for `x::Number` and a literal `p=0,1,2,3` is now lowered to
Copy link
Contributor

@innerlee innerlee Feb 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p=0,1,2,3,...

edit: when first read, i thought these four numbers are specialized.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are?

Copy link
Member Author

@stevengj stevengj Feb 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, only these four exponents are inlined by this patch. It's a minimal PR to match (and slightly exceed) what inference.jl did before. In the future, we may well want to inline more exponents.

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels

@stevengj
Copy link
Member Author

Also want to run the benchmarks against the commit before #20530:

@nanosoldier runbenchmarks(ALL, vs = "@d8ac581f474d5d0f0c032594b46fd1ed84b042f3")

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels

@StefanKarpinski
Copy link
Member

Is the array comprehension slowdown legitimate here or an artifact of some other change?

@vtjnash
Copy link
Member

vtjnash commented Feb 18, 2017

I've been seeing that in other recent benchmarks reports. I think it's noise, since it looked like the generated code was identical.

@stevengj
Copy link
Member Author

If it's noise, is this okay to merge?

@StefanKarpinski StefanKarpinski merged commit 6c6bbba into JuliaLang:master Feb 18, 2017
@stevengj stevengj deleted the inlinepow0 branch February 18, 2017 21:35
@@ -504,6 +504,9 @@ end
^(x::BigFloat, y::Integer) = typemin(Clong) <= y <= typemax(Clong) ? x^Clong(y) : x^BigInt(y)
^(x::BigFloat, y::Unsigned) = typemin(Culong) <= y <= typemax(Culong) ? x^Culong(y) : x^BigInt(y)

# override default inlining of x^2 etc.
^{p}(x::BigFloat, ::Type{Val{p}}) = x^Culong(p)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this gives an InexactError for negative powers, such as BigFloat(2) ^ -20 (which was amazingly not tested)

(wrong line beforehand)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed by #20732

stevengj added a commit to stevengj/julia that referenced this pull request Feb 22, 2017
stevengj added a commit to stevengj/julia that referenced this pull request Feb 22, 2017
stevengj added a commit to stevengj/julia that referenced this pull request Feb 22, 2017
tkelman added a commit that referenced this pull request Apr 21, 2017
#20648 was partially reverted by #20782
tkelman added a commit that referenced this pull request Apr 22, 2017
#20648 was partially reverted by #20782
tkelman added a commit that referenced this pull request Apr 23, 2017
* run NEWS-update.jl

#20648 was partially reverted by #20782

* Fix doctest line numbers

* Upgrade Documenter, add linkcheck exception

bugs.kde.org fails to load from nanosoldier for some reason,
gives a CURLE_RECV_ERROR (56) Failure with receiving network data

fix alloc.c dead link in devdocs/init.md

* fix timeit_init macro in test/perf/perfutil.jl

needed to escape its arguments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maths Mathematical functions performance Must go faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants