[llvm] [SimplifyCFG] Relax `cttz` cost check in `simplifySwitchOfPowersOfTwo` (PR #145159)
Antonio Frighetto via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 23 00:27:08 PDT 2025
================
@@ -7211,17 +7213,15 @@ static bool simplifySwitchOfPowersOfTwo(SwitchInst *SI, IRBuilder<> &Builder,
!DL.fitsInLegalInteger(CondTy->getIntegerBitWidth()))
return false;
- const auto CttzIntrinsicCost = TTI.getIntrinsicInstrCost(
- IntrinsicCostAttributes(Intrinsic::cttz, CondTy,
- {Condition, ConstantInt::getTrue(Context)}),
- TTI::TCK_SizeAndLatency);
-
- if (CttzIntrinsicCost > TTI::TCC_Basic)
- // Inserting intrinsic is too expensive.
+ // Ensure trailing zeroes count intrinsic emission is not too expensive.
+ IntrinsicCostAttributes Attrs(Intrinsic::cttz, CondTy,
+ {Condition, ConstantInt::getTrue(Context)});
+ if (TTI.getIntrinsicInstrCost(Attrs, TTI::TCK_SizeAndLatency) >
+ TTI::TCC_Basic * 2)
----------------
antoniofrighetto wrote:
> Can we increase the threshold to `< TCC_Expensive` as it is also used in other places?
I think keeping the threshold under or equal to 2 should make sense here (`< TCC_Expensive` may be already too permissive).
https://github.com/llvm/llvm-project/pull/145159
More information about the llvm-commits
mailing list