[PATCH] D117365: [InstCombine] optimize icmp-ugt-ashr
Nadav Rotem via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 14 16:08:19 PST 2022
nadav updated this revision to Diff 400177.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D117365/new/
https://reviews.llvm.org/D117365
Files:
lib/Transforms/InstCombine/InstCombineCompares.cpp
test/Transforms/InstCombine/icmp-shr-lt-gt.ll
test/Transforms/InstCombine/icmp-shr.ll
Index: test/Transforms/InstCombine/icmp-shr.ll
===================================================================
--- test/Transforms/InstCombine/icmp-shr.ll
+++ test/Transforms/InstCombine/icmp-shr.ll
@@ -574,12 +574,9 @@
ret i1 %r
}
-; negative test
-
define i1 @ashr_ugt_1(i4 %x) {
; CHECK-LABEL: @ashr_ugt_1(
-; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1
-; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[S]], 1
+; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[X:%.*]], 3
; CHECK-NEXT: ret i1 [[R]]
;
%s = ashr i4 %x, 1
@@ -587,12 +584,9 @@
ret i1 %r
}
-; negative test
-
define i1 @ashr_ugt_2(i4 %x) {
; CHECK-LABEL: @ashr_ugt_2(
-; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1
-; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[S]], 2
+; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[X:%.*]], 5
; CHECK-NEXT: ret i1 [[R]]
;
%s = ashr i4 %x, 1
@@ -694,12 +688,9 @@
ret i1 %r
}
-; negative test
-
define i1 @ashr_ugt_12(i4 %x) {
; CHECK-LABEL: @ashr_ugt_12(
-; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1
-; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[S]], -4
+; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[X:%.*]], -7
; CHECK-NEXT: ret i1 [[R]]
;
%s = ashr i4 %x, 1
@@ -707,12 +698,9 @@
ret i1 %r
}
-; negative test
-
define i1 @ashr_ugt_13(i4 %x) {
; CHECK-LABEL: @ashr_ugt_13(
-; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1
-; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[S]], -3
+; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[X:%.*]], -5
; CHECK-NEXT: ret i1 [[R]]
;
%s = ashr i4 %x, 1
Index: test/Transforms/InstCombine/icmp-shr-lt-gt.ll
===================================================================
--- test/Transforms/InstCombine/icmp-shr-lt-gt.ll
+++ test/Transforms/InstCombine/icmp-shr-lt-gt.ll
@@ -2344,8 +2344,7 @@
define i1 @ashr_ugt_noexact(i8 %x) {
; CHECK-LABEL: @ashr_ugt_noexact(
-; CHECK-NEXT: [[S:%.*]] = ashr i8 [[X:%.*]], 3
-; CHECK-NEXT: [[C:%.*]] = icmp ugt i8 [[S]], 10
+; CHECK-NEXT: [[C:%.*]] = icmp ugt i8 [[X:%.*]], 87
; CHECK-NEXT: ret i1 [[C]]
;
%s = ashr i8 %x, 3
@@ -2356,8 +2355,7 @@
define i1 @ashr_uge_noexact(i8 %x) {
; CHECK-LABEL: @ashr_uge_noexact(
-; CHECK-NEXT: [[S:%.*]] = ashr i8 [[X:%.*]], 3
-; CHECK-NEXT: [[C:%.*]] = icmp ugt i8 [[S]], 9
+; CHECK-NEXT: [[C:%.*]] = icmp ugt i8 [[X:%.*]], 79
; CHECK-NEXT: ret i1 [[C]]
;
%s = ashr i8 %x, 3
Index: lib/Transforms/InstCombine/InstCombineCompares.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -2247,8 +2247,8 @@
if (ShiftedC.ashr(ShAmtVal) == C)
return new ICmpInst(Pred, X, ConstantInt::get(ShrTy, ShiftedC));
}
- if (Pred == CmpInst::ICMP_SGT) {
- // icmp sgt (ashr X, ShAmtC), C --> icmp sgt X, ((C + 1) << ShAmtC) - 1
+ if (Pred == CmpInst::ICMP_SGT || Pred == CmpInst::ICMP_UGT) {
+ // icmp xgt (ashr X, ShAmtC), C --> icmp xgt X, ((C + 1) << ShAmtC) - 1
APInt ShiftedC = (C + 1).shl(ShAmtVal) - 1;
if (!C.isMaxSignedValue() && !(C + 1).shl(ShAmtVal).isMinSignedValue() &&
(ShiftedC + 1).ashr(ShAmtVal) == (C + 1))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117365.400177.patch
Type: text/x-patch
Size: 3211 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220115/5724612d/attachment.bin>
More information about the llvm-commits
mailing list