powf not inlining or optimizing in builtin implementation (cf. Rust, clang) #12032
Labels
backend-llvm
The LLVM backend outputs an LLVM IR Module.
bug
Observed behavior contradicts documented or intended behavior
Milestone
Uh oh!
There was an error while loading. Please reload this page.
Zig Version
0.9.0 (Godbolt)
Steps to Reproduce
This behaviour can be verified e.g. by implementing the generic Minkowski distance and compiling the instances with order 1 (equivalent to Manhattan distance) and order 2 (equivalent to Euclidean distance). Make sure to enable optimizations with fast math.
It can be done in Godbolt:
-O ReleaseFast
)-O3 -ffast-math
)--release
arg)In this case, compare the deassembled outputs.
Expected Behavior
std.math.powf
should be inlined and optimized out where applicable (i.e. where the compiler can guarantee safe behaviour, and thus simply use the equivalent oflibm
'spowf
).The first- and second-order instances of the generic Minkowski function should be automatically optimized into specific algorithms by the compiler. This can be most easily verified by checking that the assembly versions of both cases are short and don't contain
call
, and that only the 2nd-order case containsvsqrtss
(since in the first-order case, allpowf
calls are passed an exponent of 1 and can be safely optimized out).Actual Behavior
In Zig 0.9.0, the Minkowski function is neither inlined, much less optimized, in the specific cases of orders 1 and 2, as a result of the compiler failing to inline and optimize out
std.math.pow
.The text was updated successfully, but these errors were encountered: