-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 with match on repr(i8) enum #106459
Comments
Godbolt: https://rust.godbolt.org/z/3qqrhehTr We do handle the general pattern: https://llvm.godbolt.org/z/7MndEd3an The problem here is that the zext could also be an sext due to the range restriction. |
Though this one could also be solved by converting the phi into sext in InstCombine already -- pretty sure we needed that to solve some more general cases of this problem. |
In particular the case where we don't have range metadata can't be solved by just folding the add/zext/add pattern. We either need to recognize sext in simplifyUsingControlFlow(), or directly produce sext when SimplifyCFG removes the switch. |
We have llvm/llvm-project#54561 for this case and llvm/llvm-project#59671 for a more complicated case with an extra |
Added mir-opt because we could consider recognizing simple matches like this in MIR as well, replacing them with https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/enum.Rvalue.html#variant.Discriminant. That might have the advantage that we have a Rust type, and thus can tell whether to look for sext or zext of the values. |
Transforms match into an assignment statement Fixes rust-lang#106459. We should be able to do some similar transformations, like `enum` to `enum`. r? mir-opt
This should have said "sext could also be a zext". This should be very easy to fix now, because it will be a |
Although, we need to fix that. But I found that transformation on switch is also appropriate. I can expand the original issue into the following kinds.
https://rust.godbolt.org/z/KTsc53bqz The first transformation did not make better use of the UB and could not continue the transformation after it became a compare instruction. Although I can handle both scenarios in LLVM, but I can make the transformation easier in Rust by utilizing the sign information of the integers. |
Transforms match into an assignment statement Fixes rust-lang#106459. We should be able to do some similar transformations, like `enum` to `enum`. r? mir-opt
I created an issue for this: llvm/llvm-project#88348. |
@rustbot claim |
The following functions ought to be equivalent:
but compile to the following x86_64 assembly on play.rust-lang.org:
for both stable (1.66.0) and nightly (1.68.0-nightly 2023-01-03 c757267).
The text was updated successfully, but these errors were encountered: