forked from OSchip/llvm-project
[InstCombine] use m_APInt to allow icmp eq (add X, C1), C2 folds for splat constant vectors
llvm-svn: 277659
This commit is contained in:
parent
129e709a03
commit
00a324e893
|
@ -2227,13 +2227,14 @@ Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Instruction::Add:
|
case Instruction::Add: {
|
||||||
// Replace ((add A, B) != C) with (A != C-B) if B & C are constants.
|
// Replace ((add A, B) != C) with (A != C-B) if B & C are constants.
|
||||||
// FIXME: Vectors are excluded by ConstantInt.
|
const APInt *BOC;
|
||||||
if (ConstantInt *BOp1C = dyn_cast<ConstantInt>(BOp1)) {
|
if (match(BOp1, m_APInt(BOC))) {
|
||||||
if (BO->hasOneUse())
|
if (BO->hasOneUse()) {
|
||||||
return new ICmpInst(ICI.getPredicate(), BOp0,
|
Constant *SubC = ConstantExpr::getSub(RHS, cast<Constant>(BOp1));
|
||||||
ConstantExpr::getSub(RHS, BOp1C));
|
return new ICmpInst(ICI.getPredicate(), BOp0, SubC);
|
||||||
|
}
|
||||||
} else if (*RHSV == 0) {
|
} else if (*RHSV == 0) {
|
||||||
// Replace ((add A, B) != 0) with (A != -B) if A or B is
|
// Replace ((add A, B) != 0) with (A != -B) if A or B is
|
||||||
// efficiently invertible, or if the add has just this one use.
|
// efficiently invertible, or if the add has just this one use.
|
||||||
|
@ -2248,6 +2249,7 @@ Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case Instruction::Xor:
|
case Instruction::Xor:
|
||||||
if (BO->hasOneUse()) {
|
if (BO->hasOneUse()) {
|
||||||
if (Constant *BOC = dyn_cast<Constant>(BOp1)) {
|
if (Constant *BOC = dyn_cast<Constant>(BOp1)) {
|
||||||
|
|
|
@ -264,11 +264,9 @@ define i1 @test21(i32 %x) {
|
||||||
ret i1 %y
|
ret i1 %y
|
||||||
}
|
}
|
||||||
|
|
||||||
; FIXME: Vectors should fold the same way.
|
|
||||||
define <2 x i1> @test21vec(<2 x i32> %x) {
|
define <2 x i1> @test21vec(<2 x i32> %x) {
|
||||||
; CHECK-LABEL: @test21vec(
|
; CHECK-LABEL: @test21vec(
|
||||||
; CHECK-NEXT: [[T:%.*]] = add <2 x i32> %x, <i32 4, i32 4>
|
; CHECK-NEXT: [[Y:%.*]] = icmp eq <2 x i32> %x, <i32 119, i32 119>
|
||||||
; CHECK-NEXT: [[Y:%.*]] = icmp eq <2 x i32> [[T]], <i32 123, i32 123>
|
|
||||||
; CHECK-NEXT: ret <2 x i1> [[Y]]
|
; CHECK-NEXT: ret <2 x i1> [[Y]]
|
||||||
;
|
;
|
||||||
%t = add <2 x i32> %x, <i32 4, i32 4>
|
%t = add <2 x i32> %x, <i32 4, i32 4>
|
||||||
|
|
|
@ -1004,12 +1004,9 @@ define i1 @test70(i32 %X) {
|
||||||
ret i1 %C
|
ret i1 %C
|
||||||
}
|
}
|
||||||
|
|
||||||
; FIXME: Vectors should fold the same way.
|
|
||||||
|
|
||||||
define <2 x i1> @test70vec(<2 x i32> %X) {
|
define <2 x i1> @test70vec(<2 x i32> %X) {
|
||||||
; CHECK-LABEL: @test70vec(
|
; CHECK-LABEL: @test70vec(
|
||||||
; CHECK-NEXT: [[B:%.*]] = add <2 x i32> %X, <i32 2, i32 2>
|
; CHECK-NEXT: [[C:%.*]] = icmp ne <2 x i32> %X, <i32 2, i32 2>
|
||||||
; CHECK-NEXT: [[C:%.*]] = icmp ne <2 x i32> [[B]], <i32 4, i32 4>
|
|
||||||
; CHECK-NEXT: ret <2 x i1> [[C]]
|
; CHECK-NEXT: ret <2 x i1> [[C]]
|
||||||
;
|
;
|
||||||
%B = add <2 x i32> %X, <i32 2, i32 2>
|
%B = add <2 x i32> %X, <i32 2, i32 2>
|
||||||
|
|
Loading…
Reference in New Issue