[llvm] 7a9e3ad - [InstCombine] relax one-use check for icmp with mask/cast

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 23 15:25:33 PST 2023


Author: Sanjay Patel
Date: 2023-01-23T18:23:43-05:00
New Revision: 7a9e3ad070653544536a3be5fe18104bc305014f

URL: https://github.com/llvm/llvm-project/commit/7a9e3ad070653544536a3be5fe18104bc305014f
DIFF: https://github.com/llvm/llvm-project/commit/7a9e3ad070653544536a3be5fe18104bc305014f.diff

LOG: [InstCombine] relax one-use check for icmp with mask/cast

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
    llvm/test/Transforms/InstCombine/icmp.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 69de580999bf..fe04b5949770 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -4655,11 +4655,11 @@ Instruction *InstCombinerImpl::foldICmpEquality(ICmpInst &I) {
 
   // (B & (Pow2C-1)) == zext A --> A == trunc B
   // (B & (Pow2C-1)) != zext A --> A != trunc B
-  // TODO: The one use check could be relaxed.
   // TODO: This can be generalized for vector types.
   ConstantInt *Cst1;
   if (match(Op0, m_And(m_Value(B), m_ConstantInt(Cst1))) &&
-      match(Op1, m_OneUse(m_ZExt(m_Value(A))))) {
+      match(Op1, m_ZExt(m_Value(A))) &&
+      (Op0->hasOneUse() || Op1->hasOneUse())) {
     APInt Pow2 = Cst1->getValue() + 1;
     if (Pow2.isPowerOf2() && isa<IntegerType>(A->getType()) &&
         Pow2.logBase2() == cast<IntegerType>(A->getType())->getBitWidth())

diff  --git a/llvm/test/Transforms/InstCombine/icmp.ll b/llvm/test/Transforms/InstCombine/icmp.ll
index 411383e9168b..89a4c049d4c7 100644
--- a/llvm/test/Transforms/InstCombine/icmp.ll
+++ b/llvm/test/Transforms/InstCombine/icmp.ll
@@ -1157,10 +1157,10 @@ define i1 @low_mask_eq_zext_use1(i8 %a, i32 %b) {
 
 define i1 @low_mask_eq_zext_use2(i8 %a, i32 %b) {
 ; CHECK-LABEL: @low_mask_eq_zext_use2(
-; CHECK-NEXT:    [[T:%.*]] = and i32 [[B:%.*]], 255
 ; CHECK-NEXT:    [[Z:%.*]] = zext i8 [[A:%.*]] to i32
 ; CHECK-NEXT:    call void @use_i32(i32 [[Z]])
-; CHECK-NEXT:    [[C:%.*]] = icmp eq i32 [[T]], [[Z]]
+; CHECK-NEXT:    [[TMP1:%.*]] = trunc i32 [[B:%.*]] to i8
+; CHECK-NEXT:    [[C:%.*]] = icmp eq i8 [[TMP1]], [[A]]
 ; CHECK-NEXT:    ret i1 [[C]]
 ;
   %t = and i32 %b, 255


        


More information about the llvm-commits mailing list