IR: Drop everything after a conditional exit folded to always taken

Only the ExitToConst right after it was skipped before.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Henrik RydgårdandClaude Opus 5.5 committed 2026-09-24 16:39:24 -06:00
1 parent 00f5e12b47
commit 498511fd51
2 files changed
+20 -8

No files matched your search

+5 -8
View File
@@ -459,8 +459,9 @@ bool PropagateConstants(const IRWriter &in, IRWriter &out, const IROptions &opts
IRImmRegCache gpr(&out);
bool logBlocks = false;
bool skipNextExitToConst = false;
for (int i = 0; i < (int)in.GetInstructions().size(); i++) {
// Set once a conditional exit is known to be taken, making the rest of the block dead.
bool unreachable = false;
for (int i = 0; i < (int)in.GetInstructions().size() && !unreachable; i++) {
IRInst inst = in.GetInstructions()[i];
bool symmetric = true;
switch (inst.op) {
@@ -901,7 +902,7 @@ bool PropagateConstants(const IRWriter &in, IRWriter &out, const IROptions &opts
if (passed) {
gpr.FlushAll();
out.Write(IROp::ExitToConst, 0, 0, 0, inst.constant);
skipNextExitToConst = true;
unreachable = true;
}
break;
}
@@ -926,7 +927,7 @@ bool PropagateConstants(const IRWriter &in, IRWriter &out, const IROptions &opts
if (passed) {
gpr.FlushAll();
out.Write(IROp::ExitToConst, 0, 0, 0, inst.constant);
skipNextExitToConst = true;
unreachable = true;
}
break;
}
@@ -935,10 +936,6 @@ bool PropagateConstants(const IRWriter &in, IRWriter &out, const IROptions &opts
goto doDefault;
case IROp::ExitToConst:
if (skipNextExitToConst) {
skipNextExitToConst = false;
break;
}
gpr.FlushAll();
goto doDefault;
+15
View File
@@ -404,6 +404,21 @@ static const IRVerification tests[] = {
},
{ &PropagateConstants },
},
{
// The exit is always taken, so nothing after it runs.
"PropagateConstantsTakenExit",
{
{ IROp::SetConst, { MIPS_REG_A0 }, 0, 0, 0 },
{ IROp::ExitToConstIfEq, { 0 }, MIPS_REG_A0, MIPS_REG_ZERO, 0x08804000 },
{ IROp::Downcount, { 0 }, 0, 0, 4 },
{ IROp::ExitToConst, { 0 }, 0, 0, 0x08804100 },
},
{
{ IROp::SetConst, { MIPS_REG_A0 }, 0, 0, 0 },
{ IROp::ExitToConst, { 0 }, 0, 0, 0x08804000 },
},
{ &PropagateConstants },
},
};
bool TestIRPassSimplify() {