[InstCombine] use m_APInt to allow icmp eq (sub C1, X), C2 folds for splat constant vectors

llvm-svn: 277731
This commit is contained in:
Sanjay Patel 2016-08-04 15:19:25 +00:00
parent d1f4b8f6e8
commit 9d591d15ec
2 changed files with 6 additions and 10 deletions

View File

@ -2265,11 +2265,11 @@ Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI) {
break;
case Instruction::Sub:
if (BO->hasOneUse()) {
// FIXME: Vectors are excluded by ConstantInt.
if (ConstantInt *BOp0C = dyn_cast<ConstantInt>(BOp0)) {
const APInt *BOC;
if (match(BOp0, m_APInt(BOC))) {
// Replace ((sub A, B) != C) with (B != A-C) if A & C are constants.
return new ICmpInst(ICI.getPredicate(), BOp1,
ConstantExpr::getSub(BOp0C, RHS));
Constant *SubC = ConstantExpr::getSub(cast<Constant>(BOp0), RHS);
return new ICmpInst(ICI.getPredicate(), BOp1, SubC);
} else if (*RHSV == 0) {
// Replace ((sub A, B) != 0) with (A != B)
return new ICmpInst(ICI.getPredicate(), BOp0, BOp1);

View File

@ -660,11 +660,9 @@ define i1 @test55(i32 %a) {
ret i1 %cmp
}
; FIXME: Vectors should fold the same way.
define <2 x i1> @test55vec(<2 x i32> %a) {
; CHECK-LABEL: @test55vec(
; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i32> zeroinitializer, %a
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[SUB]], <i32 123, i32 123>
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> %a, <i32 -123, i32 -123>
; CHECK-NEXT: ret <2 x i1> [[CMP]]
;
%sub = sub <2 x i32> zeroinitializer, %a
@ -682,11 +680,9 @@ define i1 @test56(i32 %a) {
ret i1 %cmp
}
; FIXME: Vectors should fold the same way.
define <2 x i1> @test56vec(<2 x i32> %a) {
; CHECK-LABEL: @test56vec(
; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i32> <i32 10, i32 10>, %a
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[SUB]], <i32 123, i32 123>
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> %a, <i32 -113, i32 -113>
; CHECK-NEXT: ret <2 x i1> [[CMP]]
;
%sub = sub <2 x i32> <i32 10, i32 10>, %a