diff --git a/src/mapleall/maple_ir/src/mir_lower.cpp b/src/mapleall/maple_ir/src/mir_lower.cpp index 658af6c4aea64041a53e496bb4dbf25040910ea7..7c327cba071040a9a815e7d5e98a5439d217cdc5 100644 --- a/src/mapleall/maple_ir/src/mir_lower.cpp +++ b/src/mapleall/maple_ir/src/mir_lower.cpp @@ -323,7 +323,7 @@ BlockNode *MIRLower::LowerDoloopStmt(DoloopNode &doloop) { auto *readDovar = mirModule.CurFuncCodeMemPool()->New(OP_dread, doVarPType, doloop.GetDoVarStIdx(), 0); auto *add = - mirModule.CurFuncCodeMemPool()->New(OP_add, doVarPType, doloop.GetIncrExpr(), readDovar); + mirModule.CurFuncCodeMemPool()->New(OP_add, doVarPType, readDovar, doloop.GetIncrExpr()); auto *endDassign = mirModule.CurFuncCodeMemPool()->New(); endDassign->SetStIdx(doloop.GetDoVarStIdx()); endDassign->SetRHS(add); diff --git a/src/mapleall/maple_me/src/ssa_epre_for_lftr.cpp b/src/mapleall/maple_me/src/ssa_epre_for_lftr.cpp index a3eab84e48e8707bbdd50b9540aa48dac1bd1964..27f8ba4c68b31c2d44d783c4ae6cfff0107f0873 100644 --- a/src/mapleall/maple_me/src/ssa_epre_for_lftr.cpp +++ b/src/mapleall/maple_me/src/ssa_epre_for_lftr.cpp @@ -140,10 +140,9 @@ OpMeExpr *SSAEPre::FormLFTRCompare(MeRealOcc *compOcc, MeExpr *regorvar) { hashedSide = irMap->HashMeExpr(newSide); BuildWorkListExpr(*compOcc->GetMeStmt(), compOcc->GetSequence(), *hashedSide, false, nullptr, true, true); } - // when compare with constval, signed/unsigned integer has different behaviour + // try to preserve the opndtype signedness of the original comparison PrimType newCmpOpndType = regorvar->GetPrimType(); - if (hashedSide->GetOp() == OP_constval && - IsSignedInteger(regorvar->GetPrimType()) != IsSignedInteger(compare->GetOpndType()) && + if (IsSignedInteger(regorvar->GetPrimType()) != IsSignedInteger(compare->GetOpndType()) && compare->GetOp() != OP_ne && compare->GetOp() != OP_eq) { newCmpOpndType = IsSignedInteger(regorvar->GetPrimType()) ? GetUnsignedPrimType(regorvar->GetPrimType()) : GetSignedPrimType(regorvar->GetPrimType()); @@ -155,6 +154,14 @@ OpMeExpr *SSAEPre::FormLFTRCompare(MeRealOcc *compOcc, MeExpr *regorvar) { return static_cast(irMap->HashMeExpr(newcompare)); } +static bool IsLargeInteger(ConstMeExpr *constOpnd) { + MIRIntConst *intconst = dynamic_cast(constOpnd->GetConstVal()); + if (intconst == nullptr) { + return false; + } + return ((uint64) intconst->GetValue()) > 0x8000000; +} + void SSAEPre::CreateCompOcc(MeStmt *meStmt, int seqStmt, OpMeExpr *compare, bool isRebuilt) { if (compare->GetOpnd(0)->GetNumOpnds() > 0 && compare->GetOpnd(1)->GetNumOpnds() > 0) { @@ -176,9 +183,7 @@ void SSAEPre::CreateCompOcc(MeStmt *meStmt, int seqStmt, OpMeExpr *compare, bool constopnd = dynamic_cast(compare->GetOpnd(1)); } if (constopnd) { - MIRIntConst *intconst = dynamic_cast(constopnd->GetConstVal()); - if (intconst && ((uint64) intconst->GetValue()) > 0x8000000) - largeIntLimit = true; + largeIntLimit = IsLargeInteger(constopnd); } // search for worklist candidates set isSRCand such that one of its operands // is either compareLHS or compareRHS, and create MeRealOcc for each of them @@ -186,8 +191,18 @@ void SSAEPre::CreateCompOcc(MeStmt *meStmt, int seqStmt, OpMeExpr *compare, bool if (!wkCand->isSRCand) { continue; } - if (largeIntLimit && (wkCand->GetTheMeExpr()->GetOp() == OP_add || wkCand->GetTheMeExpr()->GetOp() == OP_sub)) { - continue; + if (wkCand->GetTheMeExpr()->GetOp() == OP_add || wkCand->GetTheMeExpr()->GetOp() == OP_sub) { + if (largeIntLimit) { + continue; + } + // skip if it has a larger integer operand + ConstMeExpr *candConstOpnd = dynamic_cast(wkCand->GetTheMeExpr()->GetOpnd(0)); + if (candConstOpnd == nullptr) { + candConstOpnd = dynamic_cast(wkCand->GetTheMeExpr()->GetOpnd(1)); + } + if (candConstOpnd && IsLargeInteger(candConstOpnd)) { + continue; + } } if (wkCand->GetTheMeExpr()->GetOp() == OP_sub && IsUnsignedInteger(compare->GetOpndType())) {