summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp6
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp1
-rw-r--r--llvm/test/Transforms/InstCombine/icmp.ll18
-rw-r--r--llvm/test/Transforms/InstCombine/minmax-fold.ll4
4 files changed, 12 insertions, 17 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index e569ae866b5..5bafab49032 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -5394,6 +5394,9 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
if (Instruction *Res = foldICmpWithDominatingICmp(I))
return Res;
+ if (Instruction *Res = foldICmpBinOp(I))
+ return Res;
+
if (Instruction *Res = foldICmpUsingKnownBits(I))
return Res;
@@ -5471,9 +5474,6 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
if (Instruction *R = foldICmpWithCastOp(I))
return R;
- if (Instruction *Res = foldICmpBinOp(I))
- return Res;
-
if (Instruction *Res = foldICmpWithMinMax(I))
return Res;
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 6ccfac28d05..55ac8202130 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -1126,6 +1126,7 @@ static Value *simplifyWithOpReplaced(Value *V, Value *Op, Value *ReplaceOp,
/// %sel = select i1 %cmp, i32 -2147483648, i32 %add
///
/// We can't replace %sel with %add unless we strip away the flags.
+/// TODO: Wrapping flags could be preserved in some cases with better analysis.
static Value *foldSelectValueEquivalence(SelectInst &Sel, ICmpInst &Cmp,
const SimplifyQuery &Q) {
if (!Cmp.isEquality())
diff --git a/llvm/test/Transforms/InstCombine/icmp.ll b/llvm/test/Transforms/InstCombine/icmp.ll
index 657f6acb899..9008db9f897 100644
--- a/llvm/test/Transforms/InstCombine/icmp.ll
+++ b/llvm/test/Transforms/InstCombine/icmp.ll
@@ -683,12 +683,9 @@ define i1 @test37_extra_uses(i32 %x, i32 %y, i32 %z) {
define i32 @neg_max_s32(i32 %x, i32 %y) {
; CHECK-LABEL: @neg_max_s32(
-; CHECK-NEXT: [[NX:%.*]] = sub nsw i32 0, [[X:%.*]]
-; CHECK-NEXT: [[NY:%.*]] = sub nsw i32 0, [[Y:%.*]]
-; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[NX]], [[NY]]
-; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i32 [[NY]], i32 [[NX]]
-; CHECK-NEXT: [[R:%.*]] = sub nsw i32 0, [[S]]
-; CHECK-NEXT: ret i32 [[R]]
+; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[Y:%.*]], [[X:%.*]]
+; CHECK-NEXT: [[S_V:%.*]] = select i1 [[C]], i32 [[Y]], i32 [[X]]
+; CHECK-NEXT: ret i32 [[S_V]]
;
%nx = sub nsw i32 0, %x
%ny = sub nsw i32 0, %y
@@ -700,12 +697,9 @@ define i32 @neg_max_s32(i32 %x, i32 %y) {
define <4 x i32> @neg_max_v4s32(<4 x i32> %x, <4 x i32> %y) {
; CHECK-LABEL: @neg_max_v4s32(
-; CHECK-NEXT: [[NX:%.*]] = sub nsw <4 x i32> zeroinitializer, [[X:%.*]]
-; CHECK-NEXT: [[NY:%.*]] = sub nsw <4 x i32> zeroinitializer, [[Y:%.*]]
-; CHECK-NEXT: [[C:%.*]] = icmp sgt <4 x i32> [[NX]], [[NY]]
-; CHECK-NEXT: [[S:%.*]] = select <4 x i1> [[C]], <4 x i32> [[NX]], <4 x i32> [[NY]]
-; CHECK-NEXT: [[R:%.*]] = sub <4 x i32> zeroinitializer, [[S]]
-; CHECK-NEXT: ret <4 x i32> [[R]]
+; CHECK-NEXT: [[C:%.*]] = icmp sgt <4 x i32> [[Y:%.*]], [[X:%.*]]
+; CHECK-NEXT: [[S_V:%.*]] = select <4 x i1> [[C]], <4 x i32> [[X]], <4 x i32> [[Y]]
+; CHECK-NEXT: ret <4 x i32> [[S_V]]
;
%nx = sub nsw <4 x i32> zeroinitializer, %x
%ny = sub nsw <4 x i32> zeroinitializer, %y
diff --git a/llvm/test/Transforms/InstCombine/minmax-fold.ll b/llvm/test/Transforms/InstCombine/minmax-fold.ll
index 264e579db1d..47588565c5c 100644
--- a/llvm/test/Transforms/InstCombine/minmax-fold.ll
+++ b/llvm/test/Transforms/InstCombine/minmax-fold.ll
@@ -1080,8 +1080,8 @@ define i37 @add_umax_constant_limit(i37 %x) {
define i37 @add_umax_simplify(i37 %x) {
; CHECK-LABEL: @add_umax_simplify(
-; CHECK-NEXT: [[R:%.*]] = add nuw i37 [[X:%.*]], 42
-; CHECK-NEXT: ret i37 [[R]]
+; CHECK-NEXT: [[A:%.*]] = add i37 [[X:%.*]], 42
+; CHECK-NEXT: ret i37 [[A]]
;
%a = add nuw i37 %x, 42
%c = icmp ugt i37 %a, 42
OpenPOWER on IntegriCloud