Missed optimization: When debuginfo is on, is_power_of_two does not imply nonzero. #137359
Labels
A-debuginfo
Area: Debugging information in compiled programs (DWARF, PDB, etc.)
A-LLVM
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
C-bug
Category: This is a bug.
C-optimization
Category: An issue highlighting optimization opportunities or PRs implementing such
needs-triage
This issue may need triage. Remove it if it has been sufficiently triaged.
I compiled the following code (Godbolt):
With
-Copt-level=3 -Cdebuginfo=2
, I got this assembly:In the above assembly, the compiler doesn't realize that
x
being a power of two implies that it is not zero.However, with
-Copt-level=3 -Cdebuginfo=0
, I got this assembly:That is, the compiler correctly optimizes the code to always returning false.
I expect debuginfo to not impact the amount of optimization, so I'm assuming that this is a bug.
Additional context
This was discovered while checking whether
x % y
is optimized wheny
is known to be a power of two.I compiled the following code (Godbolt):
With
-Copt-level=3 -Cdebuginfo=2
, I got this assembly:However, with
-Copt-level=3 -Cdebuginfo=0
, I got this assembly:This seems to imply that LLVM can make use of the fact that
is_power_of_two
returns true to do optimizations. However, for some reason, when debuginfo is on, it can't figure out thatis_power_of_two
implies that the number is not zero.Meta
The issue is reproducible on Godbolt with version info:
@rustbot labels +C-optimization +A-debuginfo
The text was updated successfully, but these errors were encountered: