From a04b09c73769623687cf8fb8d7ff059c3f8fee5f Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sat, 21 Sep 2024 13:50:14 +0200 Subject: [PATCH] Fix wrong loop invariant when result temp used before --- oscar64/InterCode.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index 4458184..2dbd3da 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -18174,9 +18174,14 @@ void InterCodeBasicBlock::SingleBlockLoopOptimisation(const NumberSet& aliasedPa if (ins->mInvariant) { - for (int j = 0; j < ins->mNumOperands; j++) - if (ins->mSrc[j].mTemp >= 0 && dep[ins->mSrc[j].mTemp] == DEP_VARIABLE) - ins->mInvariant = false; + if (ins->mDst.mTemp >= 0 && IsTempReferencedInRange(0, i, ins->mDst.mTemp)) + ins->mInvariant = false; + else + { + for (int j = 0; j < ins->mNumOperands; j++) + if (ins->mSrc[j].mTemp >= 0 && dep[ins->mSrc[j].mTemp] == DEP_VARIABLE) + ins->mInvariant = false; + } } if (ins->mInvariant)