[InstCombine] allow add+not --> sub for arbitrary vector constants.

llvm-svn: 341335
This commit is contained in:
Sanjay Patel 2018-09-03 18:21:59 +00:00
parent 7a213d2f9b
commit d75064e6d5
2 changed files with 5 additions and 7 deletions
llvm
lib/Transforms/InstCombine
test/Transforms/InstCombine

View 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);

View 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>