Instruction::CastOps CastOp = Instruction::BitCast;
switch (DepVal->getType()->getTypeID()) {
case Type::IntegerTyID: {
- CastOp = Instruction::SExt;
+ assert(TargetIntegerType->getTypeID() == Type::IntegerTyID);
+ auto* FromType = dyn_cast<IntegerType>(DepVal->getType());
+ auto* ToType = dyn_cast<IntegerType>(TargetIntegerType);
+ assert(FromType && ToType);
+ if (FromType->getBitWidth() <= ToType->getBitWidth()) {
+ CastOp = Instruction::ZExt;
+ } else {
+ CastOp = Instruction::Trunc;
+ }
break;
}
case Type::FloatTyID:
}
}
+// XXX-update: Find the next node of the last relaxed load from 'FromInst' to
+// 'ToInst'. If none, return 'ToInst'.
+Instruction* findLastLoadNext(Instruction* FromInst, Instruction* ToInst) {
+ if (FromInst == ToInst) {
+ return ToInst;
+ }
+ Instruction* LastLoad = ToInst;
+ auto* BB = FromInst->getParent();
+ auto BE = BB->end();
+ auto BBI = BasicBlock::iterator(FromInst);
+ BBI++;
+ for (; BBI != BE && &*BBI != ToInst; BBI++) {
+ auto* LI = dyn_cast<LoadInst>(&*BBI);
+ if (LI == nullptr || !LI->isAtomic() || LI->getOrdering() != Monotonic) {
+ continue;
+ }
+ LastLoad = LI;
+ LastLoad = LastLoad->getNextNode();
+ }
+ return LastLoad;
+}
+
// XXX-comment: Returns whether the code has been changed.
bool taintMonotonicLoads(const SmallVector<LoadInst*, 1>& MonotonicLoadInsts) {
bool Changed = false;
// Now we have a previously added fake cond branch.
auto* Op00 = Op0->getOperand(0);
IRBuilder<true, NoFolder> Builder(CmpInst);
- if (UsageInst->getType() == TargetIntegerType) {
+ if (Op00->getType() == UsageInst->getType()) {
AndTarget = UsageInst;
} else {
- AndTarget = createCast(Builder, UsageInst, TargetIntegerType);
+ AndTarget = createCast(Builder, UsageInst, Op00->getType());
}
AndTarget = Builder.CreateAnd(Op00, AndTarget);
auto* AndZero = dyn_cast<Instruction>(Builder.CreateAnd(
}
IRBuilder<true, NoFolder> Builder(InsertPoint);
- if (UsageInst->getType() == TargetIntegerType) {
+ if (IntegerType::classof(UsageInst->getType())) {
AndTarget = UsageInst;
} else {
AndTarget = createCast(Builder, UsageInst, TargetIntegerType);