[llvm] 0a2d694 - [InstSimplify] cttz(1<<x) --> x
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 8 13:31:14 PST 2021
Author: Sanjay Patel
Date: 2021-03-08T16:30:14-05:00
New Revision: 0a2d69480da7e4a66c0fa118ec4d10710579551d
URL: https://github.com/llvm/llvm-project/commit/0a2d69480da7e4a66c0fa118ec4d10710579551d
DIFF: https://github.com/llvm/llvm-project/commit/0a2d69480da7e4a66c0fa118ec4d10710579551d.diff
LOG: [InstSimplify] cttz(1<<x) --> x
https://alive2.llvm.org/ce/z/TDacYu
https://alive2.llvm.org/ce/z/KF84S3
Added:
Modified:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/call.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index d3b82d5cfb8e..632741e2c737 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5485,6 +5485,12 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1,
return Op0;
break;
+ case Intrinsic::cttz: {
+ Value *X;
+ if (match(Op0, m_Shl(m_One(), m_Value(X))))
+ return X;
+ break;
+ }
case Intrinsic::smax:
case Intrinsic::smin:
case Intrinsic::umax:
diff --git a/llvm/test/Transforms/InstSimplify/call.ll b/llvm/test/Transforms/InstSimplify/call.ll
index c89f0048237e..5b4acb59c270 100644
--- a/llvm/test/Transforms/InstSimplify/call.ll
+++ b/llvm/test/Transforms/InstSimplify/call.ll
@@ -1365,9 +1365,7 @@ declare <3 x i33> @llvm.cttz.v3i33(<3 x i33>, i1)
define i32 @cttz_shl1(i32 %x) {
; CHECK-LABEL: @cttz_shl1(
-; CHECK-NEXT: [[S:%.*]] = shl i32 1, [[X:%.*]]
-; CHECK-NEXT: [[R:%.*]] = call i32 @llvm.cttz.i32(i32 [[S]], i1 true)
-; CHECK-NEXT: ret i32 [[R]]
+; CHECK-NEXT: ret i32 [[X:%.*]]
;
%s = shl i32 1, %x
%r = call i32 @llvm.cttz.i32(i32 %s, i1 true)
@@ -1376,9 +1374,7 @@ define i32 @cttz_shl1(i32 %x) {
define <3 x i33> @cttz_shl1_vec(<3 x i33> %x) {
; CHECK-LABEL: @cttz_shl1_vec(
-; CHECK-NEXT: [[S:%.*]] = shl <3 x i33> <i33 1, i33 1, i33 undef>, [[X:%.*]]
-; CHECK-NEXT: [[R:%.*]] = call <3 x i33> @llvm.cttz.v3i33(<3 x i33> [[S]], i1 false)
-; CHECK-NEXT: ret <3 x i33> [[R]]
+; CHECK-NEXT: ret <3 x i33> [[X:%.*]]
;
%s = shl <3 x i33> <i33 1, i33 1, i33 undef>, %x
%r = call <3 x i33> @llvm.cttz.v3i33(<3 x i33> %s, i1 false)
More information about the llvm-commits
mailing list