[llvm] [SimplifyCFG] Treat umul + extract pattern as cheap single instruction. (PR #124933)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 30 18:42:57 PST 2025
================
@@ -3329,20 +3331,29 @@ bool SimplifyCFGOpt::speculativelyExecuteBB(BranchInst *BI,
else
++SpeculatedInstructions;
- if (SpeculatedInstructions > 1)
- return false;
-
// Don't hoist the instruction if it's unsafe or expensive.
if (!IsSafeCheapLoadStore &&
!isSafeToSpeculativelyExecute(&I, BI, Options.AC) &&
!(HoistCondStores && !SpeculatedStoreValue &&
(SpeculatedStoreValue =
isSafeToSpeculateStore(&I, BB, ThenBB, EndBB))))
return false;
- if (!IsSafeCheapLoadStore && !SpeculatedStoreValue &&
- computeSpeculationCost(&I, TTI) >
+
+ if (match(&I,
+ m_ExtractValue<1>(m_OneUse(
+ m_Intrinsic<Intrinsic::umul_with_overflow>(m_Value())))) &&
+ ThenBB->size() <= 3)
+ PatternFound = true;
+
+ BlockCostSoFar += computeSpeculationCost(&I, TTI);
+ if (!PatternFound && !IsSafeCheapLoadStore && !SpeculatedStoreValue &&
+ BlockCostSoFar >
PHINodeFoldingThreshold * TargetTransformInfo::TCC_Basic)
return false;
+ // If we don't find any pattern, that must be cheap, then only speculatively
+ // execute a single instruction (not counting the terminator).
+ if (!PatternFound && SpeculatedInstructions > 1)
+ return false;
----------------
goldsteinn wrote:
I think it may be easier to just add a `MaxSpeculatedInstructionsToHoist` variable and increment it if you find an overflow intrinsic whose only user is an extract.
https://github.com/llvm/llvm-project/pull/124933
More information about the llvm-commits
mailing list