From 4ef3e1588161b3c0baac7b2c49874f46444ba046 Mon Sep 17 00:00:00 2001 From: Brice Dobry Date: Thu, 12 Aug 2021 12:38:40 -0400 Subject: [PATCH] Fix a bug in globalopt causing error in SPEC 525 The problem was with what is called "pattern2" in the `ExtendShiftOptPattern`: UXTB/UXTW X1, W1 LSL X0, X1, #2 ....(X0 not used) AND/SUB/EOR X0, X1, X0 === becomes ===> AND/SUB/EOR X0, X1, W1 UXTB/UXTW #2 The problem here is that it was not checking if there were multiple reaching definitions of X1. If more than one definition reaches the LSL, then this optimization would be incorrect on whichever path(s) were not considered. --- .../src/cg/aarch64/aarch64_global.cpp | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_global.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_global.cpp index 67e6b853d6..704c4a2ea9 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_global.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_global.cpp @@ -1198,15 +1198,17 @@ void ExtendShiftOptPattern::ReplaceUseInsn(Insn &use, Insn &def, uint32 amount) void ExtendShiftOptPattern::Optimize(Insn &insn) { if (shiftOp == BitShiftOperand::kLSL) { InsnSet preDef = cgFunc.GetRD()->FindDefForRegOpnd(*defInsn, kInsnSecondOpnd, false); - Insn *preDefInsn = *preDef.begin(); - CHECK_FATAL((preDefInsn != nullptr), "defInsn is null!"); - SelectExtenOp(*preDefInsn); - /* preDefInsn must be uxt/sxt */ - if (extendOp != ExtendShiftOperand::kUndef) { - AArch64ImmOperand &immOpnd = static_cast(defInsn->GetOperand(kInsnThirdOpnd)); - /* do pattern2 */ - ReplaceUseInsn(insn, *preDefInsn, immOpnd.GetValue()); - return; + if (preDef.size() == 1) { + Insn *preDefInsn = *preDef.begin(); + CHECK_FATAL((preDefInsn != nullptr), "defInsn is null!"); + SelectExtenOp(*preDefInsn); + /* preDefInsn must be uxt/sxt */ + if (extendOp != ExtendShiftOperand::kUndef) { + AArch64ImmOperand &immOpnd = static_cast(defInsn->GetOperand(kInsnThirdOpnd)); + /* do pattern2 */ + ReplaceUseInsn(insn, *preDefInsn, immOpnd.GetValue()); + return; + } } } /* reset shiftOp and extendOp */ @@ -1216,7 +1218,7 @@ void ExtendShiftOptPattern::Optimize(Insn &insn) { /* do pattern1 */ ReplaceUseInsn(insn, *defInsn, 0); } else if (shiftOp != BitShiftOperand::kUndef) { - /* do pattern2 */ + /* do pattern3 */ AArch64ImmOperand &immOpnd = static_cast(defInsn->GetOperand(kInsnThirdOpnd)); ReplaceUseInsn(insn, *defInsn, immOpnd.GetValue()); } else { @@ -1282,4 +1284,4 @@ void ExtendShiftOptPattern::Run() { } } } -} /* namespace maplebe */ \ No newline at end of file +} /* namespace maplebe */ -- Gitee