Dead code/instructions generated to detect divide by zero #44500
Labels
A-LLVM
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
I-slow
Issue: Problems and improvements with respect to performance of generated code.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
This is born out of https://users.rust-lang.org/t/division-by-nonzero/12822.
The gist is the following function:
generates the following x86_64 assembly:
https://godbolt.org/g/8eh61N
As far as I can tell, that division cannot panic. If that's true, then the following inefficiences are present:
testq
andje
instructions are essentially dead.I don't know the innards of LLVM, but perhaps the non-zero/non-wrapping aspect isn't conveyed to LLVM here? Or perhaps it's not able to figure it out on its own based on whatever IR is given to it.
The text was updated successfully, but these errors were encountered: