[llvm-branch-commits] [SPARC] Use lzcnt to implement CTLZ when we have VIS3 (PR #135715)
Sergei Barannikov via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Apr 15 10:19:39 PDT 2025
================
@@ -303,4 +303,10 @@ def : Pat<(i64 (mulhs i64:$lhs, i64:$rhs)),
(SUBrr (UMULXHI $lhs, $rhs),
(ADDrr (ANDrr (SRAXri $lhs, 63), $rhs),
(ANDrr (SRAXri $rhs, 63), $lhs)))>;
+
+def : Pat<(i64 (ctlz i64:$src)), (LZCNT $src)>;
+// 32-bit LZCNT.
+// The zero extension will leave us with 32 extra leading zeros,
+// so we need to compensate for it.
+def : Pat<(i32 (ctlz i32:$src)), (ADDri (LZCNT (SRLri $src, 0)), (i32 -32))>;
----------------
s-barannikov wrote:
Probably because `CTLZ_ZERO_UNDEF` is expanded. It should be treated the same way as `CTLZ`.
(Note: Sparc's LCTNZ appears to have well-defined behavior for zero input, unlike equivalent instructions on most other targets. If the behavior was not defined, the instruction would naturally match to `CTLZ_ZERO_UNDEF`, and `CTLZ` would need to be expanded.)
https://github.com/llvm/llvm-project/pull/135715
More information about the llvm-branch-commits
mailing list