[llvm] [SLSR] Adding a cost model considering register pressure (PR #213808)
Igor Wodiany via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 13 03:13:31 PDT 2026
================
@@ -1378,11 +1505,50 @@ bool StraightLineStrengthReduce::runOnFunction(Function &F) {
}
sortCandidateInstructions();
+ // From SortedCandidateInsts, remove some candidates that are likely to
+ // increase register pressure. The candidate's Inst is the source of
+ // replacement. A candidate in the following criteria should be removed:
+ // 1. The candidate's Inst "has operands used in non-rewritable users in
+ // another block"
+ // -- checked by hasOperandsUsedInNonRewritableUsersInAnotherBlock(Inst)
+ // -- This means the candidate's Inst's original operands are live in
+ // another block, so even if rewrite the Inst, the operands may be still
+ // live out to another block.
+ // -- Thus, rewriting the Inst based on Basis might add another long live
+ // range from the Basis by increasing the live range of the Basis.
+ // -- TODO: If needed, a refinement to check that "another block" is
+ // properly dominated by the candidate's Inst's block can be added.
+ // 2. When the candidate's Basis's is only used in the the same block
+ // and its last use is before the candidate's Inst, the difference between the
+ // last use of Basis and the Inst is larger than a threshold.
+ // -- This is also for avoiding increasing the live range of the Basis by
+ // rewriting the Inst.
+ //
+ // A candidate satisfies both conditions 1 and 2 should be removed.
+
+ // Collect candidates likely to increase register pressure.
+ // Evaluate on the original IR, before any rewriteCandidate mutates it
+ // Done before rewriting: rewriting inserts instructions and does
+ // replaceAllUsesWith, which would invalidate both the in-block index map and
+ // operands' user sets.
+ DenseSet<Instruction *> ToSkipRewrite;
+ {
----------------
IgWod wrote:
Any reason to have braces around this code?
https://github.com/llvm/llvm-project/pull/213808
More information about the llvm-commits
mailing list