[llvm] r310232 - [InstCombine] Support '(C - X) ^ signmask -> (C + signmask - X)' and '(X + C) ^ signmask -> (X + C + signmask)' for vector splats.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 6 15:17:21 PDT 2017
Author: ctopper
Date: Sun Aug 6 15:17:21 2017
New Revision: 310232
URL: http://llvm.org/viewvc/llvm-project?rev=310232&view=rev
Log:
[InstCombine] Support '(C - X) ^ signmask -> (C + signmask - X)' and '(X + C) ^ signmask -> (X + C + signmask)' for vector splats.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/trunk/test/Transforms/InstCombine/xor.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp?rev=310232&r1=310231&r2=310232&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp Sun Aug 6 15:17:21 2017
@@ -2430,35 +2430,30 @@ Instruction *InstCombiner::visitXor(Bina
Constant *NewC = ConstantInt::get(I.getType(), -(*C) - 1);
return BinaryOperator::CreateAdd(V, NewC);
}
+ if (RHSC->isSignMask()) {
+ // (C - X) ^ signmask -> (C + signmask - X)
+ Constant *NewC = ConstantInt::get(I.getType(), *C + *RHSC);
+ return BinaryOperator::CreateSub(NewC, V);
+ }
} else if (match(Op0, m_Add(m_Value(V), m_APInt(C)))) {
// ~(X-c) --> (-c-1)-X
if (RHSC->isAllOnesValue()) {
Constant *NewC = ConstantInt::get(I.getType(), -(*C) - 1);
return BinaryOperator::CreateSub(NewC, V);
}
+ if (RHSC->isSignMask()) {
+ // (X + C) ^ signmask -> (X + C + signmask)
+ Constant *NewC = ConstantInt::get(I.getType(), *C + *RHSC);
+ return BinaryOperator::CreateAdd(V, NewC);
+ }
}
}
}
if (ConstantInt *RHSC = dyn_cast<ConstantInt>(Op1)) {
if (BinaryOperator *Op0I = dyn_cast<BinaryOperator>(Op0)) {
- if (Op0I->getOpcode() == Instruction::Sub)
- if (ConstantInt *Op0I0C = dyn_cast<ConstantInt>(Op0I->getOperand(0))) {
- // (C - X) ^ signmask -> (C + signmask - X)
- if (RHSC->getValue().isSignMask()) {
- Constant *C = Builder.getInt(RHSC->getValue() + Op0I0C->getValue());
- return BinaryOperator::CreateSub(C, Op0I->getOperand(1));
- }
- }
-
if (ConstantInt *Op0CI = dyn_cast<ConstantInt>(Op0I->getOperand(1))) {
- if (Op0I->getOpcode() == Instruction::Add) {
- // (X + C) ^ signmask -> (X + C + signmask)
- if (RHSC->getValue().isSignMask()) {
- Constant *C = Builder.getInt(RHSC->getValue() + Op0CI->getValue());
- return BinaryOperator::CreateAdd(Op0I->getOperand(0), C);
- }
- } else if (Op0I->getOpcode() == Instruction::Or) {
+ if (Op0I->getOpcode() == Instruction::Or) {
// (X|C1)^C2 -> X^(C1|C2) iff X&~C1 == 0
if (MaskedValueIsZero(Op0I->getOperand(0), Op0CI->getValue(),
0, &I)) {
Modified: llvm/trunk/test/Transforms/InstCombine/xor.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/xor.ll?rev=310232&r1=310231&r2=310232&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/xor.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/xor.ll Sun Aug 6 15:17:21 2017
@@ -383,6 +383,16 @@ define i32 @test28(i32 %indvar) {
ret i32 %t214
}
+define <2 x i32> @test28vec(<2 x i32> %indvar) {
+; CHECK-LABEL: @test28vec(
+; CHECK-NEXT: [[T214:%.*]] = add <2 x i32> [[INDVAR:%.*]], <i32 1, i32 1>
+; CHECK-NEXT: ret <2 x i32> [[T214]]
+;
+ %t7 = add <2 x i32> %indvar, <i32 -2147483647, i32 -2147483647>
+ %t214 = xor <2 x i32> %t7, <i32 -2147483648, i32 -2147483648>
+ ret <2 x i32> %t214
+}
+
define i32 @test28_sub(i32 %indvar) {
; CHECK-LABEL: @test28_sub(
; CHECK-NEXT: [[T214:%.*]] = sub i32 1, [[INDVAR:%.*]]
@@ -393,6 +403,16 @@ define i32 @test28_sub(i32 %indvar) {
ret i32 %t214
}
+define <2 x i32> @test28_subvec(<2 x i32> %indvar) {
+; CHECK-LABEL: @test28_subvec(
+; CHECK-NEXT: [[T214:%.*]] = sub <2 x i32> <i32 1, i32 1>, [[INDVAR:%.*]]
+; CHECK-NEXT: ret <2 x i32> [[T214]]
+;
+ %t7 = sub <2 x i32> <i32 -2147483647, i32 -2147483647>, %indvar
+ %t214 = xor <2 x i32> %t7, <i32 -2147483648, i32 -2147483648>
+ ret <2 x i32> %t214
+}
+
define i32 @test29(i1 %C) {
; CHECK-LABEL: @test29(
; CHECK-NEXT: [[V:%.*]] = select i1 [[C:%.*]], i32 915, i32 113
More information about the llvm-commits
mailing list