julia
ca4375b5 - Allow constant-folding intrinsics that are non-pure for inference only

Commit
5 years ago
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.
References
Author
Committer
Parents
Loading