[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 10:30:43 PDT 2021
xbolva00 updated this revision to Diff 342795.
xbolva00 added a comment.
Rebased.
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)
@@ -1484,8 +1482,7 @@
; CHECK-LABEL: @ctlz_negative_zero_undef(
; CHECK-NEXT: [[ASSUME:%.*]] = icmp slt i32 [[X:%.*]], 0
; CHECK-NEXT: call void @llvm.assume(i1 [[ASSUME]])
-; CHECK-NEXT: [[C:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X]], i1 true)
-; CHECK-NEXT: ret i32 [[C]]
+; CHECK-NEXT: ret i32 0
;
%assume = icmp slt i32 %x, 0
call void @llvm.assume(i1 %assume)
@@ -1497,8 +1494,7 @@
; CHECK-LABEL: @ctlz_negative_zero_def(
; CHECK-NEXT: [[ASSUME:%.*]] = icmp slt i32 [[X:%.*]], 0
; CHECK-NEXT: call void @llvm.assume(i1 [[ASSUME]])
-; CHECK-NEXT: [[C:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X]], i1 false)
-; CHECK-NEXT: ret i32 [[C]]
+; CHECK-NEXT: ret i32 0
;
%assume = icmp slt i32 %x, 0
call void @llvm.assume(i1 %assume)
@@ -1510,9 +1506,7 @@
; 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)
@@ -1528,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.342795.patch
Type: text/x-patch
Size: 2772 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210504/c0bcbb9f/attachment.bin>
More information about the llvm-commits
mailing list