[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
Wed Apr 16 15:51:29 PDT 2025


================
@@ -1815,7 +1817,8 @@ SparcTargetLowering::SparcTargetLowering(const TargetMachine &TM,
   setOperationAction(ISD::FREM , MVT::f32, Expand);
   setOperationAction(ISD::FMA  , MVT::f32, Expand);
   setOperationAction(ISD::CTTZ , MVT::i32, Expand);
-  setOperationAction(ISD::CTLZ , MVT::i32, Expand);
+  setOperationAction(ISD::CTLZ, MVT::i32,
+                     Subtarget->isVIS3() ? Promote : LibCall);
----------------
s-barannikov wrote:

The libcall corresponds to `_ZERO_UNDEF` version (it doesn't support zero input), hence no changes in tests.
`CTLZ` should be left set to `Expand`, it should be expanded into a zero check + libcall + select.

---
It may be worth double checking that `libgcc` provides `clzsi2`. It may so happen that it only provides 64-bit version (`clzdi2`) on 64-bit Sparc.
`compiler-rt` should provide both, but if I'm not mistaken it is not the default compiler support library?


https://github.com/llvm/llvm-project/pull/135715


More information about the llvm-branch-commits mailing list