-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow constant-folding intrinsics that are non-pure for inference only
Any constants produced during inference must be *exact* (in the === to what would have been produced at runtime sense). As a result, we disallow constant folding the sqrt intrinsic, since we can't guarantee that this will be the case (depending on what LLVM decides to do). However, this does not apply to the optimizer (and in fact we do it all the time by inlining pure functions here). Thus, for code size, inlining heuristics and non-LLVM backends, enable the optimizer to constant fold sqrt. Before: ``` julia> f() = sqrt(2) f (generic function with 1 method) julia> @code_typed f() CodeInfo( 1 ─ %1 = Base.Math.sqrt_llvm(2.0)::Float64 └── return %1 ) => Float64 julia> @code_typed optimize=false f() CodeInfo( 1 ─ %1 = Main.sqrt(2)::Float64 └── return %1 ) => Float64 ``` After ``` julia> @code_typed f() CodeInfo( 1 ─ return 1.4142135623730951 ) => Float64 julia> @code_typed optimize=false f() CodeInfo( 1 ─ %1 = Main.sqrt(2)::Float64 └── return %1 ) => Float64 ``` Note that we are not able to infer `Const`, but still inline the constant in the optimized version of the IR.
- Loading branch information
Showing
3 changed files
with
40 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters