From ce0ac302808657c540ced85e2113aaaacdca20a6 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Thu, 19 Sep 2024 08:12:04 +0200 Subject: [PATCH] Fix value propagation in loop dependency analysis --- oscar64/InterCode.cpp | 31 ++++++++++++++++++++++++++++--- oscar64/InterCode.h | 2 ++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index 47fbfd1..a3818ae 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -109,6 +109,30 @@ void IntegerValueRange::LimitMinWeak(int64 value) } +void IntegerValueRange::AddConstValue(InterType type, int64 value) +{ + if (value > 0 && IntegerValueRange::S_WEAK) + mMaxState = S_UNBOUND; + else if (value < 0 && mMinState == S_WEAK) + mMinState = S_UNBOUND; + + if (type == IT_INT8 && value >= 128 && mMaxState != S_BOUND) + mMinState = S_UNBOUND; + + mMinValue += value; + mMaxValue += value; + + if (type == IT_INT8) + { + if (mMinState == S_BOUND && mMinValue < -255 || mMaxState == S_BOUND && mMaxValue > 255) + { + LimitMax(255); + LimitMin(-128); + } + } +} + + void IntegerValueRange::LimitMaxWeak(int64 value) { if (mMaxState == S_UNBOUND || mMaxState != S_UNKNOWN && mMaxValue > value) @@ -15187,6 +15211,7 @@ bool InterCodeBasicBlock::SingleTailLoopOptimization(const NumberSet& aliasedPar ains->mSrc[0].mTemp = -1; ains->mSrc[0].mIntConst = s; tail->AppendBeforeBranch(ains); + ains->mDst.mRange.AddConstValue(ains->mDst.mType, s); indexScale[ains->mDst.mTemp] = s; @@ -15219,7 +15244,7 @@ bool InterCodeBasicBlock::SingleTailLoopOptimization(const NumberSet& aliasedPar ains->mSrc[0] = nins->mSrc[0]; ains->mSrc[0].mIntConst *= indexScale[lins->mSrc[0].mTemp]; tail->AppendBeforeBranch(ains); - ains->mDst.mRange.mMaxValue += ains->mSrc[0].mIntConst; + ains->mDst.mRange.AddConstValue(ains->mDst.mType, ains->mSrc[0].mIntConst); indexScale[ains->mDst.mTemp] = (int)ains->mSrc[0].mIntConst; @@ -15254,7 +15279,7 @@ bool InterCodeBasicBlock::SingleTailLoopOptimization(const NumberSet& aliasedPar ains->mSrc[0].mTemp = -1; ains->mSrc[0].mIntConst = s; tail->AppendBeforeBranch(ains); - ains->mDst.mRange.mMaxValue += ains->mSrc[0].mIntConst; + ains->mDst.mRange.AddConstValue(ains->mDst.mType, s); indexScale[ains->mDst.mTemp] = s; @@ -22074,7 +22099,7 @@ void InterCodeProcedure::Close(void) { GrowingTypeArray tstack(IT_NONE); - CheckFunc = !strcmp(mIdent->mString, "bar2"); + CheckFunc = !strcmp(mIdent->mString, "main"); CheckCase = false; mEntryBlock = mBlocks[0]; diff --git a/oscar64/InterCode.h b/oscar64/InterCode.h index 3d5e190..2c8214d 100644 --- a/oscar64/InterCode.h +++ b/oscar64/InterCode.h @@ -185,6 +185,8 @@ public: void LimitMinWeak(int64 value); void LimitMaxWeak(int64 value); + + void AddConstValue(InterType type, int64 value); };