[PATCH] D125670: [LSR] Early exit for RateFormula when it is already losing

Yueh-Ting (eop) Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 16 01:29:47 PDT 2022


eopXD created this revision.
eopXD added reviewers: reames, SjoerdMeijer, evstupac.
Herald added a subscriber: hiraditya.
Herald added a project: All.
eopXD requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The codebase implicitly implies that Cost::RateFormula is only called
when the Cost is not in losing status, or else there may be possible
to trigger the assertion of Cost::isValid.

A safe way is to direct return when the cost is already losing.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125670

Files:
  llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp


Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -1355,6 +1355,8 @@
                        const DenseSet<const SCEV *> &VisitedRegs,
                        const LSRUse &LU,
                        SmallPtrSetImpl<const SCEV *> *LoserRegs) {
+  if (isLoser())
+    return;
   assert(F.isCanonical(*L) && "Cost is accurate only for canonical formula");
   // Tally up the registers.
   unsigned PrevAddRecCost = C.AddRecCost;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125670.429643.patch
Type: text/x-patch
Size: 615 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220516/76712958/attachment.bin>


More information about the llvm-commits mailing list