[llvm] [CGP] Despeculate ctlz/cttz with "illegal" integer types (PR #137197)

Sergei Barannikov via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 24 22:39:14 PDT 2025


================
@@ -285,30 +285,35 @@ define i32 @ctlo_i32_undef(i32 %x) {
   ret i32 %tmp2
 }
 
-define i64 @ctlo_i64(i64 %x) {
+define i64 @ctlo_i64(i64 %x) nounwind {
 ; X86-NOCMOV-LABEL: ctlo_i64:
 ; X86-NOCMOV:       # %bb.0:
+; X86-NOCMOV-NEXT:    pushl %esi
----------------
s-barannikov wrote:

64-bit platform is unaffected by this change. It has `bsf` with passthrough or `lzcnt` which are said to always be cheap to speculate.
```
bool X86TargetLowering::isCheapToSpeculateCtlz(Type *Ty) const {
  // Speculate ctlz only if we can directly use LZCNT/CMOV, or can rely on BSR
  // passthrough value.
  return Subtarget.hasLZCNT() || Subtarget.canUseCMOV() ||
         Subtarget.hasBitScanPassThrough();
}
```

The only affected processors seem to be 32-bit without `cmov`.


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


More information about the llvm-commits mailing list