Commit 6be93d57 authored by Adéla Štěpková's avatar Adéla Štěpková
Browse files

do not replace older values with newer values in simplifyAssume

parent c5a4c1b4
Loading
Loading
Loading
Loading
+21 −9
Original line number Diff line number Diff line
@@ -131,11 +131,11 @@ class SamePathBlocks {
        }

        for (auto& [BB1, candidates] : samePathAndLoopCont) {
            outs() << BB1->getName() << ": ";
            for (auto& c : candidates) {
                outs() << c->getName() << ", ";
            }
            outs() << '\n';
            // outs() << BB1->getName() << ": ";
            // for (auto& c : candidates) {
            //     outs() << c->getName() << ", ";
            // }
            // outs() << '\n';
            if (earliestOnSamePathAndLoop.find(BB1) != earliestOnSamePathAndLoop.end()) {
                continue;
            }
@@ -385,8 +385,16 @@ private:

    bool canBeReplaced(Value* toBeReplaced, Value* replacedWith)
    {
        // outs() << *toBeReplaced << " " << *replacedWith << '\n';
        if (auto* I1 = dyn_cast<Instruction>(toBeReplaced)) {
            // if (I1->getParent() != origAssume->getParent() && I1->getParent() != currentBB) {
            //     return false;
            // }

            if (auto* I2 = dyn_cast<Instruction>(replacedWith)) {
                if (I1->getParent() != I2->getParent() && DT.dominates(I1, I2)) {
                    return false; // do not want to replace older values with newer ones
                }
                if (isOnSameOrLessLoops(I2->getParent(), I1->getParent())) {
                    return true; // the replacing value must change less often than the one being
                                 // replaced
@@ -447,8 +455,12 @@ private:
        if (auto* inst = dyn_cast<Instruction>(use.getUser())) {
            auto* currentBB = inst->getParent();
            if (assumeHasEffect(origAssume, currentBB, valToReplace)) {
                // outs() << "REPLACING USE " << *use << " BY " << *replaceWith << " IN " << *inst
                //    << '\n';
                if (auto* useI = dyn_cast<Instruction>(use)) {
                    // outs() << "REPLACING USE " << *use << " DEFINED IN " << useI->getParent()->getName()
                    //        << " BY " << *replaceWith << " IN " << currentBB->getName()
                    //        << " WITH ASSUME IN " << origAssume->getParent()->getName() << '\n';
                }

                return true;
            }
            return false;
@@ -993,8 +1005,8 @@ void simplifyAssumesInFunction(ReversedModule& mod, Function* revFunction, Funct
    SimplifyAssumeVisitor simplifyAssumeVisitor(mod, revFunction, assumei1, DT, PDT, LI,
                                                samePathBlocks, VDT);
    // outs() << *revFunction;
    // simplifyAssumeVisitor.visit(revFunction);
    // simplifyAssumeVisitor.handle();
    simplifyAssumeVisitor.visit(revFunction);
    simplifyAssumeVisitor.handle();

    MoveUpAssumeVisitor moveUpAssumeVisitor(mod, *revFunction, DT, PDT, LI, samePathBlocks);