diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp index 834575ca2d1c8cc10645a870aceea791675c977a..4fe8ab5fa1994a3fd6da6ba93787c0e6f0970f6b 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp @@ -4993,9 +4993,7 @@ void AArch64CGFunc::SelectCvtInt2Int(const BaseNode *parent, Operand *&resOpnd, opnd0 = &LoadIntoRegister(*opnd0, primType); if (fsize > tsize) { - if (tsize == k32BitSize) { - GetCurBB()->AppendInsn(GetCG()->BuildInstruction(MOP_wmovrr, *resOpnd, *opnd0)); - } else if (tsize == k8BitSize) { + if (tsize == k8BitSize) { MOperator mOp = IsSignedInteger(toType) ? MOP_xsxtb32 : MOP_xuxtb32; GetCurBB()->AppendInsn(GetCG()->BuildInstruction(mOp, *resOpnd, *opnd0)); } else if (tsize == k16BitSize) { 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 262c3f9be5855377caf1b48f2a1016ffd66f33d4..0d0cb27ee53826f293f9f666dfc3ed4dfff67a8f 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_global.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_global.cpp @@ -1467,7 +1467,11 @@ void ExtendShiftOptPattern::ReplaceUseInsn(Insn &use, Insn &def, uint32 amount) cgFunc.GetRD()->InitGenUse(*defInsn->GetBB(), false); cgFunc.GetRD()->UpdateInOut(*use.GetBB(), true); newInsn = replaceUseInsn; - optSuccess = true; + if (isExten) { + optSuccess = false; + } else { + optSuccess = true; + } } /* diff --git a/src/mapleall/maple_me/include/me_scalar_analysis.h b/src/mapleall/maple_me/include/me_scalar_analysis.h index 09aaafe7d120ed4614ebb85ae4ec1395cf04c96c..552877597ffa699eaab8649f8e177c8d46a0ecd4 100644 --- a/src/mapleall/maple_me/include/me_scalar_analysis.h +++ b/src/mapleall/maple_me/include/me_scalar_analysis.h @@ -322,8 +322,8 @@ class LoopScalarAnalysisResult { std::set> allCRNodes; void DumpTripCount(const CR &cr, int32 value, const MeExpr *expr); uint32 ComputeTripCountWithCR(const CR &cr, const OpMeExpr &opMeExpr, int32 value); - uint32 ComputeTripCountWithSimpleConstCR(const OpMeExpr &opMeExpr, int32 value, int32 start, int32 stride) const; + uint32 ComputeTripCountWithSimpleConstCR(const OpMeExpr &opMeExpr, int32 value, int32 start, int32 stride, bool negop = false) const; bool computeTripCountForLoopUnroll = true; }; } // namespace maple -#endif // MAPLE_ME_INCLUDE_SCALAR_ANALYSIS_H \ No newline at end of file +#endif // MAPLE_ME_INCLUDE_SCALAR_ANALYSIS_H diff --git a/src/mapleall/maple_me/src/me_loop_unrolling.cpp b/src/mapleall/maple_me/src/me_loop_unrolling.cpp index c52347a6e82a20e5c56c9d20e4d86db24faa2420..b2ce4cda737b597d9395fa7cc86b17f44c885d75 100644 --- a/src/mapleall/maple_me/src/me_loop_unrolling.cpp +++ b/src/mapleall/maple_me/src/me_loop_unrolling.cpp @@ -1236,13 +1236,14 @@ void LoopUnrollingExecutor::SetNestedLoop(const IdentifyLoops &meLoop, } bool LoopUnrollingExecutor::IsDoWhileLoop(MeFunction &func, LoopDesc &loop) const { + if (!loop.head || !loop.exitBB) return false; for (auto succ : loop.head->GetSucc()) { - if (!loop.Has(*succ)) { + if (!loop.Has(*succ) && (succ != loop.exitBB)) { return false; } } - auto exitBB = func.GetCfg()->GetBBFromID(loop.inloopBB2exitBBs.begin()->first); - for (auto pred : exitBB->GetPred()) { + + for (auto pred : loop.exitBB->GetPred()) { if (!loop.Has(*pred)) { return false; } @@ -1405,9 +1406,11 @@ void MELoopUnrolling::GetAnalysisDependence(maple::AnalysisDep &aDep) const { bool MELoopUnrolling::PhaseRun(maple::MeFunction &f) { // Do loop unrolling only when the function is hot in profile. +#if 0 if (!ProfileCheck(f)) { return false; } +#endif IdentifyLoops *meLoop = GET_ANALYSIS(MELoopAnalysis, f); if (meLoop == nullptr) { return false; diff --git a/src/mapleall/maple_me/src/me_scalar_analysis.cpp b/src/mapleall/maple_me/src/me_scalar_analysis.cpp index 36b4eb05efe009743a86ec53c817a97d00fa94d4..daf4e0bef35bc37eb8cb524d4a63e5053384d90b 100644 --- a/src/mapleall/maple_me/src/me_scalar_analysis.cpp +++ b/src/mapleall/maple_me/src/me_scalar_analysis.cpp @@ -69,7 +69,7 @@ CRNode *CR::ComputeValueAtIteration(uint32 i, LoopScalarAnalysisResult &scalarAn MeExpr *LoopScalarAnalysisResult::TryToResolveVar(MeExpr &expr, std::set &visitedPhi, MeExpr &dummyExpr) { - CHECK_FATAL(expr.GetMeOp() == kMeOpVar, "must be"); + CHECK_FATAL((expr.GetMeOp() == kMeOpVar || expr.GetMeOp() == kMeOpReg), "must be"); auto *var = static_cast(&expr); if (var->GetDefBy() == kDefByStmt && !var->GetDefStmt()->GetRHS()->IsLeaf()) { return nullptr; @@ -78,7 +78,8 @@ MeExpr *LoopScalarAnalysisResult::TryToResolveVar(MeExpr &expr, std::setGetDefStmt()->GetRHS(); } if (var->GetDefBy() == kDefByStmt) { - CHECK_FATAL(var->GetDefStmt()->GetRHS()->GetMeOp() == kMeOpVar, "must be"); + CHECK_FATAL((var->GetDefStmt()->GetRHS()->GetMeOp() == kMeOpVar || + var->GetDefStmt()->GetRHS()->GetMeOp() == kMeOpReg), "must be"); return TryToResolveVar(*(var->GetDefStmt()->GetRHS()), visitedPhi, dummyExpr); } @@ -986,7 +987,7 @@ uint32 LoopScalarAnalysisResult::ComputeTripCountWithCR(const CR &cr, const OpMe } uint32 LoopScalarAnalysisResult::ComputeTripCountWithSimpleConstCR(const OpMeExpr &opMeExpr, int32 value, - int32 start, int32 stride) const { + int32 start, int32 stride, bool negOp) const { constexpr int32 javaIntMinValue = -2147483648; // -8fffffff constexpr int32 javaIntMaxValue = 2147483647; // 7fffffff CHECK_FATAL(stride != 0, "stride must not be zero"); @@ -1001,7 +1002,18 @@ uint32 LoopScalarAnalysisResult::ComputeTripCountWithSimpleConstCR(const OpMeExp return 0; } uint32 remainder = (value < start) ? ((start - value) % stride) : ((value - start) % stride); - switch (opMeExpr.GetOp()) { + Opcode op = opMeExpr.GetOp(); + if (negOp) { + switch (op) { + case OP_ge: op = OP_lt; break; + case OP_le: op = OP_gt; break; + case OP_gt: op = OP_le; break; + case OP_lt: op = OP_ge; break; + default: + break; + } + } + switch (op) { case OP_ge: { // < if (start >= value || start - stride >= value) { return 0; @@ -1116,7 +1128,7 @@ TripCountType LoopScalarAnalysisResult::ComputeTripCount(MeFunction &func, uint3 auto *opMeExpr = static_cast(brMeStmt->GetOpnd()); MeExpr *opnd1 = opMeExpr->GetOpnd(0); MeExpr *opnd2 = opMeExpr->GetOpnd(1); - if (opnd1->GetPrimType() != PTY_i32 || opnd2->GetPrimType() != PTY_i32) { + if (!IsPrimitiveInteger(opnd1->GetPrimType()) || !IsPrimitiveInteger(opnd2->GetPrimType())) { return kCouldNotComputeCR; } CRNode *crNode1 = GetOrCreateCRNode(*opnd1); @@ -1166,12 +1178,16 @@ TripCountType LoopScalarAnalysisResult::ComputeTripCount(MeFunction &func, uint3 if (cr->GetOpndsSize() == 2) { // cr has two opnds like {1, + 1} tripCountResult = ComputeTripCountWithSimpleConstCR(*opMeExpr, constNode->GetConstValue(), static_cast(cr->GetOpnd(0))->GetConstValue(), - static_cast(cr->GetOpnd(1))->GetConstValue()); + static_cast(cr->GetOpnd(1))->GetConstValue(), + (brTarget != loop->exitBB)); return kConstCR; } else { + return kCouldNotComputeCR; // complex cr node , can not compute tripcount +#if 0 CHECK_FATAL(false, "NYI"); tripCountResult = ComputeTripCountWithCR(*cr, *opMeExpr, constNode->GetConstValue()); return kConstCR; +#endif } return kConstCR; } diff --git a/src/mapleall/maple_phase/include/phases.def b/src/mapleall/maple_phase/include/phases.def index 4bfd58725a5a2b2a6d5c84867c02d3d9cb70fda3..9e14628b67d1a54d97233c4c0613aab76d13f108 100644 --- a/src/mapleall/maple_phase/include/phases.def +++ b/src/mapleall/maple_phase/include/phases.def @@ -49,6 +49,7 @@ ADDMAPLEMEPHASE("dse", MeOption::optLevel >= 2) ADDMAPLEMEPHASE("analyzector", JAVALANG) ADDMAPLEMEPHASE("abcopt", JAVALANG && MeOption::optLevel >= 2) ADDMAPLEMEPHASE("ssadevirt", JAVALANG && MeOption::optLevel >= 2) +ADDMAPLEMEPHASE("loopunrolling", MeOption::optLevel >= 2) ADDMAPLEMEPHASE("hprop", MeOption::optLevel >= 2) ADDMAPLEMEPHASE("valueRangePropagation", CLANG && MeOption::optLevel >= 2) ADDMAPLEMEPHASE("safetyWarning", CLANG && MeOption::optLevel >= 2)