From: Peizhao Ou Date: Mon, 2 Apr 2018 22:18:20 +0000 (-0700) Subject: Adds bogus conditional branch after relaxed loads unconditionally (without local... X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=refs%2Fheads%2Frelaxed-loads-noanalysis;p=oota-llvm.git Adds bogus conditional branch after relaxed loads unconditionally (without local analysis) --- diff --git a/lib/CodeGen/CodeGenPrepare.cpp b/lib/CodeGen/CodeGenPrepare.cpp index f4ff3787e63..dafe786719e 100644 --- a/lib/CodeGen/CodeGenPrepare.cpp +++ b/lib/CodeGen/CodeGenPrepare.cpp @@ -823,9 +823,19 @@ void TaintRelaxedLoads(Instruction* UsageInst, Instruction* InsertPoint) { Op0->getOpcode() == Instruction::And && Op1 && Op1->isZero()) { auto* Op01 = dyn_cast(Op0->getOperand(1)); if (Op01 && Op01->isZero()) { + if (UsageInst == CmpInst) { + return; + } + // Now we have a previously added fake cond branch. auto* Op00 = Op0->getOperand(0); IRBuilder Builder(CmpInst); +// dbgs() << "Tainting existing fake branches: " << *BI << "\n" +// << "\tInstUsage to taint:" << *UsageInst << "\n" +// << "\tBeforeBB:" << *InsertPoint->getParent() << "\n" +// << "\tOp0 =" << *Op0 << "\n" +// << "\tOp00 =" << *Op00 << "\n"; + if (Op00->getType() == UsageInst->getType()) { AndTarget = UsageInst; } else { @@ -835,6 +845,10 @@ void TaintRelaxedLoads(Instruction* UsageInst, Instruction* InsertPoint) { auto* AndZero = dyn_cast(Builder.CreateAnd( AndTarget, Constant::getNullValue(AndTarget->getType()))); CmpInst->setOperand(0, AndZero); + +// dbgs() << "\tAndTarget =" << *AndTarget << "\n" +// << "\tAfterBB:" << *InsertPoint->getParent() << "\n"; + return; } } @@ -852,6 +866,11 @@ void TaintRelaxedLoads(Instruction* UsageInst, Instruction* InsertPoint) { auto* FakeCondition = dyn_cast(Builder.CreateICmp( CmpInst::ICMP_NE, AndZero, Constant::getNullValue(AndTarget->getType()))); AddFakeConditionalBranch(FakeCondition->getNextNode(), FakeCondition); + +// dbgs() << "Adding new fake branches: " << *FakeCondition << "\n" +// << "\tInstUsage to taint:" << *UsageInst << "\n" +// << "\tAndTarget =" << *AndTarget << "\n" +// << "\tAfterBB:" << *FakeCondition->getParent() << "\n"; } // XXX-comment: Finds the appropriate Value derived from an atomic load. @@ -937,42 +956,16 @@ Instruction* findMostRecentDependenceUsage(LoadInst* LI, Instruction* LaterInst, // XXX-comment: Returns whether the code has been changed. bool AddFakeConditionalBranchAfterMonotonicLoads( - SmallSet& MonotonicLoadInsts, DominatorTree* DT) { + SmallVector& MonotonicLoadInsts, DominatorTree* DT) { bool Changed = false; while (!MonotonicLoadInsts.empty()) { - auto* LI = *MonotonicLoadInsts.begin(); - MonotonicLoadInsts.erase(LI); + auto* LI = MonotonicLoadInsts.back(); + MonotonicLoadInsts.pop_back(); SmallVector ChainedBB; auto* FirstInst = findFirstStoreCondBranchInst(LI, &ChainedBB); - if (FirstInst != nullptr) { - if (FirstInst->getOpcode() == Instruction::Store) { - if (StoreAddressDependOnValue(dyn_cast(FirstInst), LI)) { - continue; - } - } else if (FirstInst->getOpcode() == Instruction::Br) { - if (ConditionalBranchDependsOnValue(dyn_cast(FirstInst), - LI)) { - continue; - } - } else { - IntrinsicInst* II = dyn_cast(FirstInst); - if (!II || II->getIntrinsicID() != Intrinsic::aarch64_stlxr) { - dbgs() << "FirstInst=" << *FirstInst << "\n"; - assert(false && "findFirstStoreCondBranchInst() should return a " - "store/condition branch instruction"); - } - } - } // We really need to process the relaxed load now. - StoreInst* SI = nullptr; - IntrinsicInst* II = nullptr; if (FirstInst) { - SI = dyn_cast(FirstInst); - II = dyn_cast(FirstInst); - } - if (FirstInst && - (SI || (II && II->getIntrinsicID() == Intrinsic::aarch64_stlxr))) { // For immediately coming stores, taint the address of the store. if (FirstInst->getParent() == LI->getParent() || DT->dominates(LI, FirstInst)) { @@ -990,27 +983,8 @@ bool AddFakeConditionalBranchAfterMonotonicLoads( } } } else { - // No upcoming branch - if (!FirstInst) { - TaintRelaxedLoads(LI, nullptr); - Changed = true; - } else { - // For immediately coming branch, directly add a fake branch. - if (FirstInst->getParent() == LI->getParent() || - DT->dominates(LI, FirstInst)) { - TaintRelaxedLoads(LI, FirstInst); - Changed = true; - } else { - auto* Inst = - findMostRecentDependenceUsage(LI, FirstInst, &ChainedBB, DT); - if (Inst) { - TaintRelaxedLoads(Inst, FirstInst); - } else { - LI->setOrdering(Acquire); - } - Changed = true; - } - } + LI->setOrdering(Acquire); + Changed = true; } } return Changed; @@ -1388,7 +1362,7 @@ bool CodeGenPrepare::runOnFunction(Function &F) { // XXX-comment: Delay dealing with relaxed loads in this function to avoid // further changes done by other passes (e.g., SimplifyCFG). // Collect all the relaxed loads. - SmallSet MonotonicLoadInsts; + SmallVector MonotonicLoadInsts; for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) { if (I->isAtomic()) { switch (I->getOpcode()) { @@ -1396,7 +1370,7 @@ bool CodeGenPrepare::runOnFunction(Function &F) { auto* LI = dyn_cast(&*I); if (LI->getOrdering() == Monotonic && !LI->getHasSubsequentAcqlRMW()) { - MonotonicLoadInsts.insert(LI); + MonotonicLoadInsts.push_back(LI); } break; }