[PATCH] D99147: Never sinking if none operand is used in or after loop exit block
zhengping.hu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 22 23:10:11 PDT 2021
xjtuhu created this revision.
xjtuhu added reviewers: mkazantsev, skatkov.
Herald added a subscriber: hiraditya.
xjtuhu requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
IndVarSimplify::sinkUnusedInvariants would sink a instruction from a loop's preheader block to exit block to reduce register pressure. But the optimization is not conservative, it could increase register pressure conversely if none operand is used in or after loop exit block, because sinking could extend operands' liveness range hence increase register pressure.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D99147
Files:
llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
Index: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -1265,6 +1265,32 @@
if (UsedInLoop)
continue;
+ // If none operand is used in or after the loop exit block, sinking the
+ // instruction from pre-header to exit block will extend operands'
+ // live range, hence could increase register pressure. The instruction
+ // should not be sinked for conservativeness.
+ bool OperandsUsedAfterLoop = false;
+ for (Value *Op : I->operands()) {
+ if (isa<Constant>(Op)) {
+ continue;
+ }
+ for (Use &U : Op->uses()) {
+ Instruction *User = cast<Instruction>(U.getUser());
+ BasicBlock *UseBB = User->getParent();
+ if (PHINode *P = dyn_cast<PHINode>(User)) {
+ unsigned i =
+ PHINode::getIncomingValueNumForOperand(U.getOperandNo());
+ UseBB = P->getIncomingBlock(i);
+ }
+ if (DT->dominates(ExitBlock, UseBB)) {
+ OperandsUsedAfterLoop = true;
+ break;
+ }
+ }
+ }
+ if (!OperandsUsedAfterLoop)
+ continue;
+
// Otherwise, sink it to the exit block.
Instruction *ToMove = &*I;
bool Done = false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99147.332534.patch
Type: text/x-patch
Size: 1334 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210323/26934dd9/attachment.bin>
More information about the llvm-commits
mailing list