[llvm] Optimize count leading ones if promoted type (PR #99591)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 5 02:18:45 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:
In this file, we have in other parts `int ISDOpcode = ...`, that's why I use `int`. But it seems there is no usage of setting a variable with an `ISD::<Variant>` with an `int` in the code base.
https://github.com/llvm/llvm-project/pull/99591
More information about the llvm-commits
mailing list