[llvm] r336911 - [InstCombine] Fold x & (-1 >> y) != x to x u> (-1 >> y)
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 12 07:56:12 PDT 2018
Author: lebedevri
Date: Thu Jul 12 07:56:12 2018
New Revision: 336911
URL: http://llvm.org/viewvc/llvm-project?rev=336911&view=rev
Log:
[InstCombine] Fold x & (-1 >> y) != x to x u> (-1 >> y)
Summary:
A complementary fold to D49179.
https://bugs.llvm.org/show_bug.cgi?id=38123
https://rise4fun.com/Alive/Rny
Caveat: one more thing in `test/Transforms/InstCombine/icmp-logical.ll` breaks.
Reviewers: spatel, craig.topper
Reviewed By: spatel
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D49205
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/trunk/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-ne-to-icmp-ugt.ll
llvm/trunk/test/Transforms/InstCombine/canonicalize-low-bit-mask-and-icmp-ne-to-icmp-ugt.ll
llvm/trunk/test/Transforms/InstCombine/icmp-logical.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=336911&r1=336910&r2=336911&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Thu Jul 12 07:56:12 2018
@@ -2888,6 +2888,10 @@ static Value *foldICmpWithLowBitMaskedVa
// x & (-1 >> y) == x -> x u<= (-1 >> y)
DstPred = ICmpInst::Predicate::ICMP_ULE;
break;
+ case ICmpInst::Predicate::ICMP_NE:
+ // x & (-1 >> y) != x -> x u> (-1 >> y)
+ DstPred = ICmpInst::Predicate::ICMP_UGT;
+ break;
// TODO: more folds are possible, https://bugs.llvm.org/show_bug.cgi?id=38123
default:
return nullptr;
Modified: llvm/trunk/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-ne-to-icmp-ugt.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-ne-to-icmp-ugt.ll?rev=336911&r1=336910&r2=336911&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-ne-to-icmp-ugt.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-ne-to-icmp-ugt.ll Thu Jul 12 07:56:12 2018
@@ -15,9 +15,8 @@
define i1 @p0(i8 %x) {
; CHECK-LABEL: @p0(
-; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X:%.*]], 3
-; CHECK-NEXT: [[RET:%.*]] = icmp ne i8 [[TMP0]], [[X]]
-; CHECK-NEXT: ret i1 [[RET]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i8 [[X:%.*]], 3
+; CHECK-NEXT: ret i1 [[TMP1]]
;
%tmp0 = and i8 %x, 3
%ret = icmp ne i8 %tmp0, %x
@@ -30,9 +29,8 @@ define i1 @p0(i8 %x) {
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 ne <2 x i8> [[TMP0]], [[X]]
-; CHECK-NEXT: ret <2 x i1> [[RET]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt <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 ne <2 x i8> %tmp0, %x
@@ -41,9 +39,8 @@ define <2 x i1> @p1_vec_splat(<2 x i8> %
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 ne <2 x i8> [[TMP0]], [[X]]
-; CHECK-NEXT: ret <2 x i1> [[RET]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt <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 ne <2 x i8> %tmp0, %x
@@ -52,9 +49,8 @@ define <2 x i1> @p2_vec_nonsplat(<2 x i8
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 ne <3 x i8> [[TMP0]], [[X]]
-; CHECK-NEXT: ret <3 x i1> [[RET]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt <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 ne <3 x i8> %tmp0, %x
@@ -70,9 +66,8 @@ declare i8 @gen8()
define i1 @c0() {
; CHECK-LABEL: @c0(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
-; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X]], 3
-; CHECK-NEXT: [[RET:%.*]] = icmp ne i8 [[X]], [[TMP0]]
-; CHECK-NEXT: ret i1 [[RET]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i8 [[X]], 3
+; CHECK-NEXT: ret i1 [[TMP1]]
;
%x = call i8 @gen8()
%tmp0 = and i8 %x, 3
@@ -90,8 +85,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 ne i8 [[TMP0]], [[X]]
-; CHECK-NEXT: ret i1 [[RET]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i8 [[X]], 3
+; CHECK-NEXT: ret i1 [[TMP1]]
;
%tmp0 = and i8 %x, 3
call void @use8(i8 %tmp0)
Modified: llvm/trunk/test/Transforms/InstCombine/canonicalize-low-bit-mask-and-icmp-ne-to-icmp-ugt.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/canonicalize-low-bit-mask-and-icmp-ne-to-icmp-ugt.ll?rev=336911&r1=336910&r2=336911&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/canonicalize-low-bit-mask-and-icmp-ne-to-icmp-ugt.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/canonicalize-low-bit-mask-and-icmp-ne-to-icmp-ugt.ll Thu Jul 12 07:56:12 2018
@@ -15,9 +15,8 @@
define i1 @p0(i8 %x, i8 %y) {
; CHECK-LABEL: @p0(
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
-; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[TMP0]], [[X:%.*]]
-; CHECK-NEXT: [[RET:%.*]] = icmp ne i8 [[TMP1]], [[X]]
-; CHECK-NEXT: ret i1 [[RET]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i8 [[TMP0]], [[X:%.*]]
+; CHECK-NEXT: ret i1 [[TMP1]]
;
%tmp0 = lshr i8 -1, %y
%tmp1 = and i8 %tmp0, %x
@@ -32,9 +31,8 @@ define i1 @p0(i8 %x, i8 %y) {
define <2 x i1> @p1_vec(<2 x i8> %x, <2 x i8> %y) {
; CHECK-LABEL: @p1_vec(
; CHECK-NEXT: [[TMP0:%.*]] = lshr <2 x i8> <i8 -1, i8 -1>, [[Y:%.*]]
-; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i8> [[TMP0]], [[X:%.*]]
-; CHECK-NEXT: [[RET:%.*]] = icmp ne <2 x i8> [[TMP1]], [[X]]
-; CHECK-NEXT: ret <2 x i1> [[RET]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ult <2 x i8> [[TMP0]], [[X:%.*]]
+; CHECK-NEXT: ret <2 x i1> [[TMP1]]
;
%tmp0 = lshr <2 x i8> <i8 -1, i8 -1>, %y
%tmp1 = and <2 x i8> %tmp0, %x
@@ -45,9 +43,8 @@ define <2 x i1> @p1_vec(<2 x i8> %x, <2
define <3 x i1> @p2_vec_undef(<3 x i8> %x, <3 x i8> %y) {
; CHECK-LABEL: @p2_vec_undef(
; CHECK-NEXT: [[TMP0:%.*]] = lshr <3 x i8> <i8 -1, i8 undef, i8 -1>, [[Y:%.*]]
-; CHECK-NEXT: [[TMP1:%.*]] = and <3 x i8> [[TMP0]], [[X:%.*]]
-; CHECK-NEXT: [[RET:%.*]] = icmp ne <3 x i8> [[TMP1]], [[X]]
-; CHECK-NEXT: ret <3 x i1> [[RET]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ult <3 x i8> [[TMP0]], [[X:%.*]]
+; CHECK-NEXT: ret <3 x i1> [[TMP1]]
;
%tmp0 = lshr <3 x i8> <i8 -1, i8 undef, i8 -1>, %y
%tmp1 = and <3 x i8> %tmp0, %x
@@ -65,9 +62,8 @@ define i1 @c0(i8 %y) {
; CHECK-LABEL: @c0(
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
-; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X]], [[TMP0]]
-; CHECK-NEXT: [[RET:%.*]] = icmp ne i8 [[TMP1]], [[X]]
-; CHECK-NEXT: ret i1 [[RET]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i8 [[X]], [[TMP0]]
+; CHECK-NEXT: ret i1 [[TMP1]]
;
%tmp0 = lshr i8 -1, %y
%x = call i8 @gen8()
@@ -80,9 +76,8 @@ define i1 @c1(i8 %y) {
; CHECK-LABEL: @c1(
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
-; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[TMP0]], [[X]]
-; CHECK-NEXT: [[RET:%.*]] = icmp ne i8 [[X]], [[TMP1]]
-; CHECK-NEXT: ret i1 [[RET]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i8 [[X]], [[TMP0]]
+; CHECK-NEXT: ret i1 [[TMP1]]
;
%tmp0 = lshr i8 -1, %y
%x = call i8 @gen8()
@@ -95,9 +90,8 @@ define i1 @c2(i8 %y) {
; CHECK-LABEL: @c2(
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
-; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X]], [[TMP0]]
-; CHECK-NEXT: [[RET:%.*]] = icmp ne i8 [[X]], [[TMP1]]
-; CHECK-NEXT: ret i1 [[RET]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i8 [[X]], [[TMP0]]
+; CHECK-NEXT: ret i1 [[TMP1]]
;
%tmp0 = lshr i8 -1, %y
%x = call i8 @gen8()
@@ -116,9 +110,8 @@ define i1 @oneuse0(i8 %x, i8 %y) {
; CHECK-LABEL: @oneuse0(
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
; CHECK-NEXT: call void @use8(i8 [[TMP0]])
-; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[TMP0]], [[X:%.*]]
-; CHECK-NEXT: [[RET:%.*]] = icmp ne i8 [[TMP1]], [[X]]
-; CHECK-NEXT: ret i1 [[RET]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i8 [[TMP0]], [[X:%.*]]
+; CHECK-NEXT: ret i1 [[TMP1]]
;
%tmp0 = lshr i8 -1, %y
call void @use8(i8 %tmp0)
@@ -132,8 +125,8 @@ define i1 @oneuse1(i8 %x, i8 %y) {
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[TMP0]], [[X:%.*]]
; CHECK-NEXT: call void @use8(i8 [[TMP1]])
-; CHECK-NEXT: [[RET:%.*]] = icmp ne i8 [[TMP1]], [[X]]
-; CHECK-NEXT: ret i1 [[RET]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i8 [[TMP0]], [[X]]
+; CHECK-NEXT: ret i1 [[TMP1]]
;
%tmp0 = lshr i8 -1, %y
%tmp1 = and i8 %tmp0, %x
@@ -148,8 +141,8 @@ define i1 @oneuse2(i8 %x, i8 %y) {
; CHECK-NEXT: call void @use8(i8 [[TMP0]])
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[TMP0]], [[X:%.*]]
; CHECK-NEXT: call void @use8(i8 [[TMP1]])
-; CHECK-NEXT: [[RET:%.*]] = icmp ne i8 [[TMP1]], [[X]]
-; CHECK-NEXT: ret i1 [[RET]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i8 [[TMP0]], [[X]]
+; CHECK-NEXT: ret i1 [[TMP1]]
;
%tmp0 = lshr i8 -1, %y
call void @use8(i8 %tmp0)
Modified: llvm/trunk/test/Transforms/InstCombine/icmp-logical.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/icmp-logical.ll?rev=336911&r1=336910&r2=336911&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/icmp-logical.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/icmp-logical.ll Thu Jul 12 07:56:12 2018
@@ -59,9 +59,11 @@ define i1 @masked_or_allones(i32 %A) {
define i1 @masked_and_notA(i32 %A) {
; CHECK-LABEL: @masked_and_notA(
-; CHECK-NEXT: [[MASK2:%.*]] = and i32 [[A:%.*]], 39
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i32 [[A:%.*]], 7
+; CHECK-NEXT: [[MASK2:%.*]] = and i32 [[A]], 39
; CHECK-NEXT: [[TST2:%.*]] = icmp ne i32 [[MASK2]], [[A]]
-; CHECK-NEXT: ret i1 [[TST2]]
+; CHECK-NEXT: [[RES:%.*]] = and i1 [[TMP1]], [[TST2]]
+; CHECK-NEXT: ret i1 [[RES]]
;
%mask1 = and i32 %A, 7
%tst1 = icmp ne i32 %mask1, %A
More information about the llvm-commits
mailing list