[llvm] r277731 - [InstCombine] use m_APInt to allow icmp eq (sub C1, X), C2 folds for splat constant vectors
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 4 08:19:26 PDT 2016
Author: spatel
Date: Thu Aug 4 10:19:25 2016
New Revision: 277731
URL: http://llvm.org/viewvc/llvm-project?rev=277731&view=rev
Log:
[InstCombine] use m_APInt to allow icmp eq (sub C1, X), C2 folds for splat constant vectors
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/trunk/test/Transforms/InstCombine/icmp.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=277731&r1=277730&r2=277731&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Thu Aug 4 10:19:25 2016
@@ -2265,11 +2265,11 @@ Instruction *InstCombiner::foldICmpEqual
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);
Modified: llvm/trunk/test/Transforms/InstCombine/icmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/icmp.ll?rev=277731&r1=277730&r2=277731&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/icmp.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/icmp.ll Thu Aug 4 10:19:25 2016
@@ -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
More information about the llvm-commits
mailing list