[PATCH] D87161: [DemandedBits][BDCE] Add support for min/max intrinsics
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 4 13:46:00 PDT 2020
nikic created this revision.
nikic added reviewers: lebedev.ri, spatel, hfinkel.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
nikic requested review of this revision.
Add DemandedBits / BDCE support for min/max intrinsics: If the low bits are not demanded in the result, they also aren't demanded in the operands.
We'll want the same in InstCombineSimplifyDemanded, but we need KnownBits support to land first, so that's waiting on D87034 <https://reviews.llvm.org/D87034>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D87161
Files:
llvm/lib/Analysis/DemandedBits.cpp
llvm/test/Transforms/BDCE/intrinsics.ll
Index: llvm/test/Transforms/BDCE/intrinsics.ll
===================================================================
--- llvm/test/Transforms/BDCE/intrinsics.ll
+++ llvm/test/Transforms/BDCE/intrinsics.ll
@@ -8,8 +8,8 @@
define i8 @umax(i8 %x, i8 %y, i1 %a, i1 %b) {
; CHECK-LABEL: @umax(
-; CHECK-NEXT: [[A2:%.*]] = zext i1 [[A:%.*]] to i8
-; CHECK-NEXT: [[B2:%.*]] = zext i1 [[B:%.*]] to i8
+; CHECK-NEXT: [[A2:%.*]] = zext i1 false to i8
+; CHECK-NEXT: [[B2:%.*]] = zext i1 false to i8
; CHECK-NEXT: [[X2:%.*]] = or i8 [[X:%.*]], [[A2]]
; CHECK-NEXT: [[Y2:%.*]] = or i8 [[Y:%.*]], [[B2]]
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umax.i8(i8 [[X2]], i8 [[Y2]])
@@ -27,8 +27,8 @@
define i8 @umin(i8 %x, i8 %y, i1 %a, i1 %b) {
; CHECK-LABEL: @umin(
-; CHECK-NEXT: [[A2:%.*]] = zext i1 [[A:%.*]] to i8
-; CHECK-NEXT: [[B2:%.*]] = zext i1 [[B:%.*]] to i8
+; CHECK-NEXT: [[A2:%.*]] = zext i1 false to i8
+; CHECK-NEXT: [[B2:%.*]] = zext i1 false to i8
; CHECK-NEXT: [[X2:%.*]] = or i8 [[X:%.*]], [[A2]]
; CHECK-NEXT: [[Y2:%.*]] = or i8 [[Y:%.*]], [[B2]]
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umin.i8(i8 [[X2]], i8 [[Y2]])
@@ -46,8 +46,8 @@
define i8 @smax(i8 %x, i8 %y, i1 %a, i1 %b) {
; CHECK-LABEL: @smax(
-; CHECK-NEXT: [[A2:%.*]] = zext i1 [[A:%.*]] to i8
-; CHECK-NEXT: [[B2:%.*]] = zext i1 [[B:%.*]] to i8
+; CHECK-NEXT: [[A2:%.*]] = zext i1 false to i8
+; CHECK-NEXT: [[B2:%.*]] = zext i1 false to i8
; CHECK-NEXT: [[X2:%.*]] = or i8 [[X:%.*]], [[A2]]
; CHECK-NEXT: [[Y2:%.*]] = or i8 [[Y:%.*]], [[B2]]
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smax.i8(i8 [[X2]], i8 [[Y2]])
@@ -65,8 +65,8 @@
define i8 @smin(i8 %x, i8 %y, i1 %a, i1 %b) {
; CHECK-LABEL: @smin(
-; CHECK-NEXT: [[A2:%.*]] = zext i1 [[A:%.*]] to i8
-; CHECK-NEXT: [[B2:%.*]] = zext i1 [[B:%.*]] to i8
+; CHECK-NEXT: [[A2:%.*]] = zext i1 false to i8
+; CHECK-NEXT: [[B2:%.*]] = zext i1 false to i8
; CHECK-NEXT: [[X2:%.*]] = or i8 [[X:%.*]], [[A2]]
; CHECK-NEXT: [[Y2:%.*]] = or i8 [[Y:%.*]], [[B2]]
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smin.i8(i8 [[X2]], i8 [[Y2]])
Index: llvm/lib/Analysis/DemandedBits.cpp
===================================================================
--- llvm/lib/Analysis/DemandedBits.cpp
+++ llvm/lib/Analysis/DemandedBits.cpp
@@ -170,6 +170,14 @@
}
break;
}
+ case Intrinsic::umax:
+ case Intrinsic::umin:
+ case Intrinsic::smax:
+ case Intrinsic::smin:
+ // If low bits of result are not demanded, they are also not demanded
+ // for the min/max operands.
+ AB = APInt::getBitsSetFrom(BitWidth, AOut.countTrailingZeros());
+ break;
}
break;
case Instruction::Add:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87161.290022.patch
Type: text/x-patch
Size: 2760 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200904/17fe8d20/attachment.bin>
More information about the llvm-commits
mailing list