X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=lib%2FCodeGen%2FCodeGenPrepare.cpp;h=5c9858dcec2f3cc2cb0975322800992b670f96a1;hp=1a07bfc0c3577f71585153b63635d87173c47479;hb=20a42bb20d43b80e322c95dd99b64a5a4566fe08;hpb=5666fc71f0e2ed2c0400d8bca079a1dd3f33fe53 diff --git a/lib/CodeGen/CodeGenPrepare.cpp b/lib/CodeGen/CodeGenPrepare.cpp index 1a07bfc0c35..5c9858dcec2 100644 --- a/lib/CodeGen/CodeGenPrepare.cpp +++ b/lib/CodeGen/CodeGenPrepare.cpp @@ -518,6 +518,8 @@ Value* getRootDependence(Value* DepVal) { bool taintStoreAddress(StoreInst* SI, Value* DepVal, const char* calling_func = __builtin_FUNCTION()) { DEBUG(dbgs() << "Called from " << calling_func << '\n'); + // Set the insertion point right after the 'DepVal'. + Instruction* Inst = nullptr; IRBuilder Builder(SI); BasicBlock* BB = SI->getParent(); Value* Address = SI->getPointerOperand(); @@ -749,9 +751,21 @@ void AddFakeConditionalBranch(Instruction* SplitInst, Value* Condition) { // Returns true if the code is changed, and false otherwise. void TaintRelaxedLoads(LoadInst* LI) { - IRBuilder Builder(LI->getNextNode()); + // For better performance, we can add a "AND X 0" instruction before the + // condition. + auto* FirstInst = findFirstStoreCondBranchInst(LI); + Instruction* InsertPoint = nullptr; + if (FirstInst == nullptr) { + InsertPoint = LI->getParent()->getTerminator(); + InsertPoint = LI->getNextNode(); + } else { + InsertPoint = LI->getNextNode(); + } + IRBuilder Builder(InsertPoint); + auto* AndZero = dyn_cast( + Builder.CreateAnd(LI, Constant::getNullValue(LI->getType()))); auto* FakeCondition = dyn_cast(Builder.CreateICmp( - CmpInst::ICMP_EQ, LI, Constant::getNullValue(LI->getType()))); + CmpInst::ICMP_NE, AndZero, Constant::getNullValue(LI->getType()))); AddFakeConditionalBranch(FakeCondition->getNextNode(), FakeCondition); } @@ -779,8 +793,15 @@ bool AddFakeConditionalBranchAfterMonotonicLoads( } // We really need to process the relaxed load now. - TaintRelaxedLoads(LI); - Changed = true; + StoreInst* SI = nullptr;; + if (FirstInst && (SI = dyn_cast(FirstInst))) { + // For immediately coming stores, taint the address of the store. + taintStoreAddress(SI, LI); + } else { + // For immediately coming branch, directly add a fake branch. + TaintRelaxedLoads(LI); + Changed = true; + } } return Changed; }