Skip to content

Commit ec05331

Browse files
committed
nv50/ir: only stick one preret per function
A function with multiple returns would have had multiple preret settings at the top of the function. While this is unlikely to have caused issues since we don't use functions in earnest, it could have in some cases overflowed the call stack, in case a function had a lot of early returns. Signed-off-by: Ilia Mirkin <[email protected]> Reviewed-by: Samuel Pitoiset <[email protected]>
1 parent 1f95121 commit ec05331

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3465,10 +3465,13 @@ Converter::handleInstruction(const struct tgsi_full_instruction *insn)
34653465
if (!isEndOfSubroutine(ip + 1)) {
34663466
// insert a PRERET at the entry if this is an early return
34673467
// (only needed for sharing code in the epilogue)
3468-
BasicBlock *pos = getBB();
3469-
setPosition(BasicBlock::get(func->cfg.getRoot()), false);
3470-
mkFlow(OP_PRERET, leave, CC_ALWAYS, NULL)->fixed = 1;
3471-
setPosition(pos, true);
3468+
BasicBlock *root = BasicBlock::get(func->cfg.getRoot());
3469+
if (root->getEntry() == NULL || root->getEntry()->op != OP_PRERET) {
3470+
BasicBlock *pos = getBB();
3471+
setPosition(root, false);
3472+
mkFlow(OP_PRERET, leave, CC_ALWAYS, NULL)->fixed = 1;
3473+
setPosition(pos, true);
3474+
}
34723475
}
34733476
mkFlow(OP_RET, NULL, CC_ALWAYS, NULL)->fixed = 1;
34743477
bb->cfg.attach(&leave->cfg, Graph::Edge::CROSS);

0 commit comments

Comments
 (0)