if (AnalyzeGlobal(I, GS, PHIUsers)) return true;
GS.isNotSuitableForSRA = true;
GS.HasPHIUser = true;
- } else if (isa<SetCondInst>(I)) {
+ } else if (isa<CmpInst>(I)) {
GS.isNotSuitableForSRA = true;
} else if (isa<MemCpyInst>(I) || isa<MemMoveInst>(I)) {
if (I->getOperand(1) == V)
if (!AllUsesOfValueWillTrapIfNull(CI)) return false;
} else if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(*UI)) {
if (!AllUsesOfValueWillTrapIfNull(GEPI)) return false;
- } else if (isa<SetCondInst>(*UI) &&
+ } else if (isa<ICmpInst>(*UI) &&
isa<ConstantPointerNull>(UI->getOperand(1))) {
// Ignore setcc X, null
} else {
if (LoadInst *LI = dyn_cast<LoadInst>(GV->use_back())) {
while (!LI->use_empty()) {
Use &LoadUse = LI->use_begin().getUse();
- if (!isa<SetCondInst>(LoadUse.getUser()))
+ if (!isa<ICmpInst>(LoadUse.getUser()))
LoadUse = RepValue;
else {
- // Replace the setcc X, 0 with a use of the bool value.
- SetCondInst *SCI = cast<SetCondInst>(LoadUse.getUser());
- Value *LV = new LoadInst(InitBool, InitBool->getName()+".val", SCI);
+ ICmpInst *CI = cast<ICmpInst>(LoadUse.getUser());
+ // Replace the cmp X, 0 with a use of the bool value.
+ Value *LV = new LoadInst(InitBool, InitBool->getName()+".val", CI);
InitBoolUsed = true;
- switch (SCI->getOpcode()) {
- default: assert(0 && "Unknown opcode!");
- case Instruction::SetLT:
+ switch (CI->getPredicate()) {
+ default: assert(0 && "Unknown ICmp Predicate!");
+ case ICmpInst::ICMP_ULT:
+ case ICmpInst::ICMP_SLT:
LV = ConstantBool::getFalse(); // X < null -> always false
break;
- case Instruction::SetEQ:
- case Instruction::SetLE:
- LV = BinaryOperator::createNot(LV, "notinit", SCI);
+ case ICmpInst::ICMP_ULE:
+ case ICmpInst::ICMP_SLE:
+ case ICmpInst::ICMP_EQ:
+ LV = BinaryOperator::createNot(LV, "notinit", CI);
break;
- case Instruction::SetNE:
- case Instruction::SetGE:
- case Instruction::SetGT:
+ case ICmpInst::ICMP_NE:
+ case ICmpInst::ICMP_UGE:
+ case ICmpInst::ICMP_SGE:
+ case ICmpInst::ICMP_UGT:
+ case ICmpInst::ICMP_SGT:
break; // no change.
}
- SCI->replaceAllUsesWith(LV);
- SCI->eraseFromParent();
+ CI->replaceAllUsesWith(LV);
+ CI->eraseFromParent();
}
}
LI->eraseFromParent();
static bool ValueIsOnlyUsedLocallyOrStoredToOneGlobal(Instruction *V,
GlobalVariable *GV) {
for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E;++UI)
- if (isa<LoadInst>(*UI) || isa<SetCondInst>(*UI)) {
+ if (isa<LoadInst>(*UI) || isa<CmpInst>(*UI)) {
// Fine, ignore.
} else if (StoreInst *SI = dyn_cast<StoreInst>(*UI)) {
if (SI->getOperand(0) == V && SI->getOperand(1) != GV)
for (Value::use_iterator UI = LI->use_begin(), E = LI->use_end(); UI != E;
++UI) {
// Comparison against null is ok.
- if (SetCondInst *SCI = dyn_cast<SetCondInst>(*UI)) {
- if (!isa<ConstantPointerNull>(SCI->getOperand(1)))
+ if (ICmpInst *ICI = dyn_cast<ICmpInst>(*UI)) {
+ if (!isa<ConstantPointerNull>(ICI->getOperand(1)))
return false;
continue;
}
Instruction *User = Ptr->use_back();
// If this is a comparison against null, handle it.
- if (SetCondInst *SCI = dyn_cast<SetCondInst>(User)) {
+ if (ICmpInst *SCI = dyn_cast<ICmpInst>(User)) {
assert(isa<ConstantPointerNull>(SCI->getOperand(1)));
// If we have a setcc of the loaded pointer, we can use a setcc of any
// field.
NPtr = InsertedLoadsForPtr.back();
}
- Value *New = new SetCondInst(SCI->getOpcode(), NPtr,
- Constant::getNullValue(NPtr->getType()),
- SCI->getName(), SCI);
+ Value *New = new ICmpInst(SCI->getPredicate(), NPtr,
+ Constant::getNullValue(NPtr->getType()),
+ SCI->getName(), SCI);
SCI->replaceAllUsesWith(New);
SCI->eraseFromParent();
continue;
// }
Value *RunningOr = 0;
for (unsigned i = 0, e = FieldMallocs.size(); i != e; ++i) {
- Value *Cond = new SetCondInst(Instruction::SetEQ, FieldMallocs[i],
+ Value *Cond = new ICmpInst(ICmpInst::ICMP_EQ, FieldMallocs[i],
Constant::getNullValue(FieldMallocs[i]->getType()),
"isnull", MI);
if (!RunningOr)
// pointer, because some may be null while others are not.
for (unsigned i = 0, e = FieldGlobals.size(); i != e; ++i) {
Value *GVVal = new LoadInst(FieldGlobals[i], "tmp", NullPtrBlock);
- Value *Cmp = new SetCondInst(Instruction::SetNE, GVVal,
- Constant::getNullValue(GVVal->getType()),
- "tmp", NullPtrBlock);
+ Value *Cmp = new ICmpInst(ICmpInst::ICMP_NE, GVVal,
+ Constant::getNullValue(GVVal->getType()),
+ "tmp", NullPtrBlock);
BasicBlock *FreeBlock = new BasicBlock("free_it", OrigBB->getParent());
BasicBlock *NextBlock = new BasicBlock("next", OrigBB->getParent());
new BranchInst(FreeBlock, NextBlock, Cmp, NullPtrBlock);
InstResult = ConstantExpr::get(SI->getOpcode(),
getVal(Values, SI->getOperand(0)),
getVal(Values, SI->getOperand(1)));
+ } else if (CmpInst *CI = dyn_cast<CmpInst>(CurInst)) {
+ InstResult = ConstantExpr::getCompare(CI->getPredicate(),
+ getVal(Values, CI->getOperand(0)),
+ getVal(Values, CI->getOperand(1)));
} else if (CastInst *CI = dyn_cast<CastInst>(CurInst)) {
InstResult = ConstantExpr::getCast(CI->getOpcode(),
getVal(Values, CI->getOperand(0)),