[llvm] r341335 - [InstCombine] allow add+not --> sub for arbitrary vector constants.
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 3 11:21:59 PDT 2018
Author: spatel
Date: Mon Sep 3 11:21:59 2018
New Revision: 341335
URL: http://llvm.org/viewvc/llvm-project?rev=341335&view=rev
Log:
[InstCombine] allow add+not --> sub for arbitrary vector constants.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/trunk/test/Transforms/InstCombine/not.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp?rev=341335&r1=341334&r2=341335&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp Mon Sep 3 11:21:59 2018
@@ -2699,6 +2699,10 @@ Instruction *InstCombiner::visitXor(Bina
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(Bina
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);
Modified: llvm/trunk/test/Transforms/InstCombine/not.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/not.ll?rev=341335&r1=341334&r2=341335&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/not.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/not.ll Mon Sep 3 11:21:59 2018
@@ -243,8 +243,7 @@ define <2 x i32> @not_add_splat(<2 x i32
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>
More information about the llvm-commits
mailing list