[llvm] [llvm][GVN] Propagate `trunc nuw to i1` equalities (PR #143273)
Andreas Jonson via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 7 12:05:31 PDT 2025
================
@@ -2579,6 +2579,22 @@ bool GVNPass::propagateEquality(Value *LHS, Value *RHS,
continue;
}
+
+ // Propagate equality that result from truncation with no unsigned wrap
+ // like (trunc nuw i64 %v to i1) == "true" or (trunc nuw i64 %v to i1) ==
+ // "false"
+ if (auto *Trunc = dyn_cast<TruncInst>(LHS)) {
+ if (Trunc->hasNoUnsignedWrap() && Trunc->getType()->isIntegerTy(1)) {
+ Value *Input = Trunc->getOperand(0);
+ if (ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
----------------
andjo403 wrote:
it is already know that RHS is a ConstantInt with the values 0 or 1 here so this if statment can be removed.
https://github.com/llvm/llvm-project/pull/143273
More information about the llvm-commits
mailing list