-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
[InstCombine] Missed fold: umax(x *nuw 2, x + 1)
=> x == 0 ? 1 : x *nuw 2
#122388
Comments
This also applies for saturating mul: https://godbolt.org/z/WPKohs7hT #[inline(never)]
pub unsafe fn src1(x: usize) -> usize {
std::cmp::max(x.saturating_mul(2), x + 1)
}
#[inline(never)]
pub unsafe fn tgt1(x: usize) -> usize {
match x {
0 => 1,
_ => x.saturating_mul(2),
}
} define noundef i64 @src(i64 noundef %x) {
%_6.0 = shl nuw i64 %x, 1
%_6.1.inv = icmp sgt i64 %x, -1
%_2.sroa.0.0 = select i1 %_6.1.inv, i64 %_6.0, i64 -1
%_3 = add i64 %x, 1
%_0.sroa.0.0.sroa.speculated.i = tail call noundef i64 @llvm.umax.i64(i64 %_2.sroa.0.0, i64 %_3)
ret i64 %_0.sroa.0.0.sroa.speculated.i
}
define noundef i64 @tgt(i64 noundef %x) unnamed_addr #0 {
%z = icmp eq i64 %x, 0
%_4.0 = shl nuw i64 %x, 1
%_4.1.inv = icmp sgt i64 %x, -1
%spec.select = select i1 %_4.1.inv, i64 %_4.0, i64 -1
%_0.sroa.0.0 = select i1 %z, i64 1, i64 %spec.select
ret i64 %_0.sroa.0.0
} |
Where does this pattern occur? |
In the exponential growth calculation for Rust's |
Another pattern |
Hi, I'm new to LLVM, and I'm interested in this issue. Could you assign it to me? Thank you. :) |
https://godbolt.org/z/TEzxx8vbj
https://alive2.llvm.org/ce/z/ijq6ZJ
The text was updated successfully, but these errors were encountered: