-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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 for combination of conditionals #52622
Comments
Here's a godbolt link to some code you might find interesting. The topmost source editor is the LLVM IR you pasted here with one interesting change: the Removing the problematic assume instructions seems to be a relatively easy case; walk through assume operands (with some bounds to prevent time blowup), then kill the assume if none of them are used after the assume (i.e. there are no code paths from the assume that influence its operands after it). This could be done with a simple dominance check, so nothing too bad here. The rest of the code is similar to the C++ sample at the bottom. This seems like it could be a missing case in |
Another repro, which doesn't get the After optimizations it ends up as define noundef zeroext i1 @_ZN7example4demo17h8aa2bedc8aa1e47fE(i8 noundef %x, i8 noundef %y) unnamed_addr #1 {
%0 = icmp eq i8 %x, 3
br i1 %0, label %bb1, label %bb3
bb1: ; preds = %start
%1 = icmp eq i8 %y, 3
br label %bb7
bb3: ; preds = %start
%.not = icmp ne i8 %y, 3
%2 = icmp eq i8 %x, %y
%spec.select = and i1 %.not, %2
br label %bb7
bb7: ; preds = %bb3, %bb1
%.0 = phi i1 [ %1, %bb1 ], [ %spec.select, %bb3 ]
ret i1 %.0
} Which https://alive2.llvm.org/ce/z/RmgVaQ confirms could just be %0 = icmp eq i8 %x, %y
ret i1 %0 Direct repro for whether |
rustc emits the following LLVM-IR:
Original IR
which after optimization becomes
I believe this is a missed optimization, and it would be correct to compile the function into a simple equality check on the inputs. This is however my first time reading llvm-ir, so I could also be wrong; please let me know if so.
I have tested this on both the rustc LLVM artifacts and on godbolt using trunk. If I should provide anymore metadata, please let me know. This example is the result of compiling fairly idiomatic Rust, and I can provide other similar (but probably ultimately equivalent) examples if needed.
The text was updated successfully, but these errors were encountered: