-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Missing fold (X == 0) | (trunc nuw X to i1) -> true
#134093
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
Comments
Is there any way to easily trace that back to the input rust? It reminds me of the pattern I'm fixing in rust-lang/rust#139098 (comment) but I don't know if it actually is -- it has the same shape, but in that issue LLVM doesn't actually have enough information to be able to fix it itself. |
Original pattern ( |
llvm-opt-benchmark has a fuzzy pattern matcher to check if a pattern exists in real-world applications. |
Looking at this again, it makes me think of the normalization question I mentioned back in https://discourse.llvm.org/t/rfc-add-nowrap-flags-to-trunc/77453/3?u=scottmcm.
Attempting to think of a way to generalize it: the return is poison if Hmm, maybe there's a way that known bits could use the «only the low bit can be set» from the (Oh, for an e-graph to be able to avoid these normalization questions...) |
You remind me that %x is a load. Unfortunately, the
|
Just checking: You confirmed that it's lost, but was there originally? Because if rustc isn't emitting it in this case, for some reason, I could take a look at fixing that in rustc so that LLVM can just merge all these loads. |
Confirmed. It is a JumpThreading issue. |
feels like adding support for llvm-project/llvm/lib/Analysis/InstructionSimplify.cpp Lines 1906 to 1908 in 1657331
if (Op0->getType()->isIntOrIntVectorTy(1) &&
(match(Op0, m_NUWTrunc(m_Value(A))))) {
Pred = ICmpInst::ICMP_NE;
B = ConstantInt::get(A->getType(), 0);
} else if (!match(Op0, m_ICmp(Pred, m_Value(A), m_Value(B))) ||
!ICmpInst::isEquality(Pred))
return nullptr; do we want to make the fold seems like it solves the problem in the example https://alive2.llvm.org/ce/z/c4KE9B |
That loss of information would, as I understand it, have a major negative impact on Rust. There's a bunch of places where we end up passing around bools as It's only relatively recently that improvements in LLVM finally fixed rust-lang/rust#101210 and I really wouldn't want want's currently free -- thanks to the Similarly, as of rust-lang/rust#137500 rustc uses |
Only from my experience for adding handling of |
As we discussed before, the effort for migrating
Here is my solution for this case:
|
Alive2: https://alive2.llvm.org/ce/z/RN4Sch
It is a variant of #132678. cc @scottmcm
See also dtcxzyw/llvm-opt-benchmark#2234 (comment).
I don't know how to generalize this :(
The text was updated successfully, but these errors were encountered: