diff --git a/src/mapleall/maple_me/include/lfo_dep_test.h b/src/mapleall/maple_me/include/lfo_dep_test.h index 3f017eca5be3ec17ec1638b3ba3603f11bd24999..2e7987edbb1231144facf8ab014486353b5c3f09 100644 --- a/src/mapleall/maple_me/include/lfo_dep_test.h +++ b/src/mapleall/maple_me/include/lfo_dep_test.h @@ -29,9 +29,10 @@ class LfoDepInfo; class SubscriptDesc{ public: MeExpr *subscriptX; - DreadNode *iv = nullptr; // the variable + DreadNode *iv = nullptr; // the induction variable int64 coeff = 1; // coefficient of the variable int64 additiveConst = 0; + BaseNode *additiveLoopInvar = nullptr; bool tooMessy = false;; // too complicated to analyze bool loopInvariant = false; // loop invariant w.r.t. closest nesting loop diff --git a/src/mapleall/maple_me/src/lfo_dep_test.cpp b/src/mapleall/maple_me/src/lfo_dep_test.cpp index fd881e9e4857711306afd911e776510cbf0045b0..8e8bf1b739ca7aaaabbb14a1271228c324fa7192 100644 --- a/src/mapleall/maple_me/src/lfo_dep_test.cpp +++ b/src/mapleall/maple_me/src/lfo_dep_test.cpp @@ -206,27 +206,36 @@ SubscriptDesc *DoloopInfo::BuildOneSubscriptDesc(BaseNode *subsX) { return subsDesc; } Opcode op = subsX->GetOpCode(); - BaseNode *mainTerm = nullptr; - if (op != OP_add && op != OP_sub) { - mainTerm = subsX; - } else { // get addtiveConst + BaseNode *mainTerm = subsX; + if (op == OP_add || op == OP_sub) { // get addtiveConst BinaryNode *binnode = static_cast(subsX); - BaseNode *opnd0 = binnode->Opnd(0); BaseNode *opnd1 = binnode->Opnd(1); - if (opnd1->op != OP_constval) { - subsDesc->tooMessy = true; - return subsDesc; + if (opnd1->op == OP_constval) { + MIRConst *mirconst = static_cast(opnd1)->GetConstVal(); + if (mirconst->GetKind() == kConstInt) { + subsDesc->additiveConst = static_cast(mirconst)->GetValue(); + if (op == OP_sub) { + subsDesc->additiveConst = - subsDesc->additiveConst; + } + mainTerm = binnode->Opnd(0); + } } - MIRConst *mirconst = static_cast(opnd1)->GetConstVal(); - if (mirconst->GetKind() != kConstInt) { + } + // if main term is another add, see if it is addition to loop-invarant + if (mainTerm->GetOpCode() == OP_add) { + BinaryNode *mtbinnode = static_cast(mainTerm); + BaseNode *mtopnd0 = mtbinnode->Opnd(0); + BaseNode *mtopnd1 = mtbinnode->Opnd(1); + if (IsLoopInvariant2(mtopnd0)) { + subsDesc->additiveLoopInvar = mtopnd0; + mainTerm = mtopnd1; + } else if (IsLoopInvariant2(mtopnd1)) { + subsDesc->additiveLoopInvar = mtopnd1; + mainTerm = mtopnd0; + } else { subsDesc->tooMessy = true; return subsDesc; } - subsDesc->additiveConst = static_cast(mirconst)->GetValue(); - if (op == OP_sub) { - subsDesc->additiveConst = - subsDesc->additiveConst; - } - mainTerm = opnd0; } // process mainTerm BaseNode *varNode = nullptr; @@ -251,10 +260,6 @@ SubscriptDesc *DoloopInfo::BuildOneSubscriptDesc(BaseNode *subsX) { return subsDesc; } subsDesc->coeff = static_cast(mirconst)->GetValue(); - if (subsDesc->coeff < 0) { - subsDesc->tooMessy = true; - return subsDesc; - } } // process varNode if (varNode->GetOpCode() == OP_cvt) { @@ -468,6 +473,15 @@ void DoloopInfo::TestDependences(MapleVector *depTestList, bool bot break; } } + if (subs1->additiveLoopInvar != nullptr || subs2->additiveLoopInvar != nullptr) { + if (subs1->additiveLoopInvar == nullptr || + subs2->additiveLoopInvar == nullptr || + !subs1->additiveLoopInvar->IsSameContent(subs2->additiveLoopInvar)) { + testPair->dependent = true; + testPair->unknownDist = true; + break; + } + } if (subs1->coeff == subs2->coeff) { // lamport test if (((subs1->additiveConst - subs2->additiveConst) % subs1->coeff) != 0) { continue; @@ -677,7 +691,11 @@ void LfoDepInfo::PerformDepTest() { LogInfo::MapleLogger() << " [" << subs->coeff << "*"; ScalarMeExpr *scalar = static_cast(preEmit->GetMexpr(subs->iv)); scalar->GetOst()->Dump(); - LogInfo::MapleLogger() << "+" << subs->additiveConst << "]"; + LogInfo::MapleLogger() << "+" << subs->additiveConst; + if (subs->additiveLoopInvar != nullptr) { + LogInfo::MapleLogger() << "+"; + } + LogInfo::MapleLogger() << "]"; } } LogInfo::MapleLogger() << std::endl; @@ -701,7 +719,11 @@ void LfoDepInfo::PerformDepTest() { LogInfo::MapleLogger() << " [" << subs->coeff << "*"; ScalarMeExpr *scalar = static_cast(preEmit->GetMexpr(subs->iv)); scalar->GetOst()->Dump(); - LogInfo::MapleLogger() << "+" << subs->additiveConst << "]"; + LogInfo::MapleLogger() << "+" << subs->additiveConst; + if (subs->additiveLoopInvar != nullptr) { + LogInfo::MapleLogger() << "+"; + } + LogInfo::MapleLogger() << "]"; } } LogInfo::MapleLogger() << std::endl;