[llvm] r304562 - [InstCombine] fix icmp with not op and constant to work with splat vector constant

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 2 09:29:42 PDT 2017


Author: spatel
Date: Fri Jun  2 11:29:41 2017
New Revision: 304562

URL: http://llvm.org/viewvc/llvm-project?rev=304562&view=rev
Log:
[InstCombine] fix icmp with not op and constant to work with splat vector constant

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

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=304562&r1=304561&r2=304562&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Fri Jun  2 11:29:41 2017
@@ -4514,10 +4514,10 @@ Instruction *InstCombiner::visitICmpInst
       if (match(Op1, m_Not(m_Value(B))))
         return new ICmpInst(I.getPredicate(), B, A);
 
-      // FIXME: Use m_APInt to include splat vector constants.
-      if (ConstantInt *RHSC = dyn_cast<ConstantInt>(Op1))
+      const APInt *C;
+      if (match(Op1, m_APInt(C)))
         return new ICmpInst(I.getSwappedPredicate(), A,
-                            ConstantExpr::getNot(RHSC));
+                            ConstantInt::get(Op1->getType(), ~(*C)));
     }
 
     Instruction *AddI = nullptr;

Modified: llvm/trunk/test/Transforms/InstCombine/not.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/not.ll?rev=304562&r1=304561&r2=304562&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/not.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/not.ll Fri Jun  2 11:29:41 2017
@@ -67,8 +67,7 @@ define i1 @not_cmp_constant(i32 %a) {
 
 define <2 x i1> @not_cmp_constant_vector(<2 x i32> %a) {
 ; CHECK-LABEL: @not_cmp_constant_vector(
-; CHECK-NEXT:    [[NOTA:%.*]] = xor <2 x i32> %a, <i32 -1, i32 -1>
-; CHECK-NEXT:    [[CMP:%.*]] = icmp slt <2 x i32> [[NOTA]], <i32 42, i32 42>
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt <2 x i32> %a, <i32 -43, i32 -43>
 ; CHECK-NEXT:    ret <2 x i1> [[CMP]]
 ;
   %nota = xor <2 x i32> %a, <i32 -1, i32 -1>




More information about the llvm-commits mailing list