};
private:
- // XXX-update: A flag that checks whether we can eliminate this machine basic
- // block.
- bool canEliminateMachineBB;
-
typedef ilist<MachineInstr> Instructions;
Instructions Insts;
const BasicBlock *BB;
/// is only computed once and is cached.
mutable MCSymbol *CachedMCSymbol = nullptr;
+ // XXX-update: A flag that checks whether we can eliminate this machine basic
+ // block.
+ bool canEliminateMachineBB;
+
// Intrusive list support
MachineBasicBlock() {}
BundledSucc = 1 << 3 // Instruction has bundled successors.
};
private:
- // XXX-update: A flag that checks whether we can eliminate this instruction.
- bool canEliminateMachineInstr;
-
const MCInstrDesc *MCID; // Instruction descriptor.
MachineBasicBlock *Parent; // Pointer to the owning basic block.
friend class MachineFunction;
public:
- // XXX-update:
- void disableCanEliminateMachineInstr() {
- canEliminateMachineInstr = false;
- }
-
- bool getCanEliminateMachineInstr() {
- return canEliminateMachineInstr;
- }
-
const MachineBasicBlock* getParent() const { return Parent; }
MachineBasicBlock* getParent() { return Parent; }
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<true, NoFolder> Builder(SI);
BasicBlock* BB = SI->getParent();
Value* Address = SI->getPointerOperand();
// Returns true if the code is changed, and false otherwise.
void TaintRelaxedLoads(LoadInst* LI) {
- IRBuilder<true, NoFolder> 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<true, NoFolder> Builder(InsertPoint);
+ auto* AndZero = dyn_cast<Instruction>(
+ Builder.CreateAnd(LI, Constant::getNullValue(LI->getType())));
auto* FakeCondition = dyn_cast<Instruction>(Builder.CreateICmp(
- CmpInst::ICMP_EQ, LI, Constant::getNullValue(LI->getType())));
+ CmpInst::ICMP_NE, AndZero, Constant::getNullValue(LI->getType())));
AddFakeConditionalBranch(FakeCondition->getNextNode(), FakeCondition);
}
}
// We really need to process the relaxed load now.
- TaintRelaxedLoads(LI);
- Changed = true;
+ StoreInst* SI = nullptr;;
+ if (FirstInst && (SI = dyn_cast<StoreInst>(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;
}
DebugLoc dl, bool NoImp)
: MCID(&tid), Parent(nullptr), Operands(nullptr), NumOperands(0), Flags(0),
AsmPrinterFlags(0), NumMemRefs(0), MemRefs(nullptr),
- debugLoc(std::move(dl)), canEliminateMachineInstr(true) {
+ debugLoc(std::move(dl)) {
assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor");
// Reserve space for the expected number of operands.
: MCID(&MI.getDesc()), Parent(nullptr), Operands(nullptr), NumOperands(0),
Flags(0), AsmPrinterFlags(0),
NumMemRefs(MI.NumMemRefs), MemRefs(MI.MemRefs),
- debugLoc(MI.getDebugLoc()), canEliminateMachineInstr(true) {
+ debugLoc(MI.getDebugLoc()) {
assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor");
CapOperands = OperandCapacity::get(MI.getNumOperands());
// XXX-disabled: (and x, 0) should not be folded.
// (and (and x, 0), y) shouldn't either.
- if (!N0C && N1C->isNullValue()) {
+ if (!N0C && N1C && N1C->isNullValue()) {
return SDValue();
}
if (!N0C) {
MachineBasicBlock* Succ2Succ = nullptr;
if ((Succ1->size() == 1 && Succ1->begin()->isUnconditionalBranch()) ||
(Succ1->size() == 0)) {
- Succ1Succ = *Succ1->succ_begin();
+ if (Succ1->succ_size()) {
+ Succ1Succ = *Succ1->succ_begin();
+ }
}
if ((Succ2->size() == 1 && Succ2->begin()->isUnconditionalBranch()) ||
(Succ2->size() == 0)) {
- Succ2Succ = *Succ2->succ_begin();
+ if (Succ1->succ_size()) {
+ Succ2Succ = *Succ2->succ_begin();
+ }
}
bool HasCommonDest = Succ1Succ && Succ1Succ == Succ2Succ;
auto MBBIter = MBB.end();
std::advance(MBBIter, -2);
assert(MBBIter->isConditionalBranch());
- MBBIter->disableCanEliminateMachineInstr();
MBB.disableCanEliminateMachineBB();
Succ1->disableCanEliminateMachineBB();
Succ2->disableCanEliminateMachineBB();