diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index 576aa2d28ac..75c434265fb 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2227,13 +2227,14 @@ Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI) { } } break; - case Instruction::Add: + case Instruction::Add: { // Replace ((add A, B) != C) with (A != C-B) if B & C are constants. - // FIXME: Vectors are excluded by ConstantInt. - if (ConstantInt *BOp1C = dyn_cast(BOp1)) { - if (BO->hasOneUse()) - return new ICmpInst(ICI.getPredicate(), BOp0, - ConstantExpr::getSub(RHS, BOp1C)); + const APInt *BOC; + if (match(BOp1, m_APInt(BOC))) { + if (BO->hasOneUse()) { + Constant *SubC = ConstantExpr::getSub(RHS, cast(BOp1)); + return new ICmpInst(ICI.getPredicate(), BOp0, SubC); + } } else if (*RHSV == 0) { // Replace ((add A, B) != 0) with (A != -B) if A or B is // efficiently invertible, or if the add has just this one use. @@ -2248,6 +2249,7 @@ Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI) { } } break; + } case Instruction::Xor: if (BO->hasOneUse()) { if (Constant *BOC = dyn_cast(BOp1)) { diff --git a/test/Transforms/InstCombine/add.ll b/test/Transforms/InstCombine/add.ll index 10c15928efb..7c46257273a 100644 --- a/test/Transforms/InstCombine/add.ll +++ b/test/Transforms/InstCombine/add.ll @@ -264,11 +264,9 @@ define i1 @test21(i32 %x) { ret i1 %y } -; FIXME: Vectors should fold the same way. define <2 x i1> @test21vec(<2 x i32> %x) { ; CHECK-LABEL: @test21vec( -; CHECK-NEXT: [[T:%.*]] = add <2 x i32> %x, -; CHECK-NEXT: [[Y:%.*]] = icmp eq <2 x i32> [[T]], +; CHECK-NEXT: [[Y:%.*]] = icmp eq <2 x i32> %x, ; CHECK-NEXT: ret <2 x i1> [[Y]] ; %t = add <2 x i32> %x, diff --git a/test/Transforms/InstCombine/icmp.ll b/test/Transforms/InstCombine/icmp.ll index cefe45c9681..1e1957558ad 100644 --- a/test/Transforms/InstCombine/icmp.ll +++ b/test/Transforms/InstCombine/icmp.ll @@ -1004,12 +1004,9 @@ define i1 @test70(i32 %X) { ret i1 %C } -; FIXME: Vectors should fold the same way. - define <2 x i1> @test70vec(<2 x i32> %X) { ; CHECK-LABEL: @test70vec( -; CHECK-NEXT: [[B:%.*]] = add <2 x i32> %X, -; CHECK-NEXT: [[C:%.*]] = icmp ne <2 x i32> [[B]], +; CHECK-NEXT: [[C:%.*]] = icmp ne <2 x i32> %X, ; CHECK-NEXT: ret <2 x i1> [[C]] ; %B = add <2 x i32> %X,