From 69b8fb9bc2afea41b79804fe00b4ac58f930708e Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 20 Sep 2023 08:28:50 -0700 Subject: [PATCH] irjit: Correct alignment checks against SP. --- Core/MIPS/IR/IRPassSimplify.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Core/MIPS/IR/IRPassSimplify.cpp b/Core/MIPS/IR/IRPassSimplify.cpp index 87aa27687d..2079b799d6 100644 --- a/Core/MIPS/IR/IRPassSimplify.cpp +++ b/Core/MIPS/IR/IRPassSimplify.cpp @@ -1794,7 +1794,8 @@ bool ApplyMemoryValidation(const IRWriter &in, IRWriter &out, const IROptions &o bool spModified = false; for (IRInst inst : in.GetInstructions()) { IRMemoryOpInfo info = IROpMemoryAccessSize(inst.op); - if (info.size != 0 && inst.src1 == MIPS_REG_SP) { + // Note: we only combine word aligned accesses. + if (info.size != 0 && inst.src1 == MIPS_REG_SP && info.size == 4) { if (spModified) { // No good, it was modified and then we did more accesses. Can't combine. spUpper = -1; @@ -1805,11 +1806,6 @@ bool ApplyMemoryValidation(const IRWriter &in, IRWriter &out, const IROptions &o spUpper = -1; break; } - if (info.size == 16 && (inst.constant & 0xF) != 0) { - // Shouldn't happen, sp should always be aligned. - spUpper = -1; - break; - } spLower = std::min(spLower, (int)inst.constant); spUpper = std::max(spUpper, (int)inst.constant + info.size); @@ -1828,7 +1824,7 @@ bool ApplyMemoryValidation(const IRWriter &in, IRWriter &out, const IROptions &o std::map checks; const auto addValidate = [&](IROp validate, uint8_t sz, const IRInst &inst, bool isStore) { - if (inst.src1 == MIPS_REG_SP && skipSP) { + if (inst.src1 == MIPS_REG_SP && skipSP && validate == IROp::ValidateAddress32) { if (!flushedSP) { out.Write(IROp::ValidateAddress32, 0, MIPS_REG_SP, spWrite ? 1U : 0U, spLower); if (spUpper > spLower + 4)