[llvm] 6e8e8ea - Revert "[InstSimplify] Simplify and/or of trunc nuw to i1 with op replacement"

Andreas Jonson via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 9 13:51:58 PDT 2026


Author: Andreas Jonson
Date: 2026-03-09T21:51:46+01:00
New Revision: 6e8e8eaa3476fb20e68b3b4cfe589bc91294f812

URL: https://github.com/llvm/llvm-project/commit/6e8e8eaa3476fb20e68b3b4cfe589bc91294f812
DIFF: https://github.com/llvm/llvm-project/commit/6e8e8eaa3476fb20e68b3b4cfe589bc91294f812.diff

LOG: Revert "[InstSimplify] Simplify and/or of trunc nuw to i1 with op replacement"

This reverts commit dacb62989db8084cc2865d6b9ef85bbdf34e112d.

Added: 
    

Modified: 
    llvm/lib/Analysis/InstructionSimplify.cpp
    llvm/test/Transforms/InstSimplify/and-or-implied-cond.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 536c25cee736e..4da15280029d9 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -1950,12 +1950,8 @@ static Value *simplifyAndOrWithICmpEq(unsigned Opcode, Value *Op0, Value *Op1,
          "Must be and/or");
   CmpPredicate Pred;
   Value *A, *B;
-  if (Op0->getType()->isIntOrIntVectorTy(1) &&
-      match(Op0, m_NUWTrunc(m_Value(A)))) {
-    B = ConstantInt::getNullValue(A->getType());
-    Pred = ICmpInst::ICMP_NE;
-  } else if (!match(Op0, m_ICmp(Pred, m_Value(A), m_Value(B))) ||
-             !ICmpInst::isEquality(Pred))
+  if (!match(Op0, m_ICmp(Pred, m_Value(A), m_Value(B))) ||
+      !ICmpInst::isEquality(Pred))
     return nullptr;
 
   auto Simplify = [&](Value *Res) -> Value * {

diff  --git a/llvm/test/Transforms/InstSimplify/and-or-implied-cond.ll b/llvm/test/Transforms/InstSimplify/and-or-implied-cond.ll
index 440499d1bfd30..253edc4b8156c 100644
--- a/llvm/test/Transforms/InstSimplify/and-or-implied-cond.ll
+++ b/llvm/test/Transforms/InstSimplify/and-or-implied-cond.ll
@@ -351,7 +351,8 @@ define i1 @and_trunc_nuw_implied(i8 %x, i8 %y) {
 ; CHECK-NEXT:    [[TRUNC:%.*]] = trunc nuw i8 [[X:%.*]] to i1
 ; CHECK-NEXT:    [[SELECT:%.*]] = select i1 [[TRUNC]], i8 [[Y:%.*]], i8 0
 ; CHECK-NEXT:    [[ICMP:%.*]] = icmp ne i8 [[SELECT]], 0
-; CHECK-NEXT:    ret i1 [[ICMP]]
+; CHECK-NEXT:    [[AND:%.*]] = and i1 [[TRUNC]], [[ICMP]]
+; CHECK-NEXT:    ret i1 [[AND]]
 ;
   %trunc = trunc nuw i8 %x to i1
   %select = select i1 %trunc, i8 %y, i8 0
@@ -363,7 +364,10 @@ define i1 @and_trunc_nuw_implied(i8 %x, i8 %y) {
 define i1 @or_trunc_nuw_implied(i8 %x, i8 %y) {
 ; CHECK-LABEL: @or_trunc_nuw_implied(
 ; CHECK-NEXT:    [[TRUNC:%.*]] = trunc nuw i8 [[X:%.*]] to i1
-; CHECK-NEXT:    ret i1 [[TRUNC]]
+; CHECK-NEXT:    [[SELECT:%.*]] = select i1 [[TRUNC]], i8 [[Y:%.*]], i8 0
+; CHECK-NEXT:    [[ICMP:%.*]] = icmp ne i8 [[SELECT]], 0
+; CHECK-NEXT:    [[AND:%.*]] = or i1 [[TRUNC]], [[ICMP]]
+; CHECK-NEXT:    ret i1 [[AND]]
 ;
   %trunc = trunc nuw i8 %x to i1
   %select = select i1 %trunc, i8 %y, i8 0
@@ -374,7 +378,11 @@ define i1 @or_trunc_nuw_implied(i8 %x, i8 %y) {
 
 define i1 @or_trunc_nuw_implied_to_true(i8 %x, i8 %y) {
 ; CHECK-LABEL: @or_trunc_nuw_implied_to_true(
-; CHECK-NEXT:    ret i1 true
+; CHECK-NEXT:    [[TRUNC:%.*]] = trunc nuw i8 [[X:%.*]] to i1
+; CHECK-NEXT:    [[SELECT:%.*]] = select i1 [[TRUNC]], i8 [[Y:%.*]], i8 0
+; CHECK-NEXT:    [[ICMP:%.*]] = icmp eq i8 [[SELECT]], 0
+; CHECK-NEXT:    [[AND:%.*]] = or i1 [[TRUNC]], [[ICMP]]
+; CHECK-NEXT:    ret i1 [[AND]]
 ;
   %trunc = trunc nuw i8 %x to i1
   %select = select i1 %trunc, i8 %y, i8 0


        


More information about the llvm-commits mailing list