[InstCombine] allow add+not --> sub for arbitrary vector constants.
authorSanjay Patel <spatel@rotateright.com>
Mon, 3 Sep 2018 18:21:59 +0000 (18:21 +0000)
committerSanjay Patel <spatel@rotateright.com>
Mon, 3 Sep 2018 18:21:59 +0000 (18:21 +0000)
llvm-svn: 341335

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/test/Transforms/InstCombine/not.ll

index f34ec13..9af5ad0 100644 (file)
@@ -2699,6 +2699,10 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
       Constant *NotC = ConstantExpr::getNot(C);
       return BinaryOperator::CreateAShr(NotC, Y);
     }
+
+    // ~(X + C) --> -(C + 1) - X
+    if (match(Op0, m_Add(m_Value(X), m_Constant(C))))
+      return BinaryOperator::CreateSub(ConstantExpr::getNeg(AddOne(C)), X);
   }
 
   // not (cmp A, B) = !cmp A, B
@@ -2720,11 +2724,6 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
           return BinaryOperator::CreateSub(NewC, X);
         }
       } else if (match(Op0, m_Add(m_Value(X), m_APInt(C)))) {
-        // ~(X + C) --> (-C - 1) - X
-        if (RHSC->isAllOnesValue()) {
-          Constant *NewC = ConstantInt::get(I.getType(), -(*C) - 1);
-          return BinaryOperator::CreateSub(NewC, X);
-        }
         if (RHSC->isSignMask()) {
           // (X + C) ^ signmask -> (X + C + signmask)
           Constant *NewC = ConstantInt::get(I.getType(), *C + *RHSC);
index 4e41f46..42a910a 100644 (file)
@@ -243,8 +243,7 @@ define <2 x i32> @not_add_splat(<2 x i32> %x) {
 
 define <2 x i32> @not_add_vec(<2 x i32> %x) {
 ; CHECK-LABEL: @not_add_vec(
-; CHECK-NEXT:    [[A:%.*]] = add <2 x i32> [[X:%.*]], <i32 42, i32 123>
-; CHECK-NEXT:    [[R:%.*]] = xor <2 x i32> [[A]], <i32 -1, i32 -1>
+; CHECK-NEXT:    [[R:%.*]] = sub <2 x i32> <i32 -43, i32 -124>, [[X:%.*]]
 ; CHECK-NEXT:    ret <2 x i32> [[R]]
 ;
   %a = add <2 x i32> %x, <i32 42, i32 123>