[llvm] Optimize count leading ones if promoted type (PR #99591)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 25 10:34:21 PDT 2024


================
@@ -2310,6 +2310,26 @@ static bool despeculateCountZeros(IntrinsicInst *CountZeros,
   if (Ty->isVectorTy() || SizeInBits > DL->getLargestLegalIntTypeSizeInBits())
     return false;
 
+  // Do not despeculate if we have (ctlz/cttz (xor op -1)) if the operand is
+  // promoted as legalisation should be later able to transform it to:
+  //
+  // ctlz:
+  // (ctlz_zero_undef (lshift (xor (extend op) -1)
+  //                          lshiftamount))
+  //
+  // cttz:
+  // (cttz_zero_undef (xor (zeroextend op) -1))
+  //
+  // Despeculation is not only useless but also not wanted with SelectionDAG
+  // as XOR and CTLZ/CTTZ would be in different basic blocks.
+  EVT VTy = TLI->getValueType(*DL, Ty);
+  int ISDOpcode = IntrinsicID == Intrinsic::ctlz ? ISD::CTLZ : ISD::CTTZ;
----------------
v01dXYZ wrote:

No because of the check above early exiting if `Operand[1] ~= One`. 

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


More information about the llvm-commits mailing list