summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2018-07-14 20:08:47 +0000
committerRoman Lebedev <lebedev.ri@gmail.com>2018-07-14 20:08:47 +0000
commitb972fc3e8a2e9569685a794cad7546d895935ccd (patch)
tree3b5b7b3f9d06800c91711eb1ce47bca0be1e6d18
parentedba515baa3d924000f9704890987aaad5d90630 (diff)
downloadbcm5719-llvm-b972fc3e8a2e9569685a794cad7546d895935ccd.tar.gz
bcm5719-llvm-b972fc3e8a2e9569685a794cad7546d895935ccd.zip
[InstCombine] Fold x & (-1 >> y) s< x to x s> (-1 >> y)
https://bugs.llvm.org/show_bug.cgi?id=38123 https://rise4fun.com/Alive/I3O This pattern is not commutative! We must make sure not to fold the commuted version! llvm-svn: 337111
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp6
-rw-r--r--llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-slt-to-icmp-sgt.ll34
2 files changed, 20 insertions, 20 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index b43520d9e92..94999ba3df2 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -2924,6 +2924,12 @@ static Value *foldICmpWithLowBitMaskedVal(ICmpInst &I,
return nullptr; // Ignore the other case.
DstPred = ICmpInst::Predicate::ICMP_SLE;
break;
+ case ICmpInst::Predicate::ICMP_SLT:
+ // x & (-1 >> y) s< x -> x s> (-1 >> y)
+ if (X != I.getOperand(1)) // X must be on RHS of comparison!
+ return nullptr; // Ignore the other case.
+ DstPred = ICmpInst::Predicate::ICMP_SGT;
+ break;
case ICmpInst::Predicate::ICMP_SLE:
// x s<= x & (-1 >> y) -> x s<= (-1 >> y)
if (X != I.getOperand(0)) // X must be on LHS of comparison!
diff --git a/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-slt-to-icmp-sgt.ll b/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-slt-to-icmp-sgt.ll
index c5e981b9a82..d1792d1e075 100644
--- a/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-slt-to-icmp-sgt.ll
+++ b/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-slt-to-icmp-sgt.ll
@@ -15,9 +15,8 @@
define i1 @p0(i8 %x) {
; CHECK-LABEL: @p0(
-; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X:%.*]], 3
-; CHECK-NEXT: [[RET:%.*]] = icmp slt i8 [[TMP0]], [[X]]
-; CHECK-NEXT: ret i1 [[RET]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i8 [[X:%.*]], 3
+; CHECK-NEXT: ret i1 [[TMP1]]
;
%tmp0 = and i8 %x, 3
%ret = icmp slt i8 %tmp0, %x
@@ -27,9 +26,8 @@ define i1 @p0(i8 %x) {
define i1 @pv(i8 %x, i8 %y) {
; CHECK-LABEL: @pv(
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
-; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[TMP0]], [[X:%.*]]
-; CHECK-NEXT: [[RET:%.*]] = icmp slt i8 [[TMP1]], [[X]]
-; CHECK-NEXT: ret i1 [[RET]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i8 [[TMP0]], [[X:%.*]]
+; CHECK-NEXT: ret i1 [[TMP1]]
;
%tmp0 = lshr i8 -1, %y
%tmp1 = and i8 %tmp0, %x
@@ -43,9 +41,8 @@ define i1 @pv(i8 %x, i8 %y) {
define <2 x i1> @p1_vec_splat(<2 x i8> %x) {
; CHECK-LABEL: @p1_vec_splat(
-; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i8> [[X:%.*]], <i8 3, i8 3>
-; CHECK-NEXT: [[RET:%.*]] = icmp slt <2 x i8> [[TMP0]], [[X]]
-; CHECK-NEXT: ret <2 x i1> [[RET]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <2 x i8> [[X:%.*]], <i8 3, i8 3>
+; CHECK-NEXT: ret <2 x i1> [[TMP1]]
;
%tmp0 = and <2 x i8> %x, <i8 3, i8 3>
%ret = icmp slt <2 x i8> %tmp0, %x
@@ -54,9 +51,8 @@ define <2 x i1> @p1_vec_splat(<2 x i8> %x) {
define <2 x i1> @p2_vec_nonsplat(<2 x i8> %x) {
; CHECK-LABEL: @p2_vec_nonsplat(
-; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i8> [[X:%.*]], <i8 3, i8 15>
-; CHECK-NEXT: [[RET:%.*]] = icmp slt <2 x i8> [[TMP0]], [[X]]
-; CHECK-NEXT: ret <2 x i1> [[RET]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <2 x i8> [[X:%.*]], <i8 3, i8 15>
+; CHECK-NEXT: ret <2 x i1> [[TMP1]]
;
%tmp0 = and <2 x i8> %x, <i8 3, i8 15> ; doesn't have to be splat.
%ret = icmp slt <2 x i8> %tmp0, %x
@@ -65,9 +61,8 @@ define <2 x i1> @p2_vec_nonsplat(<2 x i8> %x) {
define <3 x i1> @p3_vec_splat_undef(<3 x i8> %x) {
; CHECK-LABEL: @p3_vec_splat_undef(
-; CHECK-NEXT: [[TMP0:%.*]] = and <3 x i8> [[X:%.*]], <i8 3, i8 undef, i8 3>
-; CHECK-NEXT: [[RET:%.*]] = icmp slt <3 x i8> [[TMP0]], [[X]]
-; CHECK-NEXT: ret <3 x i1> [[RET]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <3 x i8> [[X:%.*]], <i8 3, i8 undef, i8 3>
+; CHECK-NEXT: ret <3 x i1> [[TMP1]]
;
%tmp0 = and <3 x i8> %x, <i8 3, i8 undef, i8 3>
%ret = icmp slt <3 x i8> %tmp0, %x
@@ -84,8 +79,8 @@ define i1 @oneuse0(i8 %x) {
; CHECK-LABEL: @oneuse0(
; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X:%.*]], 3
; CHECK-NEXT: call void @use8(i8 [[TMP0]])
-; CHECK-NEXT: [[RET:%.*]] = icmp slt i8 [[TMP0]], [[X]]
-; CHECK-NEXT: ret i1 [[RET]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i8 [[X]], 3
+; CHECK-NEXT: ret i1 [[TMP1]]
;
%tmp0 = and i8 %x, 3
call void @use8(i8 %tmp0)
@@ -125,9 +120,8 @@ define i1 @cv0(i8 %y) {
; CHECK-LABEL: @cv0(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
-; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X]], [[TMP0]]
-; CHECK-NEXT: [[RET:%.*]] = icmp slt i8 [[TMP1]], [[X]]
-; CHECK-NEXT: ret i1 [[RET]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i8 [[X]], [[TMP0]]
+; CHECK-NEXT: ret i1 [[TMP1]]
;
%x = call i8 @gen8()
%tmp0 = lshr i8 -1, %y
OpenPOWER on IntegriCloud