-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missed optimization: extra branch with slicing and integer overflow checks #58692
Comments
Slightly reduced testcase:
LLVM does not realize that |
Ok, looks like the thing to do is file an LLVM bug -- do you know off hand if they're ok with Rust reproducers, or do they prefer C ones? |
Ok, ended up converting to C because that seemed easy: https://bugs.llvm.org/show_bug.cgi?id=40845 |
Submitted https://bugs.llvm.org/show_bug.cgi?id=40846 additionally for the IR pattern above (which is an issue separate from the missing add.with.overflow+sub.with.overflow combining). Just verified that fixing this does indeed eliminate the |
@nikic am I correct in reading that this has been waiting on a review of the LLVM patch? |
@alex Needs a rebase. More generally though, I think this is fighting a losing battle. uadd.with.overflow and usub.with.overflow are not considered canonical IR for a reason: They optimize badly in the middle end. I think we'd be better off with generating the canonical variants instead (which are As we already have a good benchmark for the overhead of overflow checks in #58475, I think it might be worth trying to rerun that without using the unsigned overflow intrinsics. |
From the second LLVM bug above:
🎉 |
🎉 once this makes it's way into Rust's LLVM (is there a good way to track this?) I'll verify that the assembly in this bug was improved, and if so I'll rebase the rustc patch and we can get some new numbers! |
Ok, confirmed that the recent LLVM10 update removes this branch: https://rust.godbolt.org/z/B38vDX Shall this be closed? |
Actually, that was probably premature. We should add a codegen test. |
@Mark-Simulacrum is there a good example of what a test looks like? I can spin one up pretty easily if someone can point me at how to add one. |
@alex Codegen tests are located in src/test/codegen. One test that is thematically related: slice-position-bounds-check.rs. They use LLVM FileCheck to verify generated LLVM IR. Codegen tests can be run with: ./x.py test --stage 1 src/test/codegen |
Thanks much, that's exactly what I needed! PR is up now. |
Added a codegen test for a recent optimization for overflow-checks=on Closes rust-lang#58692
Added a codegen test for a recent optimization for overflow-checks=on Closes rust-lang#58692
Added a codegen test for a recent optimization for overflow-checks=on Closes rust-lang#58692
Added a codegen test for a recent optimization for overflow-checks=on Closes rust-lang#58692
Godbolt: https://rust.godbolt.org/z/PXY1lr
Basically the issue is that you compute
s.position + n
, check that it doesn't overflow, and then you verify thats.position + n
is greater thans.position
, which it of course always is, since you checked for an overflow! This is probably an LLVM optimization bug, but I'm starting here :-)Command line arguments:
-C opt-level=3 -C debug-assertions
Source:
ASM:
The text was updated successfully, but these errors were encountered: