[llvm] [InstCombine] Fold shift+cttz with power of 2 operands (PR #127055)
Matthew Devereau via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 13 08:56:46 PST 2025
================
@@ -103,4 +103,38 @@ entry:
ret i32 %res
}
+define i64 @fold_cttz_64() vscale_range(1,16) {
+; CHECK-LABEL: define i64 @fold_cttz_64(
+; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: ret i64 4
+;
+entry:
+ %0 = tail call i64 @llvm.vscale.i64()
+ %1 = shl nuw nsw i64 %0, 4
+ %2 = shl nuw nsw i64 %0, 2
+ %3 = tail call range(i64 2, 65) i64 @llvm.cttz.i64(i64 %2, i1 true)
+ %div1 = lshr i64 %1, %3
+ ret i64 %div1
+}
+
+define i32 @fold_cttz_32() vscale_range(1,16) {
+; CHECK-LABEL: define i32 @fold_cttz_32(
+; CHECK-SAME: ) #[[ATTR0]] {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: ret i32 4
+;
+entry:
+ %0 = tail call i32 @llvm.vscale.i32()
+ %1 = shl nuw nsw i32 %0, 4
+ %2 = shl nuw nsw i32 %0, 2
+ %3 = tail call range(i32 2, 65) i32 @llvm.cttz.i32(i32 %2, i1 true)
+ %div1 = lshr i32 %1, %3
+ ret i32 %div1
+}
+
+declare i64 @llvm.vscale.i64()
+declare i64 @llvm.cttz.i64(i64, i1 immarg)
+declare i32 @llvm.vscale.i32()
+declare i32 @llvm.cttz.i32(i32, i1 immarg)
----------------
MDevereau wrote:
Removed
https://github.com/llvm/llvm-project/pull/127055
More information about the llvm-commits
mailing list