[llvm] [X86] Promote cttz_i32(x) -> cttz_i64((i64)x | (1 << 32)) (PR #102900)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 12 07:48:44 PDT 2024


================
@@ -3237,9 +3238,10 @@ bool X86TargetLowering::shouldFormOverflowOp(unsigned Opcode, EVT VT,
 }
 
 bool X86TargetLowering::isCheapToSpeculateCttz(Type *Ty) const {
-  // Speculate cttz only if we can directly use TZCNT or can promote to i32.
+  // Speculate cttz only if we can directly use TZCNT or can promote to i32/i64.
   return Subtarget.hasBMI() ||
-         (!Ty->isVectorTy() && Ty->getScalarSizeInBits() < 32);
+         (!Ty->isVectorTy() &&
+          Ty->getScalarSizeInBits() < (Subtarget.is64Bit() ? 64u : 32u));
----------------
RKSimon wrote:

It fixes an annoying MSVC warning (I have /WX enabled) - it can't correctly see through the ternary to check the bounds of the int values. I can pull out the max bounds value instead if you prefer?

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


More information about the llvm-commits mailing list