[PATCH] D101840: [InstSimplify] ctlz(x) -> 0 if x is known negative number
Dávid Bolvanský via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 4 08:46:00 PDT 2021
xbolva00 updated this revision to Diff 342757.
xbolva00 added a comment.
Generalization.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D101840/new/
https://reviews.llvm.org/D101840
Files:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/call.ll
Index: llvm/test/Transforms/InstSimplify/call.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/call.ll
+++ llvm/test/Transforms/InstSimplify/call.ll
@@ -1469,9 +1469,7 @@
; CHECK-LABEL: @ctlz_sext_negative_zero_undef(
; CHECK-NEXT: [[ASSUME:%.*]] = icmp slt i16 [[X:%.*]], 0
; CHECK-NEXT: call void @llvm.assume(i1 [[ASSUME]])
-; CHECK-NEXT: [[S:%.*]] = sext i16 [[X]] to i32
-; CHECK-NEXT: [[C:%.*]] = call i32 @llvm.ctlz.i32(i32 [[S]], i1 true)
-; CHECK-NEXT: ret i32 [[C]]
+; CHECK-NEXT: ret i32 0
;
%assume = icmp slt i16 %x, 0
call void @llvm.assume(i1 %assume)
@@ -1480,13 +1478,35 @@
ret i32 %c
}
+define i32 @ctlz_negative_zero_undef(i32 %x) {
+; CHECK-LABEL: @ctlz_negative_zero_undef(
+; CHECK-NEXT: [[ASSUME:%.*]] = icmp slt i32 [[X:%.*]], 0
+; CHECK-NEXT: call void @llvm.assume(i1 [[ASSUME]])
+; CHECK-NEXT: ret i32 0
+;
+ %assume = icmp slt i32 %x, 0
+ call void @llvm.assume(i1 %assume)
+ %c = call i32 @llvm.ctlz.i32(i32 %x, i1 true)
+ ret i32 %c
+}
+
+define i32 @ctlz_negative_zero_def(i32 %x) {
+; CHECK-LABEL: @ctlz_negative_zero_def(
+; CHECK-NEXT: [[ASSUME:%.*]] = icmp slt i32 [[X:%.*]], 0
+; CHECK-NEXT: call void @llvm.assume(i1 [[ASSUME]])
+; CHECK-NEXT: ret i32 0
+;
+ %assume = icmp slt i32 %x, 0
+ call void @llvm.assume(i1 %assume)
+ %c = call i32 @llvm.ctlz.i32(i32 %x, i1 false)
+ ret i32 %c
+}
+
define i32 @ctlz_sext_negative_zero_def(i16 %x) {
; CHECK-LABEL: @ctlz_sext_negative_zero_def(
; CHECK-NEXT: [[ASSUME:%.*]] = icmp slt i16 [[X:%.*]], 0
; CHECK-NEXT: call void @llvm.assume(i1 [[ASSUME]])
-; CHECK-NEXT: [[S:%.*]] = sext i16 [[X]] to i32
-; CHECK-NEXT: [[C:%.*]] = call i32 @llvm.ctlz.i32(i32 [[S]], i1 false)
-; CHECK-NEXT: ret i32 [[C]]
+; CHECK-NEXT: ret i32 0
;
%assume = icmp slt i16 %x, 0
call void @llvm.assume(i1 %assume)
@@ -1502,8 +1522,7 @@
; CHECK-NEXT: call void @llvm.assume(i1 [[ASSUME]])
; CHECK-NEXT: [[S:%.*]] = sext i16 [[X]] to i32
; CHECK-NEXT: call void @use(i32 [[S]])
-; CHECK-NEXT: [[C:%.*]] = call i32 @llvm.ctlz.i32(i32 [[S]], i1 true)
-; CHECK-NEXT: ret i32 [[C]]
+; CHECK-NEXT: ret i32 0
;
%assume = icmp slt i16 %x, 0
call void @llvm.assume(i1 %assume)
Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5411,6 +5411,8 @@
return X;
if (match(Op0, m_AShr(m_Negative(), m_Value())))
return Constant::getNullValue(ReturnType);
+ if (isKnownNegative(Op0, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT))
+ return Constant::getNullValue(ReturnType);
break;
}
case Intrinsic::smax:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101840.342757.patch
Type: text/x-patch
Size: 2818 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210504/4a5ced5e/attachment.bin>
More information about the llvm-commits
mailing list