From ef039085f7ac85bd7bfa991b6eb3574ddb1dfbb8 Mon Sep 17 00:00:00 2001 From: linma Date: Thu, 26 Aug 2021 11:01:39 -0700 Subject: [PATCH] fix bug: check variable in conditional stmt when optimize shortCircuit BB --- src/mapleall/maple_me/src/cfg_opt.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/mapleall/maple_me/src/cfg_opt.cpp b/src/mapleall/maple_me/src/cfg_opt.cpp index ab5556af8e..1bae694949 100644 --- a/src/mapleall/maple_me/src/cfg_opt.cpp +++ b/src/mapleall/maple_me/src/cfg_opt.cpp @@ -76,6 +76,13 @@ void CfgOpt::PropagateBB(BB &bb, BB *trueBranchBB, BB *falseBranchBB) { auto &condGoto = static_cast(predBB->GetLast()); SimplifyCondGotoStmt(condGoto); BB *branchBB; + // check predBB's rhs is same st as bb's rhs + if (condGoto.GetRHS()->GetOpCode() == OP_dread) { + AddrofNode *rhs = static_cast(condGoto.GetRHS()); + if (!IsShortCircuitStIdx(rhs->GetStIdx())) { + continue; + } + } if (condGoto.GetOpCode() == OP_brfalse) { trueBranchBBForPred = predBB->GetSucc(0); branchBB = falseBranchBBForPred; @@ -136,8 +143,13 @@ void CfgOpt::PropagateOuterBBInfo() { if (bb->GetFirst().GetOpCode() != OP_brfalse && bb->GetFirst().GetOpCode() != OP_brtrue) { PropagateBB(*bb, bb, bb); } else if (condGoto.GetOpCode() == OP_brfalse) { + // check condgoto rhs is shortcircuit variable + CHECK_FATAL((condGoto.GetRHS()->GetOpCode() == OP_dread) && IsShortCircuitStIdx((static_cast(condGoto.GetRHS()))->GetStIdx()), + "expect a shortcircuit varialbe"); PropagateBB(*bb, bb->GetSucc(0), bb->GetSucc(1)); } else { + CHECK_FATAL((condGoto.GetRHS()->GetOpCode() == OP_dread) && IsShortCircuitStIdx((static_cast(condGoto.GetRHS()))->GetStIdx()), + "expect a shortcircuit variable"); PropagateBB(*bb, bb->GetSucc(1), bb->GetSucc(0)); } break; -- Gitee