[PATCH] D101764: [InstCombine] cttz(sext(x)) -> cttz(zext(x))
Dávid Bolvanský via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 3 09:36:14 PDT 2021
xbolva00 updated this revision to Diff 342425.
xbolva00 retitled this revision from "[InstCombine] cttz(sext(x)) -> zext(cttz(x))" to "[InstCombine] cttz(sext(x)) -> cttz(zext(x))".
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D101764/new/
https://reviews.llvm.org/D101764
Files:
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/test/Transforms/InstCombine/cttz.ll
Index: llvm/test/Transforms/InstCombine/cttz.ll
===================================================================
--- llvm/test/Transforms/InstCombine/cttz.ll
+++ llvm/test/Transforms/InstCombine/cttz.ll
@@ -64,9 +64,9 @@
define i32 @cttz_sext_zero_undef(i16 %x) {
; CHECK-LABEL: @cttz_sext_zero_undef(
-; CHECK-NEXT: [[S:%.*]] = sext i16 [[X:%.*]] to i32
-; CHECK-NEXT: [[TZ:%.*]] = call i32 @llvm.cttz.i32(i32 [[S]], i1 true), !range [[RNG1]]
-; CHECK-NEXT: ret i32 [[TZ]]
+; CHECK-NEXT: [[TMP1:%.*]] = call i16 @llvm.cttz.i16(i16 [[X:%.*]], i1 true), !range [[RNG0]]
+; CHECK-NEXT: [[TMP2:%.*]] = zext i16 [[TMP1]] to i32
+; CHECK-NEXT: ret i32 [[TMP2]]
;
%s = sext i16 %x to i32
%tz = call i32 @llvm.cttz.i32(i32 %s, i1 true)
@@ -99,9 +99,9 @@
define <2 x i64> @cttz_sext_zero_undef_vec(<2 x i32> %x) {
; CHECK-LABEL: @cttz_sext_zero_undef_vec(
-; CHECK-NEXT: [[S:%.*]] = sext <2 x i32> [[X:%.*]] to <2 x i64>
-; CHECK-NEXT: [[TZ:%.*]] = tail call <2 x i64> @llvm.cttz.v2i64(<2 x i64> [[S]], i1 true)
-; CHECK-NEXT: ret <2 x i64> [[TZ]]
+; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> [[X:%.*]], i1 true)
+; CHECK-NEXT: [[TMP2:%.*]] = zext <2 x i32> [[TMP1]] to <2 x i64>
+; CHECK-NEXT: ret <2 x i64> [[TMP2]]
;
%s = sext <2 x i32> %x to <2 x i64>
%tz = tail call <2 x i64> @llvm.cttz.v2i64(<2 x i64> %s, i1 true)
@@ -110,9 +110,9 @@
define <2 x i64> @cttz_sext_zero_def_vec(<2 x i32> %x) {
; CHECK-LABEL: @cttz_sext_zero_def_vec(
-; CHECK-NEXT: [[S:%.*]] = sext <2 x i32> [[X:%.*]] to <2 x i64>
-; CHECK-NEXT: [[TZ:%.*]] = tail call <2 x i64> @llvm.cttz.v2i64(<2 x i64> [[S]], i1 false)
-; CHECK-NEXT: ret <2 x i64> [[TZ]]
+; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> [[X:%.*]], i1 false)
+; CHECK-NEXT: [[TMP2:%.*]] = zext <2 x i32> [[TMP1]] to <2 x i64>
+; CHECK-NEXT: ret <2 x i64> [[TMP2]]
;
%s = sext <2 x i32> %x to <2 x i64>
%tz = tail call <2 x i64> @llvm.cttz.v2i64(<2 x i64> %s, i1 false)
Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -448,6 +448,14 @@
return IC.replaceInstUsesWith(II, ZextCttz);
}
+ // Sext doesn't change the number of trailing zeros, so narrow:
+ // cttz(sext(x)) -> zext(cttz(x))
+ if (match(Op0, m_OneUse(m_SExt(m_Value(X))))) {
+ auto *Cttz = IC.Builder.CreateBinaryIntrinsic(Intrinsic::cttz, X, Op1);
+ auto *ZextCttz = IC.Builder.CreateZExt(Cttz, II.getType());
+ return IC.replaceInstUsesWith(II, ZextCttz);
+ }
+
// cttz(abs(x)) -> cttz(x)
// cttz(nabs(x)) -> cttz(x)
Value *Y;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101764.342425.patch
Type: text/x-patch
Size: 2816 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210503/9052ecc5/attachment.bin>
More information about the llvm-commits
mailing list