]> granicus.if.org Git - llvm/commitdiff
[InstCombine] fix icmp with not op and constant to work with splat vector constant
authorSanjay Patel <spatel@rotateright.com>
Fri, 2 Jun 2017 16:29:41 +0000 (16:29 +0000)
committerSanjay Patel <spatel@rotateright.com>
Fri, 2 Jun 2017 16:29:41 +0000 (16:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304562 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineCompares.cpp
test/Transforms/InstCombine/not.ll

index 4ca967d3afb4df3a085b40f8251022e875c7dddd..c0798e164c39fb4ca01520634a557b3cf13c2909 100644 (file)
@@ -4514,10 +4514,10 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
       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;
index b52919071d20a7ea6811f8fcf87fb671497ebcb6..8352c07a816b5aaa602e65b9c6f621adcc1df656 100644 (file)
@@ -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>