auto* BB = UsageInst->getParent();
if (InsertPoint == nullptr) {
InsertPoint = UsageInst->getNextNode();
- while (dyn_cast<PHINode>(InsertPoint)) {
- InsertPoint = InsertPoint->getNextNode();
- }
+ }
+ // Insert instructions after PHI nodes.
+ while (dyn_cast<PHINode>(InsertPoint)) {
+ InsertPoint = InsertPoint->getNextNode();
}
// First thing is to cast 'UsageInst' to an integer type if necessary.
Value* AndTarget = nullptr;
- if (IntegerType::classof(UsageInst->getType())) {
+ Type* TargetIntegerType =
+ IntegerType::get(UsageInst->getContext(),
+ BB->getModule()->getDataLayout().getPointerSizeInBits());
+ if (UsageInst->getType() == TargetIntegerType) {
AndTarget = UsageInst;
} else {
- Type* TargetIntegerType = IntegerType::get(
- UsageInst->getContext(),
- BB->getModule()->getDataLayout().getPointerSizeInBits());
- IRBuilder<true, NoFolder> Builder(UsageInst->getNextNode());
+ IRBuilder<true, NoFolder> Builder(InsertPoint);
AndTarget = createCast(Builder, UsageInst, TargetIntegerType);
}