mirror of
https://github.com/RPCS3/llvm.git
synced 2025-01-09 05:31:37 +00:00
[InstCombine] Support '(C - X) ^ signmask -> (C + signmask - X)' and '(X + C) ^ signmask -> (X + C + signmask)' for vector splats.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310232 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4bd72a825d
commit
6b4cc4f3b5
@ -2430,35 +2430,30 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
|
||||
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)) {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user