12 changes: 6 additions & 6 deletions llvm/lib/Transforms/Utils/LowerInvoke.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,9 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
EntryBB->getTerminator());

// Compare the return value to zero.
Value *IsNormal = BinaryOperator::createSetEQ(SJRet,
Constant::getNullValue(SJRet->getType()),
"notunwind", EntryBB->getTerminator());
Value *IsNormal = new ICmpInst(ICmpInst::ICMP_EQ, SJRet,
Constant::getNullValue(SJRet->getType()),
"notunwind", EntryBB->getTerminator());
// Nuke the uncond branch.
EntryBB->getTerminator()->eraseFromParent();

Expand Down Expand Up @@ -551,9 +551,9 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
}

// Load the JBList, if it's null, then there was no catch!
Value *NotNull = BinaryOperator::createSetNE(BufPtr,
Constant::getNullValue(BufPtr->getType()),
"notnull", UnwindHandler);
Value *NotNull = new ICmpInst(ICmpInst::ICMP_NE, BufPtr,
Constant::getNullValue(BufPtr->getType()),
"notnull", UnwindHandler);
new BranchInst(UnwindBlock, TermBlock, NotNull, UnwindHandler);

// Create the block to do the longjmp.
Expand Down
7 changes: 3 additions & 4 deletions llvm/lib/Transforms/Utils/LowerSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ BasicBlock* LowerSwitch::switchConvert(CaseItr Begin, CaseItr End,
BasicBlock* NewNode = new BasicBlock("NodeBlock");
F->getBasicBlockList().insert(OrigBlock->getNext(), NewNode);

SetCondInst* Comp = new SetCondInst(Instruction::SetLT, Val, Pivot.first,
"Pivot");
ICmpInst* Comp = new ICmpInst(ICmpInst::ICMP_ULT, Val, Pivot.first, "Pivot");
NewNode->getInstList().push_back(Comp);
new BranchInst(LBranch, RBranch, Comp, NewNode);
return NewNode;
Expand All @@ -165,8 +164,8 @@ BasicBlock* LowerSwitch::newLeafBlock(Case& Leaf, Value* Val,
F->getBasicBlockList().insert(OrigBlock->getNext(), NewLeaf);

// Make the seteq instruction...
SetCondInst* Comp = new SetCondInst(Instruction::SetEQ, Val,
Leaf.first, "SwitchLeaf");
ICmpInst* Comp = new ICmpInst(ICmpInst::ICMP_EQ, Val,
Leaf.first, "SwitchLeaf");
NewLeaf->getInstList().push_back(Comp);

// Make the conditional branch...
Expand Down
49 changes: 24 additions & 25 deletions llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,8 @@ static bool DominatesMergePoint(Value *V, BasicBlock *BB,
case Instruction::Shl:
case Instruction::LShr:
case Instruction::AShr:
case Instruction::SetEQ:
case Instruction::SetNE:
case Instruction::SetLT:
case Instruction::SetGT:
case Instruction::SetLE:
case Instruction::SetGE:
case Instruction::ICmp:
case Instruction::FCmp:
break; // These are all cheap and non-trapping instructions.
}

Expand All @@ -390,12 +386,13 @@ static bool DominatesMergePoint(Value *V, BasicBlock *BB,
return true;
}

// GatherConstantSetEQs - Given a potentially 'or'd together collection of seteq
// instructions that compare a value against a constant, return the value being
// compared, and stick the constant into the Values vector.
// GatherConstantSetEQs - Given a potentially 'or'd together collection of
// icmp_eq instructions that compare a value against a constant, return the
// value being compared, and stick the constant into the Values vector.
static Value *GatherConstantSetEQs(Value *V, std::vector<ConstantInt*> &Values){
if (Instruction *Inst = dyn_cast<Instruction>(V))
if (Inst->getOpcode() == Instruction::SetEQ) {
if (Inst->getOpcode() == Instruction::ICmp &&
cast<ICmpInst>(Inst)->getPredicate() == ICmpInst::ICMP_EQ) {
if (ConstantInt *C = dyn_cast<ConstantInt>(Inst->getOperand(1))) {
Values.push_back(C);
return Inst->getOperand(0);
Expand All @@ -417,7 +414,8 @@ static Value *GatherConstantSetEQs(Value *V, std::vector<ConstantInt*> &Values){
// being compared, and stick the constant into the Values vector.
static Value *GatherConstantSetNEs(Value *V, std::vector<ConstantInt*> &Values){
if (Instruction *Inst = dyn_cast<Instruction>(V))
if (Inst->getOpcode() == Instruction::SetNE) {
if (Inst->getOpcode() == Instruction::ICmp &&
cast<ICmpInst>(Inst)->getPredicate() == ICmpInst::ICMP_NE) {
if (ConstantInt *C = dyn_cast<ConstantInt>(Inst->getOperand(1))) {
Values.push_back(C);
return Inst->getOperand(0);
Expand Down Expand Up @@ -503,11 +501,11 @@ static Value *isValueEqualityComparison(TerminatorInst *TI) {
}
if (BranchInst *BI = dyn_cast<BranchInst>(TI))
if (BI->isConditional() && BI->getCondition()->hasOneUse())
if (SetCondInst *SCI = dyn_cast<SetCondInst>(BI->getCondition()))
if ((SCI->getOpcode() == Instruction::SetEQ ||
SCI->getOpcode() == Instruction::SetNE) &&
isa<ConstantInt>(SCI->getOperand(1)))
return SCI->getOperand(0);
if (ICmpInst *ICI = dyn_cast<ICmpInst>(BI->getCondition()))
if ((ICI->getPredicate() == ICmpInst::ICMP_EQ ||
ICI->getPredicate() == ICmpInst::ICMP_NE) &&
isa<ConstantInt>(ICI->getOperand(1)))
return ICI->getOperand(0);
return 0;
}

Expand All @@ -525,11 +523,11 @@ GetValueEqualityComparisonCases(TerminatorInst *TI,
}

BranchInst *BI = cast<BranchInst>(TI);
SetCondInst *SCI = cast<SetCondInst>(BI->getCondition());
Cases.push_back(std::make_pair(cast<ConstantInt>(SCI->getOperand(1)),
BI->getSuccessor(SCI->getOpcode() ==
Instruction::SetNE)));
return BI->getSuccessor(SCI->getOpcode() == Instruction::SetEQ);
ICmpInst *ICI = cast<ICmpInst>(BI->getCondition());
Cases.push_back(std::make_pair(cast<ConstantInt>(ICI->getOperand(1)),
BI->getSuccessor(ICI->getPredicate() ==
ICmpInst::ICMP_NE)));
return BI->getSuccessor(ICI->getPredicate() == ICmpInst::ICMP_EQ);
}


Expand Down Expand Up @@ -847,8 +845,8 @@ static bool HoistThenElseCodeToIf(BranchInst *BI) {
BasicBlock *BB2 = BI->getSuccessor(1); // The false destination

Instruction *I1 = BB1->begin(), *I2 = BB2->begin();
if (I1->getOpcode() != I2->getOpcode() || !I1->isIdenticalTo(I2) ||
isa<PHINode>(I1) || isa<InvokeInst>(I1))
if (I1->getOpcode() != I2->getOpcode() || isa<PHINode>(I1) ||
isa<InvokeInst>(I1) || !I1->isIdenticalTo(I2))
return false;

// If we get here, we can hoist at least one instruction.
Expand Down Expand Up @@ -1443,8 +1441,9 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
// predecessor and use logical operations to pick the right destination.
BasicBlock *TrueDest = BI->getSuccessor(0);
BasicBlock *FalseDest = BI->getSuccessor(1);
if (BinaryOperator *Cond = dyn_cast<BinaryOperator>(BI->getCondition()))
if (Cond->getParent() == BB && &BB->front() == Cond &&
if (Instruction *Cond = dyn_cast<Instruction>(BI->getCondition()))
if ((isa<CmpInst>(Cond) || isa<BinaryOperator>(Cond)) &&
Cond->getParent() == BB && &BB->front() == Cond &&
Cond->getNext() == BI && Cond->hasOneUse() &&
TrueDest != BB && FalseDest != BB)
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI!=E; ++PI)
Expand Down
1,377 changes: 581 additions & 796 deletions llvm/lib/VMCore/ConstantFolding.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions llvm/lib/VMCore/ConstantFolding.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ namespace llvm {
const Constant *Mask);
Constant *ConstantFoldBinaryInstruction(unsigned Opcode, const Constant *V1,
const Constant *V2);
Constant *ConstantFoldCompare(unsigned opcode, Constant *C1, Constant *C2,
unsigned short predicate);
Constant *ConstantFoldCompareInstruction(unsigned short predicate,
Constant *C1, Constant *C2);
Constant *ConstantFoldGetElementPtr(const Constant *C,
const std::vector<Value*> &IdxList);
} // End llvm namespace
Expand Down
65 changes: 25 additions & 40 deletions llvm/lib/VMCore/Constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,6 @@ ConstantPacked::~ConstantPacked() {
delete [] OperandList;
}

static bool isSetCC(unsigned Opcode) {
return Opcode == Instruction::SetEQ || Opcode == Instruction::SetNE ||
Opcode == Instruction::SetLT || Opcode == Instruction::SetGT ||
Opcode == Instruction::SetLE || Opcode == Instruction::SetGE;
}

// We declare several classes private to this file, so use an anonymous
// namespace
namespace {
Expand All @@ -290,8 +284,7 @@ class VISIBILITY_HIDDEN BinaryConstantExpr : public ConstantExpr {
Use Ops[2];
public:
BinaryConstantExpr(unsigned Opcode, Constant *C1, Constant *C2)
: ConstantExpr(isSetCC(Opcode) ? Type::BoolTy : C1->getType(),
Opcode, Ops, 2) {
: ConstantExpr(C1->getType(), Opcode, Ops, 2) {
Ops[0].init(C1, this);
Ops[1].init(C2, this);
}
Expand Down Expand Up @@ -448,24 +441,6 @@ Constant *ConstantExpr::getOr(Constant *C1, Constant *C2) {
Constant *ConstantExpr::getXor(Constant *C1, Constant *C2) {
return get(Instruction::Xor, C1, C2);
}
Constant *ConstantExpr::getSetEQ(Constant *C1, Constant *C2) {
return get(Instruction::SetEQ, C1, C2);
}
Constant *ConstantExpr::getSetNE(Constant *C1, Constant *C2) {
return get(Instruction::SetNE, C1, C2);
}
Constant *ConstantExpr::getSetLT(Constant *C1, Constant *C2) {
return get(Instruction::SetLT, C1, C2);
}
Constant *ConstantExpr::getSetGT(Constant *C1, Constant *C2) {
return get(Instruction::SetGT, C1, C2);
}
Constant *ConstantExpr::getSetLE(Constant *C1, Constant *C2) {
return get(Instruction::SetLE, C1, C2);
}
Constant *ConstantExpr::getSetGE(Constant *C1, Constant *C2) {
return get(Instruction::SetGE, C1, C2);
}
unsigned ConstantExpr::getPredicate() const {
assert(getOpcode() == Instruction::FCmp || getOpcode() == Instruction::ICmp);
return dynamic_cast<const CompareConstantExpr*>(this)->predicate;
Expand Down Expand Up @@ -582,6 +557,9 @@ getWithOperands(const std::vector<Constant*> &Ops) const {
std::vector<Constant*> ActualOps(Ops.begin()+1, Ops.end());
return ConstantExpr::getGetElementPtr(Ops[0], ActualOps);
}
case Instruction::ICmp:
case Instruction::FCmp:
return ConstantExpr::getCompare(getPredicate(), Ops[0], Ops[1]);
default:
assert(getNumOperands() == 2 && "Must be binary operator?");
return ConstantExpr::get(getOpcode(), Ops[0], Ops[1]);
Expand Down Expand Up @@ -1657,8 +1635,7 @@ Constant *ConstantExpr::getTy(const Type *ReqTy, unsigned Opcode,
assert(C1->getType() == C2->getType() &&
"Operand types in binary constant expression should match");

if (ReqTy == C1->getType() || (Instruction::isComparison(Opcode) &&
ReqTy == Type::BoolTy))
if (ReqTy == C1->getType() || ReqTy == Type::BoolTy)
if (Constant *FC = ConstantFoldBinaryInstruction(Opcode, C1, C2))
return FC; // Fold a few common cases...

Expand All @@ -1667,11 +1644,23 @@ Constant *ConstantExpr::getTy(const Type *ReqTy, unsigned Opcode,
return ExprConstants->getOrCreate(ReqTy, Key);
}

Constant *ConstantExpr::getCompareTy(unsigned Opcode, unsigned short predicate,
Constant *ConstantExpr::getCompareTy(unsigned short predicate,
Constant *C1, Constant *C2) {
if (Opcode == Instruction::ICmp)
return getICmp(predicate, C1, C2);
return getFCmp(predicate, C1, C2);
switch (predicate) {
default: assert(0 && "Invalid CmpInst predicate");
case FCmpInst::FCMP_FALSE: case FCmpInst::FCMP_OEQ: case FCmpInst::FCMP_OGT:
case FCmpInst::FCMP_OGE: case FCmpInst::FCMP_OLT: case FCmpInst::FCMP_OLE:
case FCmpInst::FCMP_ONE: case FCmpInst::FCMP_ORD: case FCmpInst::FCMP_UNO:
case FCmpInst::FCMP_UEQ: case FCmpInst::FCMP_UGT: case FCmpInst::FCMP_UGE:
case FCmpInst::FCMP_ULT: case FCmpInst::FCMP_ULE: case FCmpInst::FCMP_UNE:
case FCmpInst::FCMP_TRUE:
return getFCmp(predicate, C1, C2);
case ICmpInst::ICMP_EQ: case ICmpInst::ICMP_NE: case ICmpInst::ICMP_UGT:
case ICmpInst::ICMP_UGE: case ICmpInst::ICMP_ULT: case ICmpInst::ICMP_ULE:
case ICmpInst::ICMP_SGT: case ICmpInst::ICMP_SGE: case ICmpInst::ICMP_SLT:
case ICmpInst::ICMP_SLE:
return getICmp(predicate, C1, C2);
}
}

Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) {
Expand Down Expand Up @@ -1718,10 +1707,6 @@ Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) {
assert((C1->getType()->isIntegral() || isa<PackedType>(C1->getType())) &&
"Tried to create a logical operation on a non-integral type!");
break;
case Instruction::SetLT: case Instruction::SetGT: case Instruction::SetLE:
case Instruction::SetGE: case Instruction::SetEQ: case Instruction::SetNE:
assert(C1->getType() == C2->getType() && "Op types should be identical!");
break;
case Instruction::Shl:
case Instruction::LShr:
case Instruction::AShr:
Expand All @@ -1737,10 +1722,10 @@ Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) {
return getTy(C1->getType(), Opcode, C1, C2);
}

Constant *ConstantExpr::getCompare(unsigned Opcode, unsigned short pred,
Constant *ConstantExpr::getCompare(unsigned short pred,
Constant *C1, Constant *C2) {
assert(C1->getType() == C2->getType() && "Op types should be identical!");
return getCompareTy(Opcode, pred, C1, C2);
return getCompareTy(pred, C1, C2);
}

Constant *ConstantExpr::getSelectTy(const Type *ReqTy, Constant *C,
Expand Down Expand Up @@ -1826,7 +1811,7 @@ ConstantExpr::getICmp(unsigned short pred, Constant* LHS, Constant* RHS) {
assert(pred >= ICmpInst::FIRST_ICMP_PREDICATE &&
pred <= ICmpInst::LAST_ICMP_PREDICATE && "Invalid ICmp Predicate");

if (Constant *FC = ConstantFoldCompare(Instruction::ICmp, LHS, RHS, pred))
if (Constant *FC = ConstantFoldCompareInstruction(pred, LHS, RHS))
return FC; // Fold a few common cases...

// Look up the constant in the table first to ensure uniqueness
Expand All @@ -1843,7 +1828,7 @@ ConstantExpr::getFCmp(unsigned short pred, Constant* LHS, Constant* RHS) {
assert(LHS->getType() == RHS->getType());
assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && "Invalid FCmp Predicate");

if (Constant *FC = ConstantFoldCompare(Instruction::FCmp, LHS, RHS, pred))
if (Constant *FC = ConstantFoldCompareInstruction(pred, LHS, RHS))
return FC; // Fold a few common cases...

// Look up the constant in the table first to ensure uniqueness
Expand Down
54 changes: 27 additions & 27 deletions llvm/lib/VMCore/Instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,6 @@ const char *Instruction::getOpcodeName(unsigned OpCode) {
case Or : return "or";
case Xor: return "xor";

// SetCC operators...
case SetLE: return "setle";
case SetGE: return "setge";
case SetLT: return "setlt";
case SetGT: return "setgt";
case SetEQ: return "seteq";
case SetNE: return "setne";

// Memory instructions...
case Malloc: return "malloc";
case Free: return "free";
Expand Down Expand Up @@ -176,8 +168,35 @@ bool Instruction::isIdenticalTo(Instruction *I) const {
return LI->isVolatile() == cast<LoadInst>(I)->isVolatile();
if (const StoreInst *SI = dyn_cast<StoreInst>(this))
return SI->isVolatile() == cast<StoreInst>(I)->isVolatile();
if (const CmpInst *CI = dyn_cast<CmpInst>(this))
return CI->getPredicate() == cast<CmpInst>(I)->getPredicate();
if (const CallInst *CI = dyn_cast<CallInst>(this))
return CI->isTailCall() == cast<CallInst>(I)->isTailCall();
return true;
}

// isSameOperationAs
bool Instruction::isSameOperationAs(Instruction *I) const {
if (getOpcode() != I->getOpcode() || getType() != I->getType() ||
getNumOperands() != I->getNumOperands())
return false;

// We have two instructions of identical opcode and #operands. Check to see
// if all operands are the same type
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
if (getOperand(i)->getType() != I->getOperand(i)->getType())
return false;

// Check special state that is a part of some instructions.
if (const LoadInst *LI = dyn_cast<LoadInst>(this))
return LI->isVolatile() == cast<LoadInst>(I)->isVolatile();
if (const StoreInst *SI = dyn_cast<StoreInst>(this))
return SI->isVolatile() == cast<StoreInst>(I)->isVolatile();
if (const CmpInst *CI = dyn_cast<CmpInst>(this))
return CI->getPredicate() == cast<CmpInst>(I)->getPredicate();
if (const CallInst *CI = dyn_cast<CallInst>(this))
return CI->isTailCall() == cast<CallInst>(I)->isTailCall();

return true;
}

Expand Down Expand Up @@ -213,31 +232,12 @@ bool Instruction::isCommutative(unsigned op) {
case And:
case Or:
case Xor:
case SetEQ:
case SetNE:
return true;
default:
return false;
}
}

/// isComparison - Return true if the instruction is a Set* instruction:
///
bool Instruction::isComparison(unsigned op) {
switch (op) {
case SetEQ:
case SetNE:
case SetLT:
case SetGT:
case SetLE:
case SetGE:
return true;
}
return false;
}



/// isTrappingInstruction - Return true if the instruction may trap.
///
bool Instruction::isTrapping(unsigned op) {
Expand Down
137 changes: 63 additions & 74 deletions llvm/lib/VMCore/Instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1068,9 +1068,6 @@ void BinaryOperator::init(BinaryOps iType)
cast<PackedType>(getType())->getElementType()->isIntegral())) &&
"Tried to create a logical operation on a non-integral type!");
break;
case SetLT: case SetGT: case SetLE:
case SetGE: case SetEQ: case SetNE:
assert(getType() == Type::BoolTy && "Setcc must return bool!");
default:
break;
}
Expand All @@ -1082,15 +1079,7 @@ BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2,
Instruction *InsertBefore) {
assert(S1->getType() == S2->getType() &&
"Cannot create binary operator with two operands of differing type!");
switch (Op) {
// Binary comparison operators...
case SetLT: case SetGT: case SetLE:
case SetGE: case SetEQ: case SetNE:
return new SetCondInst(Op, S1, S2, Name, InsertBefore);

default:
return new BinaryOperator(Op, S1, S2, S1->getType(), Name, InsertBefore);
}
return new BinaryOperator(Op, S1, S2, S1->getType(), Name, InsertBefore);
}

BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2,
Expand Down Expand Up @@ -1210,14 +1199,8 @@ const Value *BinaryOperator::getNotArgument(const Value *BinOp) {
// order dependent (SetLT f.e.) the opcode is changed.
//
bool BinaryOperator::swapOperands() {
if (isCommutative())
; // If the instruction is commutative, it is safe to swap the operands
else if (SetCondInst *SCI = dyn_cast<SetCondInst>(this))
/// FIXME: SetCC instructions shouldn't all have different opcodes.
setOpcode(SCI->getSwappedCondition());
else
return true; // Can't commute operands

if (!isCommutative())
return true; // Can't commute operands
std::swap(Ops[0], Ops[1]);
return false;
}
Expand Down Expand Up @@ -1925,58 +1908,6 @@ BitCastInst::BitCastInst(
assert(checkCast(getOpcode(), S, Ty) && "Illegal BitCast");
}

//===----------------------------------------------------------------------===//
// SetCondInst Class
//===----------------------------------------------------------------------===//

SetCondInst::SetCondInst(BinaryOps Opcode, Value *S1, Value *S2,
const std::string &Name, Instruction *InsertBefore)
: BinaryOperator(Opcode, S1, S2, Type::BoolTy, Name, InsertBefore) {

// Make sure it's a valid type... getInverseCondition will assert out if not.
assert(getInverseCondition(Opcode));
}

SetCondInst::SetCondInst(BinaryOps Opcode, Value *S1, Value *S2,
const std::string &Name, BasicBlock *InsertAtEnd)
: BinaryOperator(Opcode, S1, S2, Type::BoolTy, Name, InsertAtEnd) {

// Make sure it's a valid type... getInverseCondition will assert out if not.
assert(getInverseCondition(Opcode));
}

// getInverseCondition - Return the inverse of the current condition opcode.
// For example seteq -> setne, setgt -> setle, setlt -> setge, etc...
//
Instruction::BinaryOps SetCondInst::getInverseCondition(BinaryOps Opcode) {
switch (Opcode) {
default:
assert(0 && "Unknown setcc opcode!");
case SetEQ: return SetNE;
case SetNE: return SetEQ;
case SetGT: return SetLE;
case SetLT: return SetGE;
case SetGE: return SetLT;
case SetLE: return SetGT;
}
}

// getSwappedCondition - Return the condition opcode that would be the result
// of exchanging the two operands of the setcc instruction without changing
// the result produced. Thus, seteq->seteq, setle->setge, setlt->setgt, etc.
//
Instruction::BinaryOps SetCondInst::getSwappedCondition(BinaryOps Opcode) {
switch (Opcode) {
default: assert(0 && "Unknown setcc instruction!");
case SetEQ: case SetNE: return Opcode;
case SetGT: return SetLT;
case SetLT: return SetGT;
case SetGE: return SetLE;
case SetLE: return SetGE;
}
}


//===----------------------------------------------------------------------===//
// CmpInst Classes
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -2111,7 +2042,7 @@ ICmpInst::Predicate ICmpInst::getInversePredicate(Predicate pred) {

ICmpInst::Predicate ICmpInst::getSwappedPredicate(Predicate pred) {
switch (pred) {
default: assert(! "Unknown setcc instruction!");
default: assert(! "Unknown icmp predicate!");
case ICMP_EQ: case ICMP_NE:
return pred;
case ICMP_SGT: return ICMP_SLT;
Expand All @@ -2125,6 +2056,30 @@ ICmpInst::Predicate ICmpInst::getSwappedPredicate(Predicate pred) {
}
}

ICmpInst::Predicate ICmpInst::getSignedPredicate(Predicate pred) {
switch (pred) {
default: assert(! "Unknown icmp predicate!");
case ICMP_EQ: case ICMP_NE:
case ICMP_SGT: case ICMP_SLT: case ICMP_SGE: case ICMP_SLE:
return pred;
case ICMP_UGT: return ICMP_SGT;
case ICMP_ULT: return ICMP_SLT;
case ICMP_UGE: return ICMP_SGE;
case ICMP_ULE: return ICMP_SLE;
}
}

bool ICmpInst::isSignedPredicate(Predicate pred) {
switch (pred) {
default: assert(! "Unknown icmp predicate!");
case ICMP_SGT: case ICMP_SLT: case ICMP_SGE: case ICMP_SLE:
return true;
case ICMP_EQ: case ICMP_NE: case ICMP_UGT: case ICMP_ULT:
case ICMP_UGE: case ICMP_ULE:
return false;
}
}

FCmpInst::Predicate FCmpInst::getInversePredicate(Predicate pred) {
switch (pred) {
default:
Expand All @@ -2150,7 +2105,7 @@ FCmpInst::Predicate FCmpInst::getInversePredicate(Predicate pred) {

FCmpInst::Predicate FCmpInst::getSwappedPredicate(Predicate pred) {
switch (pred) {
default: assert(!"Unknown setcc instruction!");
default: assert(!"Unknown fcmp predicate!");
case FCMP_FALSE: case FCMP_TRUE:
case FCMP_OEQ: case FCMP_ONE:
case FCMP_UEQ: case FCMP_UNE:
Expand All @@ -2167,6 +2122,40 @@ FCmpInst::Predicate FCmpInst::getSwappedPredicate(Predicate pred) {
}
}

bool CmpInst::isUnsigned(unsigned short predicate) {
switch (predicate) {
default: return false;
case ICmpInst::ICMP_ULT: case ICmpInst::ICMP_ULE: case ICmpInst::ICMP_UGT:
case ICmpInst::ICMP_UGE: return true;
}
}

bool CmpInst::isSigned(unsigned short predicate){
switch (predicate) {
default: return false;
case ICmpInst::ICMP_SLT: case ICmpInst::ICMP_SLE: case ICmpInst::ICMP_SGT:
case ICmpInst::ICMP_SGE: return true;
}
}

bool CmpInst::isOrdered(unsigned short predicate) {
switch (predicate) {
default: return false;
case FCmpInst::FCMP_OEQ: case FCmpInst::FCMP_ONE: case FCmpInst::FCMP_OGT:
case FCmpInst::FCMP_OLT: case FCmpInst::FCMP_OGE: case FCmpInst::FCMP_OLE:
case FCmpInst::FCMP_ORD: return true;
}
}

bool CmpInst::isUnordered(unsigned short predicate) {
switch (predicate) {
default: return false;
case FCmpInst::FCMP_UEQ: case FCmpInst::FCMP_UNE: case FCmpInst::FCMP_UGT:
case FCmpInst::FCMP_ULT: case FCmpInst::FCMP_UGE: case FCmpInst::FCMP_ULE:
case FCmpInst::FCMP_UNO: return true;
}
}

//===----------------------------------------------------------------------===//
// SwitchInst Implementation
//===----------------------------------------------------------------------===//
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/VMCore/SymbolTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ void SymbolTable::insertEntry(const std::string &Name, const Type *VTy,
}


// insertEntry - Insert a value into the symbol table with the specified
// insertEntry - Insert a type into the symbol table with the specified
// name...
//
void SymbolTable::insert(const std::string& Name, const Type* T) {
Expand Down
4 changes: 0 additions & 4 deletions llvm/lib/VMCore/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,10 +719,6 @@ void Verifier::visitBinaryOperator(BinaryOperator &B) {
Assert1(B.getType() == B.getOperand(0)->getType(),
"Logical operators must have same type for operands and result!",
&B);
} else if (isa<SetCondInst>(B)) {
// Check that setcc instructions return bool
Assert1(B.getType() == Type::BoolTy,
"setcc instructions must return boolean values!", &B);
} else {
// Arithmetic operators only work on integer or fp values
Assert1(B.getType() == B.getOperand(0)->getType(),
Expand Down
50 changes: 25 additions & 25 deletions llvm/projects/Stacker/lib/compiler/StackerCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ StackerCompiler::handle_if( char* ifTrue, char* ifFalse )
LoadInst* cond = cast<LoadInst>( pop_integer(bb) );

// Compare the condition against 0
SetCondInst* cond_inst = new SetCondInst( Instruction::SetNE, cond,
ICmpInst* cond_inst = new ICmpInst( ICmpInst::ICMP_NE, cond,
ConstantInt::get( Type::LongTy, 0) );
bb->getInstList().push_back( cond_inst );

Expand All @@ -735,7 +735,7 @@ StackerCompiler::handle_if( char* ifTrue, char* ifFalse )
BasicBlock* false_bb = 0;
if ( ifFalse ) false_bb = new BasicBlock((echo?"else":""));

// Create a branch on the SetCond
// Create a branch on the ICmp
BranchInst* br_inst = new BranchInst( true_bb,
( ifFalse ? false_bb : exit_bb ), cond_inst );
bb->getInstList().push_back( br_inst );
Expand Down Expand Up @@ -805,8 +805,8 @@ StackerCompiler::handle_while( char* todo )
LoadInst* cond = cast<LoadInst>( stack_top(test) );

// Compare the condition against 0
SetCondInst* cond_inst = new SetCondInst(
Instruction::SetNE, cond, ConstantInt::get( Type::LongTy, 0));
ICmpInst* cond_inst = new ICmpInst(
ICmpInst::ICMP_NE, cond, ConstantInt::get( Type::LongTy, 0));
test->getInstList().push_back( cond_inst );

// Add the branch instruction
Expand Down Expand Up @@ -920,8 +920,8 @@ StackerCompiler::handle_word( int tkn )
if (echo) bb->setName("LESS");
LoadInst* op1 = cast<LoadInst>(pop_integer(bb));
LoadInst* op2 = cast<LoadInst>(pop_integer(bb));
SetCondInst* cond_inst =
new SetCondInst( Instruction::SetLT, op1, op2 );
ICmpInst* cond_inst =
new ICmpInst( ICmpInst::ICMP_SLT, op1, op2 );
bb->getInstList().push_back( cond_inst );
push_value( bb, cond_inst );
break;
Expand All @@ -931,8 +931,8 @@ StackerCompiler::handle_word( int tkn )
if (echo) bb->setName("MORE");
LoadInst* op1 = cast<LoadInst>(pop_integer(bb));
LoadInst* op2 = cast<LoadInst>(pop_integer(bb));
SetCondInst* cond_inst =
new SetCondInst( Instruction::SetGT, op1, op2 );
ICmpInst* cond_inst =
new ICmpInst( ICmpInst::ICMP_SGT, op1, op2 );
bb->getInstList().push_back( cond_inst );
push_value( bb, cond_inst );
break;
Expand All @@ -942,8 +942,8 @@ StackerCompiler::handle_word( int tkn )
if (echo) bb->setName("LE");
LoadInst* op1 = cast<LoadInst>(pop_integer(bb));
LoadInst* op2 = cast<LoadInst>(pop_integer(bb));
SetCondInst* cond_inst =
new SetCondInst( Instruction::SetLE, op1, op2 );
ICmpInst* cond_inst =
new ICmpInst( ICmpInst::ICMP_SLE, op1, op2 );
bb->getInstList().push_back( cond_inst );
push_value( bb, cond_inst );
break;
Expand All @@ -953,8 +953,8 @@ StackerCompiler::handle_word( int tkn )
if (echo) bb->setName("GE");
LoadInst* op1 = cast<LoadInst>(pop_integer(bb));
LoadInst* op2 = cast<LoadInst>(pop_integer(bb));
SetCondInst* cond_inst =
new SetCondInst( Instruction::SetGE, op1, op2 );
ICmpInst* cond_inst =
new ICmpInst( ICmpInst::ICMP_SGE, op1, op2 );
bb->getInstList().push_back( cond_inst );
push_value( bb, cond_inst );
break;
Expand All @@ -964,8 +964,8 @@ StackerCompiler::handle_word( int tkn )
if (echo) bb->setName("NE");
LoadInst* op1 = cast<LoadInst>(pop_integer(bb));
LoadInst* op2 = cast<LoadInst>(pop_integer(bb));
SetCondInst* cond_inst =
new SetCondInst( Instruction::SetNE, op1, op2 );
ICmpInst* cond_inst =
new ICmpInst( ICmpInst::ICMP_NE, op1, op2 );
bb->getInstList().push_back( cond_inst );
push_value( bb, cond_inst );
break;
Expand All @@ -975,8 +975,8 @@ StackerCompiler::handle_word( int tkn )
if (echo) bb->setName("EQ");
LoadInst* op1 = cast<LoadInst>(pop_integer(bb));
LoadInst* op2 = cast<LoadInst>(pop_integer(bb));
SetCondInst* cond_inst =
new SetCondInst( Instruction::SetEQ, op1, op2 );
ICmpInst* cond_inst =
new ICmpInst( ICmpInst::ICMP_EQ, op1, op2 );
bb->getInstList().push_back( cond_inst );
push_value( bb, cond_inst );
break;
Expand Down Expand Up @@ -1102,8 +1102,8 @@ StackerCompiler::handle_word( int tkn )
LoadInst* op1 = cast<LoadInst>(stack_top(bb));

// Determine if its negative
SetCondInst* cond_inst =
new SetCondInst( Instruction::SetLT, op1, Zero );
ICmpInst* cond_inst =
new ICmpInst( ICmpInst::ICMP_SLT, op1, Zero );
bb->getInstList().push_back( cond_inst );

// Create a block for storing the result
Expand All @@ -1112,7 +1112,7 @@ StackerCompiler::handle_word( int tkn )
// Create a block for making it a positive value
BasicBlock* pos_bb = new BasicBlock((echo?"neg":""));

// Create the branch on the SetCond
// Create the branch on the ICmp
BranchInst* br_inst = new BranchInst( pos_bb, exit_bb, cond_inst );
bb->getInstList().push_back( br_inst );

Expand Down Expand Up @@ -1143,11 +1143,11 @@ StackerCompiler::handle_word( int tkn )
LoadInst* op2 = cast<LoadInst>(pop_integer(bb));

// Compare them
SetCondInst* cond_inst =
new SetCondInst( Instruction::SetLT, op1, op2);
ICmpInst* cond_inst =
new ICmpInst( ICmpInst::ICMP_SLT, op1, op2);
bb->getInstList().push_back( cond_inst );

// Create a branch on the SetCond
// Create a branch on the ICmp
BranchInst* br_inst =
new BranchInst( op1_block, op2_block, cond_inst );
bb->getInstList().push_back( br_inst );
Expand Down Expand Up @@ -1175,8 +1175,8 @@ StackerCompiler::handle_word( int tkn )
LoadInst* op2 = cast<LoadInst>(pop_integer(bb));

// Compare them
SetCondInst* cond_inst =
new SetCondInst( Instruction::SetGT, op1, op2);
ICmpInst* cond_inst =
new ICmpInst( ICmpInst::ICMP_SGT, op1, op2);
bb->getInstList().push_back( cond_inst );

// Create an exit block
Expand All @@ -1192,7 +1192,7 @@ StackerCompiler::handle_word( int tkn )
push_value(op2_block, op2);
op2_block->getInstList().push_back( new BranchInst( exit_bb ) );

// Create a banch on the SetCond
// Create a banch on the ICmp
BranchInst* br_inst =
new BranchInst( op1_block, op2_block, cond_inst );
bb->getInstList().push_back( br_inst );
Expand Down
3 changes: 1 addition & 2 deletions llvm/test/Regression/CFrontend/2006-12-14-ordered_expr.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %llvmgcc -O3 -S %s -o - | grep llvm.isunordered &&
// RUN: %llvmgcc -O3 -S %s -o - | grep xor
// RUN: %llvmgcc -O3 -S %s -o - | grep 'fcmp ord float %X, %Y'

int test2(float X, float Y) {
return !__builtin_isunordered(X, Y);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
; These tests have an infinite trip count. We obviously shouldn't remove the
; loops! :)
;
; RUN: llvm-upgrade < %s | llvm-as | opt -indvars -adce -simplifycfg | llvm-dis | grep set | wc -l > %t2
; RUN: llvm-upgrade < %s | llvm-as | llvm-dis | grep set | wc -l > %t1
; RUN: llvm-upgrade < %s | llvm-as | opt -indvars -adce -simplifycfg | llvm-dis | grep icmp | wc -l > %t2
; RUN: llvm-upgrade < %s | llvm-as | llvm-dis | grep icmp | wc -l > %t1
; RUN: diff %t1 %t2

int %infinite_linear() { ;; test for (i = 1; i != 100; i += 2)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | grep 'setlt'
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis|grep 'icmp slt'
; ModuleID = 'visible.bc'
target datalayout = "e-p:32:32"
target endian = little
Expand Down
165 changes: 165 additions & 0 deletions llvm/test/Regression/Transforms/InstCombine/2006-12-10-ICmp-GEP-GEP.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
; RUN: grep -v 'icmp ult int'
; ModuleID = 'good.bc'
target datalayout = "e-p:32:32"
target endian = little
target pointersize = 32
target triple = "i686-pc-linux-gnu"
%struct.edgeBox = type { short, short, short, short, short, short }
%qsz = external global int ; <int*> [#uses=12]
%thresh = external global int ; <int*> [#uses=2]
%mthresh = external global int ; <int*> [#uses=1]

implementation ; Functions:

int %qsorte(sbyte* %base, int %n, int %size) {
entry:
%tmp = setgt int %n, 1 ; <bool> [#uses=1]
br bool %tmp, label %cond_next, label %return

cond_next: ; preds = %entry
store int %size, int* %qsz
%tmp3 = shl int %size, ubyte 2 ; <int> [#uses=1]
store int %tmp3, int* %thresh
%tmp4 = load int* %qsz ; <int> [#uses=1]
%tmp5 = mul int %tmp4, 6 ; <int> [#uses=1]
store int %tmp5, int* %mthresh
%tmp6 = load int* %qsz ; <int> [#uses=1]
%tmp8 = mul int %tmp6, %n ; <int> [#uses=1]
%tmp9 = getelementptr sbyte* %base, int %tmp8 ; <sbyte*> [#uses=3]
%tmp11 = setgt int %n, 3 ; <bool> [#uses=1]
br bool %tmp11, label %cond_true12, label %bb30

cond_true12: ; preds = %cond_next
%tmp156 = call int %qste( sbyte* %base, sbyte* %tmp9 ) ; <int> [#uses=0]
%tmp16 = load int* %thresh ; <int> [#uses=1]
%tmp18 = getelementptr sbyte* %base, int %tmp16 ; <sbyte*> [#uses=2]
%tmp3117 = load int* %qsz ; <int> [#uses=1]
%tmp3318 = getelementptr sbyte* %base, int %tmp3117 ; <sbyte*> [#uses=2]
%tmp3621 = setlt sbyte* %tmp3318, %tmp18 ; <bool> [#uses=1]
br bool %tmp3621, label %bb, label %bb37

bb: ; preds = %bb30, %cond_true12
%hi.0.0 = phi sbyte* [ %tmp18, %cond_true12 ], [ %hi.0, %bb30 ] ; <sbyte*> [#uses=4]
%j.1.0 = phi sbyte* [ %base, %cond_true12 ], [ %j.1, %bb30 ] ; <sbyte*> [#uses=4]
%tmp33.0 = phi sbyte* [ %tmp3318, %cond_true12 ], [ %tmp33, %bb30 ] ; <sbyte*> [#uses=6]
%tmp3 = bitcast sbyte* %j.1.0 to %struct.edgeBox* ; <%struct.edgeBox*> [#uses=1]
%tmp4 = bitcast sbyte* %tmp33.0 to %struct.edgeBox* ; <%struct.edgeBox*> [#uses=1]
%tmp255 = call int %comparee( %struct.edgeBox* %tmp3, %struct.edgeBox* %tmp4 ) ; <int> [#uses=1]
%tmp26 = setgt int %tmp255, 0 ; <bool> [#uses=1]
br bool %tmp26, label %cond_true27, label %bb30

cond_true27: ; preds = %bb
br label %bb30

bb30: ; preds = %cond_true27, %bb, %cond_next
%hi.0.3 = phi sbyte* [ %hi.0.0, %cond_true27 ], [ %hi.0.0, %bb ], [ undef, %cond_next ] ; <sbyte*> [#uses=0]
%j.1.3 = phi sbyte* [ %j.1.0, %cond_true27 ], [ %j.1.0, %bb ], [ undef, %cond_next ] ; <sbyte*> [#uses=0]
%tmp33.3 = phi sbyte* [ %tmp33.0, %cond_true27 ], [ %tmp33.0, %bb ], [ undef, %cond_next ] ; <sbyte*> [#uses=0]
%hi.0 = phi sbyte* [ %tmp9, %cond_next ], [ %hi.0.0, %bb ], [ %hi.0.0, %cond_true27 ] ; <sbyte*> [#uses=2]
%lo.1 = phi sbyte* [ %tmp33.0, %cond_true27 ], [ %tmp33.0, %bb ], [ %base, %cond_next ] ; <sbyte*> [#uses=1]
%j.1 = phi sbyte* [ %tmp33.0, %cond_true27 ], [ %j.1.0, %bb ], [ %base, %cond_next ] ; <sbyte*> [#uses=2]
%tmp31 = load int* %qsz ; <int> [#uses=1]
%tmp33 = getelementptr sbyte* %lo.1, int %tmp31 ; <sbyte*> [#uses=2]
%tmp36 = setlt sbyte* %tmp33, %hi.0 ; <bool> [#uses=1]
br bool %tmp36, label %bb, label %bb37

bb37: ; preds = %bb30, %cond_true12
%j.1.1 = phi sbyte* [ %j.1, %bb30 ], [ %base, %cond_true12 ] ; <sbyte*> [#uses=4]
%tmp40 = seteq sbyte* %j.1.1, %base ; <bool> [#uses=1]
br bool %tmp40, label %bb115, label %cond_true41

cond_true41: ; preds = %bb37
%tmp43 = load int* %qsz ; <int> [#uses=1]
%tmp45 = getelementptr sbyte* %base, int %tmp43 ; <sbyte*> [#uses=2]
%tmp6030 = setlt sbyte* %base, %tmp45 ; <bool> [#uses=1]
br bool %tmp6030, label %bb46, label %bb115

bb46: ; preds = %bb46, %cond_true41
%j.2.0 = phi sbyte* [ %j.1.1, %cond_true41 ], [ %tmp52, %bb46 ] ; <sbyte*> [#uses=3]
%i.2.0 = phi sbyte* [ %base, %cond_true41 ], [ %tmp56, %bb46 ] ; <sbyte*> [#uses=3]
%tmp = load sbyte* %j.2.0 ; <sbyte> [#uses=2]
%tmp49 = load sbyte* %i.2.0 ; <sbyte> [#uses=1]
store sbyte %tmp49, sbyte* %j.2.0
%tmp52 = getelementptr sbyte* %j.2.0, int 1 ; <sbyte*> [#uses=2]
store sbyte %tmp, sbyte* %i.2.0
%tmp56 = getelementptr sbyte* %i.2.0, int 1 ; <sbyte*> [#uses=3]
%tmp60 = setlt sbyte* %tmp56, %tmp45 ; <bool> [#uses=1]
br bool %tmp60, label %bb46, label %bb115

bb66: ; preds = %bb115, %bb66
%hi.3 = phi sbyte* [ %tmp118, %bb115 ], [ %tmp70, %bb66 ] ; <sbyte*> [#uses=2]
%tmp67 = load int* %qsz ; <int> [#uses=2]
%tmp68 = sub int 0, %tmp67 ; <int> [#uses=1]
%tmp70 = getelementptr sbyte* %hi.3, int %tmp68 ; <sbyte*> [#uses=2]
%tmp = bitcast sbyte* %tmp70 to %struct.edgeBox* ; <%struct.edgeBox*> [#uses=1]
%tmp1 = bitcast sbyte* %tmp118 to %struct.edgeBox* ; <%struct.edgeBox*> [#uses=1]
%tmp732 = call int %comparee( %struct.edgeBox* %tmp, %struct.edgeBox* %tmp1 ) ; <int> [#uses=1]
%tmp74 = setgt int %tmp732, 0 ; <bool> [#uses=1]
br bool %tmp74, label %bb66, label %bb75

bb75: ; preds = %bb66
%tmp76 = load int* %qsz ; <int> [#uses=1]
%tmp70.sum = sub int %tmp76, %tmp67 ; <int> [#uses=1]
%tmp78 = getelementptr sbyte* %hi.3, int %tmp70.sum ; <sbyte*> [#uses=3]
%tmp81 = seteq sbyte* %tmp78, %tmp118 ; <bool> [#uses=1]
br bool %tmp81, label %bb115, label %cond_true82

cond_true82: ; preds = %bb75
%tmp83 = load int* %qsz ; <int> [#uses=1]
%tmp118.sum = add int %tmp116, %tmp83 ; <int> [#uses=1]
%tmp85 = getelementptr sbyte* %min.1, int %tmp118.sum ; <sbyte*> [#uses=1]
%tmp10937 = getelementptr sbyte* %tmp85, int -1 ; <sbyte*> [#uses=3]
%tmp11239 = setlt sbyte* %tmp10937, %tmp118 ; <bool> [#uses=1]
br bool %tmp11239, label %bb115, label %bb86

bb86: ; preds = %bb104, %cond_true82
%tmp109.0 = phi sbyte* [ %tmp10937, %cond_true82 ], [ %tmp109, %bb104 ] ; <sbyte*> [#uses=5]
%i.5.2 = phi sbyte* [ %i.5.3, %cond_true82 ], [ %i.5.1, %bb104 ] ; <sbyte*> [#uses=0]
%tmp100.2 = phi sbyte* [ %tmp100.3, %cond_true82 ], [ %tmp100.1, %bb104 ] ; <sbyte*> [#uses=0]
%tmp88 = load sbyte* %tmp109.0 ; <sbyte> [#uses=2]
%tmp9746 = load int* %qsz ; <int> [#uses=1]
%tmp9847 = sub int 0, %tmp9746 ; <int> [#uses=1]
%tmp10048 = getelementptr sbyte* %tmp109.0, int %tmp9847 ; <sbyte*> [#uses=3]
%tmp10350 = setlt sbyte* %tmp10048, %tmp78 ; <bool> [#uses=1]
br bool %tmp10350, label %bb104, label %bb91

bb91: ; preds = %bb91, %bb86
%i.5.0 = phi sbyte* [ %tmp109.0, %bb86 ], [ %tmp100.0, %bb91 ] ; <sbyte*> [#uses=1]
%tmp100.0 = phi sbyte* [ %tmp10048, %bb86 ], [ %tmp100, %bb91 ] ; <sbyte*> [#uses=4]
%tmp93 = load sbyte* %tmp100.0 ; <sbyte> [#uses=1]
store sbyte %tmp93, sbyte* %i.5.0
%tmp97 = load int* %qsz ; <int> [#uses=1]
%tmp98 = sub int 0, %tmp97 ; <int> [#uses=1]
%tmp100 = getelementptr sbyte* %tmp100.0, int %tmp98 ; <sbyte*> [#uses=3]
%tmp103 = setlt sbyte* %tmp100, %tmp78 ; <bool> [#uses=1]
br bool %tmp103, label %bb104, label %bb91

bb104: ; preds = %bb91, %bb86
%i.5.1 = phi sbyte* [ %tmp109.0, %bb86 ], [ %tmp100.0, %bb91 ] ; <sbyte*> [#uses=4]
%tmp100.1 = phi sbyte* [ %tmp10048, %bb86 ], [ %tmp100, %bb91 ] ; <sbyte*> [#uses=3]
store sbyte %tmp88, sbyte* %i.5.1
%tmp109 = getelementptr sbyte* %tmp109.0, int -1 ; <sbyte*> [#uses=3]
%tmp112 = setlt sbyte* %tmp109, %tmp118 ; <bool> [#uses=1]
br bool %tmp112, label %bb115, label %bb86

bb115: ; preds = %bb104, %cond_true82, %bb75, %bb46, %cond_true41, %bb37
%tmp109.1 = phi sbyte* [ undef, %bb37 ], [ %tmp109.1, %bb75 ], [ %tmp10937, %cond_true82 ], [ %tmp109, %bb104 ], [ undef, %bb46 ], [ undef, %cond_true41 ] ; <sbyte*> [#uses=1]
%i.5.3 = phi sbyte* [ undef, %bb37 ], [ %i.5.3, %bb75 ], [ %i.5.3, %cond_true82 ], [ %i.5.1, %bb104 ], [ undef, %bb46 ], [ undef, %cond_true41 ] ; <sbyte*> [#uses=3]
%tmp100.3 = phi sbyte* [ undef, %bb37 ], [ %tmp100.3, %bb75 ], [ %tmp100.3, %cond_true82 ], [ %tmp100.1, %bb104 ], [ undef, %bb46 ], [ undef, %cond_true41 ] ; <sbyte*> [#uses=3]
%min.1 = phi sbyte* [ %tmp118, %bb104 ], [ %tmp118, %bb75 ], [ %base, %bb37 ], [ %base, %bb46 ], [ %base, %cond_true41 ], [ %tmp118, %cond_true82 ] ; <sbyte*> [#uses=2]
%j.5 = phi sbyte* [ %tmp100.1, %bb104 ], [ %j.5, %bb75 ], [ %tmp52, %bb46 ], [ %j.1.1, %bb37 ], [ %j.1.1, %cond_true41 ], [ %j.5, %cond_true82 ] ; <sbyte*> [#uses=2]
%i.4 = phi sbyte* [ %i.5.1, %bb104 ], [ %i.4, %bb75 ], [ %tmp56, %bb46 ], [ undef, %bb37 ], [ %base, %cond_true41 ], [ %i.4, %cond_true82 ] ; <sbyte*> [#uses=2]
%c.4 = phi sbyte [ %tmp88, %bb104 ], [ %c.4, %bb75 ], [ %tmp, %bb46 ], [ undef, %bb37 ], [ undef, %cond_true41 ], [ %c.4, %cond_true82 ] ; <sbyte> [#uses=2]
%tmp116 = load int* %qsz ; <int> [#uses=2]
%tmp118 = getelementptr sbyte* %min.1, int %tmp116 ; <sbyte*> [#uses=9]
%tmp122 = setlt sbyte* %tmp118, %tmp9 ; <bool> [#uses=1]
br bool %tmp122, label %bb66, label %return

return: ; preds = %bb115, %entry
ret int undef
}

declare int %qste(sbyte*, sbyte*)

declare int %comparee(%struct.edgeBox*, %struct.edgeBox*)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep 'icmp' | wc -l | grep 1
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep 'icmp ugt' | wc -l | grep 1
; ModuleID = 'bugpoint-tooptimize.bc'
target datalayout = "e-p:32:32"
target endian = little
target pointersize = 32
target triple = "i686-pc-linux-gnu"
%r = external global [17 x int] ; <[17 x int]*> [#uses=1]

implementation ; Functions:

bool %print_pgm_cond_true(int %tmp12.reload, int* %tmp16.out) {
newFuncRoot:
br label %cond_true

bb27.exitStub: ; preds = %cond_true
store int %tmp16, int* %tmp16.out
ret bool true

cond_next23.exitStub: ; preds = %cond_true
store int %tmp16, int* %tmp16.out
ret bool false

cond_true: ; preds = %newFuncRoot
%tmp15 = getelementptr [17 x int]* %r, int 0, int %tmp12.reload ; <int*> [#uses=1]
%tmp16 = load int* %tmp15 ; <int> [#uses=4]
%tmp18 = icmp slt int %tmp16, -31 ; <bool> [#uses=1]
%tmp21 = icmp sgt int %tmp16, 31 ; <bool> [#uses=1]
%bothcond = or bool %tmp18, %tmp21 ; <bool> [#uses=1]
br bool %bothcond, label %bb27.exitStub, label %cond_next23.exitStub
}

2 changes: 1 addition & 1 deletion llvm/test/Regression/Transforms/InstCombine/JavaCompare.ll
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; This is the sequence of stuff that the Java front-end expands for a single
; <= comparison. Check to make sure we turn it into a <= (only)

; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | grep -v 'setle'| not grep '#uses'
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | grep -v 'icmp sle'| not grep '#uses'

bool %le(int %A, int %B) {
%c1 = setgt int %A, %B;
Expand Down
11 changes: 6 additions & 5 deletions llvm/test/Regression/Transforms/InstCombine/cast.ll
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ bool %test14(sbyte %A) {
ret bool %X
}

bool %test15(ubyte %A) {
%c = cast ubyte %A to sbyte
%X = setlt sbyte %c, 0 ; setgt %A, 127
ret bool %X
}
; This just won't occur when there's no difference between ubyte and sbyte
;bool %test15(ubyte %A) {
; %c = cast ubyte %A to sbyte
; %X = setlt sbyte %c, 0 ; setgt %A, 127
; ret bool %X
;}

bool %test16(int* %P) {
%c = cast int* %P to bool ;; setne P, null
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Regression/Transforms/InstCombine/set.ll
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; This test makes sure that these instructions are properly eliminated.
;
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine -disable-output &&
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | not grep set
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | not grep icmp

%X = uninitialized global int

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
; into equivalent setne,eq instructions.
;

; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | grep -v seteq | grep -v setne | not grep set
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | grep -v 'icmp eq' | grep -v 'icmp ne' | not grep icmp

bool %test1(uint %A) {
%B = setge uint %A, 1 ; setne %A, 0
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; having overlapping live ranges that result in copies. We want the setcc instruction
; immediately before the conditional branch.
;
; RUN: llvm-upgrade < %s | llvm-as | opt -loop-reduce | llvm-dis | %prcontext 'br bool' 1 | grep set
; RUN: llvm-upgrade < %s | llvm-as | opt -loop-reduce | llvm-dis | %prcontext 'br bool' 1 | grep icmp

void %foo(float* %D, uint %E) {
entry:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
; RUN: llvm-as < %s | opt -simplifycfg | llvm-dis
; ModuleID = 'bugpoint-tooptimize.bc'
target datalayout = "e-p:32:32"
target endian = little
target pointersize = 32
target triple = "i686-pc-linux-gnu"
%struct.FILE = type { int, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, %struct._IO_marker*, %struct.FILE*, int, int, int, ushort, sbyte, [1 x sbyte], sbyte*, long, sbyte*, sbyte*, sbyte*, sbyte*, uint, int, [40 x sbyte] }
%struct._IO_FILE = type { int, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, %struct._IO_marker*, %struct.FILE*, int, int, int, ushort, sbyte, [1 x sbyte], sbyte*, long, sbyte*, sbyte*, sbyte*, sbyte*, uint, int, [40 x sbyte] }
%struct._IO_marker = type { %struct._IO_marker*, %struct.FILE*, int }
%struct.charsequence = type { sbyte*, uint, uint }
%struct.trie_s = type { [26 x %struct.trie_s*], int }
%str = external global [14 x sbyte] ; <[14 x sbyte]*> [#uses=0]
%str = external global [32 x sbyte] ; <[32 x sbyte]*> [#uses=0]
%str = external global [12 x sbyte] ; <[12 x sbyte]*> [#uses=0]
%C.0.2294 = external global %struct.charsequence ; <%struct.charsequence*> [#uses=3]
%t = external global %struct.trie_s* ; <%struct.trie_s**> [#uses=0]
%str = external global [3 x sbyte] ; <[3 x sbyte]*> [#uses=0]
%str = external global [26 x sbyte] ; <[26 x sbyte]*> [#uses=0]

implementation ; Functions:

declare void %charsequence_reset(%struct.charsequence*)
declare void %free(sbyte*)
declare void %charsequence_push(%struct.charsequence*, sbyte)
declare sbyte* %charsequence_val(%struct.charsequence*)
declare int %_IO_getc(%struct.FILE*)
declare int %tolower(int)
declare %struct.trie_s* %trie_insert(%struct.trie_s*, sbyte*)
declare int %feof(%struct.FILE*)

void %addfile(%struct.trie_s* %t, %struct.FILE* %f) {
entry:
%t_addr = alloca %struct.trie_s* ; <%struct.trie_s**> [#uses=2]
%f_addr = alloca %struct.FILE* ; <%struct.FILE**> [#uses=3]
%c = alloca sbyte, align 1 ; <sbyte*> [#uses=7]
%wstate = alloca int, align 4 ; <int*> [#uses=4]
%cs = alloca %struct.charsequence, align 16 ; <%struct.charsequence*> [#uses=7]
%str = alloca sbyte*, align 4 ; <sbyte**> [#uses=3]
"alloca point" = bitcast int 0 to int ; <int> [#uses=0]
store %struct.trie_s* %t, %struct.trie_s** %t_addr
store %struct.FILE* %f, %struct.FILE** %f_addr
store int 0, int* %wstate
%tmp = getelementptr %struct.charsequence* %cs, uint 0, uint 0 ; <sbyte**> [#uses=1]
%tmp1 = getelementptr %struct.charsequence* %C.0.2294, uint 0, uint 0 ; <sbyte**> [#uses=1]
%tmp = load sbyte** %tmp1 ; <sbyte*> [#uses=1]
store sbyte* %tmp, sbyte** %tmp
%tmp = getelementptr %struct.charsequence* %cs, uint 0, uint 1 ; <uint*> [#uses=1]
%tmp2 = getelementptr %struct.charsequence* %C.0.2294, uint 0, uint 1 ; <uint*> [#uses=1]
%tmp = load uint* %tmp2 ; <uint> [#uses=1]
store uint %tmp, uint* %tmp
%tmp3 = getelementptr %struct.charsequence* %cs, uint 0, uint 2 ; <uint*> [#uses=1]
%tmp4 = getelementptr %struct.charsequence* %C.0.2294, uint 0, uint 2 ; <uint*> [#uses=1]
%tmp5 = load uint* %tmp4 ; <uint> [#uses=1]
store uint %tmp5, uint* %tmp3
br label %bb33

bb: ; preds = %bb33
%tmp = load %struct.FILE** %f_addr ; <%struct.FILE*> [#uses=1]
%tmp = call int %_IO_getc( %struct.FILE* %tmp ) ; <int> [#uses=1]
%tmp6 = call int %tolower( int %tmp ) ; <int> [#uses=1]
%tmp6 = trunc int %tmp6 to sbyte ; <sbyte> [#uses=1]
store sbyte %tmp6, sbyte* %c
%tmp7 = load int* %wstate ; <int> [#uses=1]
%tmp = icmp ne int %tmp7, 0 ; <bool> [#uses=1]
br bool %tmp, label %cond_true, label %cond_false

cond_true: ; preds = %bb
%tmp = load sbyte* %c ; <sbyte> [#uses=1]
%tmp8 = icmp sle sbyte %tmp, 96 ; <bool> [#uses=1]
br bool %tmp8, label %cond_true9, label %cond_next

cond_true9: ; preds = %cond_true
br label %bb16

cond_next: ; preds = %cond_true
%tmp10 = load sbyte* %c ; <sbyte> [#uses=1]
%tmp11 = icmp sgt sbyte %tmp10, 122 ; <bool> [#uses=1]
br bool %tmp11, label %cond_true12, label %cond_next13

cond_true12: ; preds = %cond_next
br label %bb16

cond_next13: ; preds = %cond_next
%tmp14 = load sbyte* %c ; <sbyte> [#uses=1]
%tmp14 = sext sbyte %tmp14 to int ; <int> [#uses=1]
%tmp1415 = trunc int %tmp14 to sbyte ; <sbyte> [#uses=1]
call void %charsequence_push( %struct.charsequence* %cs, sbyte %tmp1415 )
br label %bb21

bb16: ; preds = %cond_true12, %cond_true9
%tmp17 = call sbyte* %charsequence_val( %struct.charsequence* %cs ) ; <sbyte*> [#uses=1]
store sbyte* %tmp17, sbyte** %str
%tmp = load %struct.trie_s** %t_addr ; <%struct.trie_s*> [#uses=1]
%tmp18 = load sbyte** %str ; <sbyte*> [#uses=1]
%tmp19 = call %struct.trie_s* %trie_insert( %struct.trie_s* %tmp, sbyte* %tmp18 ) ; <%struct.trie_s*> [#uses=0]
%tmp20 = load sbyte** %str ; <sbyte*> [#uses=1]
call void %free( sbyte* %tmp20 )
store int 0, int* %wstate
br label %bb21

bb21: ; preds = %bb16, %cond_next13
br label %cond_next32

cond_false: ; preds = %bb
%tmp22 = load sbyte* %c ; <sbyte> [#uses=1]
%tmp23 = icmp sgt sbyte %tmp22, 96 ; <bool> [#uses=1]
br bool %tmp23, label %cond_true24, label %cond_next31

cond_true24: ; preds = %cond_false
%tmp25 = load sbyte* %c ; <sbyte> [#uses=1]
%tmp26 = icmp sle sbyte %tmp25, 122 ; <bool> [#uses=1]
br bool %tmp26, label %cond_true27, label %cond_next30

cond_true27: ; preds = %cond_true24
call void %charsequence_reset( %struct.charsequence* %cs )
%tmp28 = load sbyte* %c ; <sbyte> [#uses=1]
%tmp28 = sext sbyte %tmp28 to int ; <int> [#uses=1]
%tmp2829 = trunc int %tmp28 to sbyte ; <sbyte> [#uses=1]
call void %charsequence_push( %struct.charsequence* %cs, sbyte %tmp2829 )
store int 1, int* %wstate
br label %cond_next30

cond_next30: ; preds = %cond_true27, %cond_true24
br label %cond_next31

cond_next31: ; preds = %cond_next30, %cond_false
br label %cond_next32

cond_next32: ; preds = %cond_next31, %bb21
br label %bb33

bb33: ; preds = %cond_next32, %entry
%tmp34 = load %struct.FILE** %f_addr ; <%struct.FILE*> [#uses=1]
%tmp35 = call int %feof( %struct.FILE* %tmp34 ) ; <int> [#uses=1]
%tmp36 = icmp eq int %tmp35, 0 ; <bool> [#uses=1]
br bool %tmp36, label %bb, label %bb37

bb37: ; preds = %bb33
br label %return

return: ; preds = %bb37
ret void
}

2 changes: 1 addition & 1 deletion llvm/test/Regression/Transforms/SimplifyCFG/DeadSetCC.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: llvm-upgrade < %s | llvm-as | opt -simplifycfg | llvm-dis | not grep seteq
; RUN: llvm-upgrade < %s | llvm-as | opt -simplifycfg | llvm-dis | not grep 'icmp eq'

; Check that simplifycfg deletes a dead 'seteq' instruction when it
; folds a conditional branch into a switch instruction.
Expand Down
4 changes: 2 additions & 2 deletions llvm/tools/bugpoint/Miscompilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,8 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,

// Check to see if we already looked up the value.
Value *CachedVal = new LoadInst(Cache, "fpcache", EntryBB);
Value *IsNull = new SetCondInst(Instruction::SetEQ, CachedVal,
NullPtr, "isNull", EntryBB);
Value *IsNull = new ICmpInst(ICmpInst::ICMP_EQ, CachedVal,
NullPtr, "isNull", EntryBB);
new BranchInst(LookupBB, DoCallBB, IsNull, EntryBB);

// Resolve the call to function F via the JIT API:
Expand Down
406 changes: 196 additions & 210 deletions llvm/tools/llvm-upgrade/UpgradeParser.cpp

Large diffs are not rendered by default.

406 changes: 196 additions & 210 deletions llvm/tools/llvm-upgrade/UpgradeParser.cpp.cvs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion llvm/tools/llvm-upgrade/UpgradeParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@


#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
#line 285 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
#line 275 "/proj/llvm/llvm-3/tools/llvm-upgrade/UpgradeParser.y"
typedef union YYSTYPE {
std::string* String;
TypeInfo Type;
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-upgrade/UpgradeParser.h.cvs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@


#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
#line 285 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
#line 275 "/proj/llvm/llvm-3/tools/llvm-upgrade/UpgradeParser.y"
typedef union YYSTYPE {
std::string* String;
TypeInfo Type;
Expand Down
18 changes: 2 additions & 16 deletions llvm/tools/llvm-upgrade/UpgradeParser.y
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#define YYERROR_VERBOSE 1
#define YYINCLUDED_STDLIB_H
#define YYDEBUG 1
#define UPGRADE_SETCOND_OPS 0
#define GENERATE_FCMP_INSTS 0

int yylex(); // declaration" of xxx warnings.
int yyparse();
Expand Down Expand Up @@ -194,11 +192,7 @@ static std::string getCastUpgrade(
// the original intent by replace the cast with a setne
const char* comparator = SrcTy.isPointer() ? ", null" :
(SrcTy.isFloatingPoint() ? ", 0.0" : ", 0");
#if UPGRADE_SETCOND_OPS
const char* compareOp = SrcTy.isFloatingPoint() ? "setne " : "icmp ne ";
#else
const char* compareOp = "setne";
#endif
const char* compareOp = SrcTy.isFloatingPoint() ? "fcmp one " : "icmp ne ";
if (isConst) {
Result = "(" + Source + comparator + ")";
Result = compareOp + Result;
Expand Down Expand Up @@ -254,16 +248,12 @@ getCompareOp(const std::string& setcc, const TypeInfo& TI) {
result[6] = cc1;
result[7] = cc2;
if (TI.isFloatingPoint()) {
#if GENERATE_FCMP_INSTS
result[0] = 'f';
result[5] = 'o'; // FIXME: Always map to ordered comparison ?
result[5] = 'o';
if (cc1 == 'n')
result[5] = 'u'; // NE maps to unordered
else
result[5] = 'o'; // everything else maps to ordered
#else
result = setcc;
#endif
} else if (TI.isIntegral() || TI.isPointer()) {
result[0] = 'i';
if ((cc1 == 'e' && cc2 == 'q') || (cc1 == 'n' && cc2 == 'e'))
Expand Down Expand Up @@ -679,9 +669,7 @@ ConstExpr: CastOps '(' ConstVal TO Types ')' {
$$ = $1;
}
| SetCondOps '(' ConstVal ',' ConstVal ')' {
#if UPGRADE_SETCOND_OPS
*$1 = getCompareOp(*$1, $3.type);
#endif
*$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
$3.destroy(); $5.destroy();
$$ = $1;
Expand Down Expand Up @@ -1205,9 +1193,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
$$ = $1;
}
| SetCondOps Types ValueRef ',' ValueRef {
#if UPGRADE_SETCOND_OPS
*$1 = getCompareOp(*$1, $2);
#endif
*$1 += " " + *$2.newTy + " " + *$3.val + ", " + *$5.val;
$2.destroy(); $3.destroy(); $5.destroy();
$$ = $1;
Expand Down
18 changes: 2 additions & 16 deletions llvm/tools/llvm-upgrade/UpgradeParser.y.cvs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#define YYERROR_VERBOSE 1
#define YYINCLUDED_STDLIB_H
#define YYDEBUG 1
#define UPGRADE_SETCOND_OPS 0
#define GENERATE_FCMP_INSTS 0

int yylex(); // declaration" of xxx warnings.
int yyparse();
Expand Down Expand Up @@ -194,11 +192,7 @@ static std::string getCastUpgrade(
// the original intent by replace the cast with a setne
const char* comparator = SrcTy.isPointer() ? ", null" :
(SrcTy.isFloatingPoint() ? ", 0.0" : ", 0");
#if UPGRADE_SETCOND_OPS
const char* compareOp = SrcTy.isFloatingPoint() ? "setne " : "icmp ne ";
#else
const char* compareOp = "setne";
#endif
const char* compareOp = SrcTy.isFloatingPoint() ? "fcmp one " : "icmp ne ";
if (isConst) {
Result = "(" + Source + comparator + ")";
Result = compareOp + Result;
Expand Down Expand Up @@ -254,16 +248,12 @@ getCompareOp(const std::string& setcc, const TypeInfo& TI) {
result[6] = cc1;
result[7] = cc2;
if (TI.isFloatingPoint()) {
#if GENERATE_FCMP_INSTS
result[0] = 'f';
result[5] = 'o'; // FIXME: Always map to ordered comparison ?
result[5] = 'o';
if (cc1 == 'n')
result[5] = 'u'; // NE maps to unordered
else
result[5] = 'o'; // everything else maps to ordered
#else
result = setcc;
#endif
} else if (TI.isIntegral() || TI.isPointer()) {
result[0] = 'i';
if ((cc1 == 'e' && cc2 == 'q') || (cc1 == 'n' && cc2 == 'e'))
Expand Down Expand Up @@ -679,9 +669,7 @@ ConstExpr: CastOps '(' ConstVal TO Types ')' {
$$ = $1;
}
| SetCondOps '(' ConstVal ',' ConstVal ')' {
#if UPGRADE_SETCOND_OPS
*$1 = getCompareOp(*$1, $3.type);
#endif
*$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
$3.destroy(); $5.destroy();
$$ = $1;
Expand Down Expand Up @@ -1205,9 +1193,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
$$ = $1;
}
| SetCondOps Types ValueRef ',' ValueRef {
#if UPGRADE_SETCOND_OPS
*$1 = getCompareOp(*$1, $2);
#endif
*$1 += " " + *$2.newTy + " " + *$3.val + ", " + *$5.val;
$2.destroy(); $3.destroy(); $5.destroy();
$$ = $1;
Expand Down
137 changes: 97 additions & 40 deletions llvm/tools/llvm2cpp/CppWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,31 +783,63 @@ void CppWriter::printConstant(const Constant *CV) {
}
Out << "Constant* " << constName << " = ConstantExpr::";
switch (CE->getOpcode()) {
case Instruction::Add: Out << "getAdd"; break;
case Instruction::Sub: Out << "getSub"; break;
case Instruction::Mul: Out << "getMul"; break;
case Instruction::UDiv: Out << "getUDiv"; break;
case Instruction::SDiv: Out << "getSDiv"; break;
case Instruction::FDiv: Out << "getFDiv"; break;
case Instruction::URem: Out << "getURem"; break;
case Instruction::SRem: Out << "getSRem"; break;
case Instruction::FRem: Out << "getFRem"; break;
case Instruction::And: Out << "getAnd"; break;
case Instruction::Or: Out << "getOr"; break;
case Instruction::Xor: Out << "getXor"; break;
case Instruction::SetEQ: Out << "getSetEQ"; break;
case Instruction::SetNE: Out << "getSetNE"; break;
case Instruction::SetLE: Out << "getSetLE"; break;
case Instruction::SetGE: Out << "getSetGE"; break;
case Instruction::SetLT: Out << "getSetLT"; break;
case Instruction::SetGT: Out << "getSetGT"; break;
case Instruction::Shl: Out << "getShl"; break;
case Instruction::LShr: Out << "getLShr"; break;
case Instruction::AShr: Out << "getAShr"; break;
case Instruction::Select: Out << "getSelect"; break;
case Instruction::ExtractElement: Out << "getExtractElement"; break;
case Instruction::InsertElement: Out << "getInsertElement"; break;
case Instruction::ShuffleVector: Out << "getShuffleVector"; break;
case Instruction::Add: Out << "getAdd("; break;
case Instruction::Sub: Out << "getSub("; break;
case Instruction::Mul: Out << "getMul("; break;
case Instruction::UDiv: Out << "getUDiv("; break;
case Instruction::SDiv: Out << "getSDiv("; break;
case Instruction::FDiv: Out << "getFDiv("; break;
case Instruction::URem: Out << "getURem("; break;
case Instruction::SRem: Out << "getSRem("; break;
case Instruction::FRem: Out << "getFRem("; break;
case Instruction::And: Out << "getAnd("; break;
case Instruction::Or: Out << "getOr("; break;
case Instruction::Xor: Out << "getXor("; break;
case Instruction::ICmp:
Out << "getICmp(ICmpInst::ICMP_";
switch (CE->getPredicate()) {
case ICmpInst::ICMP_EQ: Out << "EQ"; break;
case ICmpInst::ICMP_NE: Out << "NE"; break;
case ICmpInst::ICMP_SLT: Out << "SLT"; break;
case ICmpInst::ICMP_ULT: Out << "ULT"; break;
case ICmpInst::ICMP_SGT: Out << "SGT"; break;
case ICmpInst::ICMP_UGT: Out << "UGT"; break;
case ICmpInst::ICMP_SLE: Out << "SLE"; break;
case ICmpInst::ICMP_ULE: Out << "ULE"; break;
case ICmpInst::ICMP_SGE: Out << "SGE"; break;
case ICmpInst::ICMP_UGE: Out << "UGE"; break;
default: error("Invalid ICmp Predicate");
}
break;
case Instruction::FCmp:
Out << "getFCmp(FCmpInst::FCMP_";
switch (CE->getPredicate()) {
case FCmpInst::FCMP_FALSE: Out << "FALSE"; break;
case FCmpInst::FCMP_ORD: Out << "ORD"; break;
case FCmpInst::FCMP_UNO: Out << "UNO"; break;
case FCmpInst::FCMP_OEQ: Out << "OEQ"; break;
case FCmpInst::FCMP_UEQ: Out << "UEQ"; break;
case FCmpInst::FCMP_ONE: Out << "ONE"; break;
case FCmpInst::FCMP_UNE: Out << "UNE"; break;
case FCmpInst::FCMP_OLT: Out << "OLT"; break;
case FCmpInst::FCMP_ULT: Out << "ULT"; break;
case FCmpInst::FCMP_OGT: Out << "OGT"; break;
case FCmpInst::FCMP_UGT: Out << "UGT"; break;
case FCmpInst::FCMP_OLE: Out << "OLE"; break;
case FCmpInst::FCMP_ULE: Out << "ULE"; break;
case FCmpInst::FCMP_OGE: Out << "OGE"; break;
case FCmpInst::FCMP_UGE: Out << "UGE"; break;
case FCmpInst::FCMP_TRUE: Out << "TRUE"; break;
default: error("Invalid FCmp Predicate");
}
break;
case Instruction::Shl: Out << "getShl("; break;
case Instruction::LShr: Out << "getLShr("; break;
case Instruction::AShr: Out << "getAShr("; break;
case Instruction::Select: Out << "getSelect("; break;
case Instruction::ExtractElement: Out << "getExtractElement("; break;
case Instruction::InsertElement: Out << "getInsertElement("; break;
case Instruction::ShuffleVector: Out << "getShuffleVector("; break;
default:
error("Invalid constant expression");
break;
Expand Down Expand Up @@ -1075,21 +1107,46 @@ CppWriter::printInstruction(const Instruction *I, const std::string& bbname) {
Out << "\", " << bbname << ");";
break;
}
case Instruction::SetEQ:
case Instruction::SetNE:
case Instruction::SetLE:
case Instruction::SetGE:
case Instruction::SetLT:
case Instruction::SetGT: {
Out << "SetCondInst* " << iName << " = new SetCondInst(";
switch (I->getOpcode()) {
case Instruction::SetEQ: Out << "Instruction::SetEQ"; break;
case Instruction::SetNE: Out << "Instruction::SetNE"; break;
case Instruction::SetLE: Out << "Instruction::SetLE"; break;
case Instruction::SetGE: Out << "Instruction::SetGE"; break;
case Instruction::SetLT: Out << "Instruction::SetLT"; break;
case Instruction::SetGT: Out << "Instruction::SetGT"; break;
default: Out << "Instruction::BadOpCode"; break;
case Instruction::FCmp: {
Out << "FCmpInst* " << iName << " = new FCmpInst(";
switch (cast<FCmpInst>(I)->getPredicate()) {
case FCmpInst::FCMP_FALSE: Out << "FCmpInst::FCMP_FALSE"; break;
case FCmpInst::FCMP_OEQ : Out << "FCmpInst::FCMP_OEQ"; break;
case FCmpInst::FCMP_OGT : Out << "FCmpInst::FCMP_OGT"; break;
case FCmpInst::FCMP_OGE : Out << "FCmpInst::FCMP_OGE"; break;
case FCmpInst::FCMP_OLT : Out << "FCmpInst::FCMP_OLT"; break;
case FCmpInst::FCMP_OLE : Out << "FCmpInst::FCMP_OLE"; break;
case FCmpInst::FCMP_ONE : Out << "FCmpInst::FCMP_ONE"; break;
case FCmpInst::FCMP_ORD : Out << "FCmpInst::FCMP_ORD"; break;
case FCmpInst::FCMP_UNO : Out << "FCmpInst::FCMP_UNO"; break;
case FCmpInst::FCMP_UEQ : Out << "FCmpInst::FCMP_UEQ"; break;
case FCmpInst::FCMP_UGT : Out << "FCmpInst::FCMP_UGT"; break;
case FCmpInst::FCMP_UGE : Out << "FCmpInst::FCMP_UGE"; break;
case FCmpInst::FCMP_ULT : Out << "FCmpInst::FCMP_ULT"; break;
case FCmpInst::FCMP_ULE : Out << "FCmpInst::FCMP_ULE"; break;
case FCmpInst::FCMP_UNE : Out << "FCmpInst::FCMP_UNE"; break;
case FCmpInst::FCMP_TRUE : Out << "FCmpInst::FCMP_TRUE"; break;
default: Out << "FCmpInst::BAD_ICMP_PREDICATE"; break;
}
Out << ", " << opNames[0] << ", " << opNames[1] << ", \"";
printEscapedString(I->getName());
Out << "\", " << bbname << ");";
break;
}
case Instruction::ICmp: {
Out << "ICmpInst* " << iName << " = new ICmpInst(";
switch (cast<ICmpInst>(I)->getPredicate()) {
case ICmpInst::ICMP_EQ: Out << "ICmpInst::ICMP_EQ"; break;
case ICmpInst::ICMP_NE: Out << "ICmpInst::ICMP_NE"; break;
case ICmpInst::ICMP_ULE: Out << "ICmpInst::ICMP_ULE"; break;
case ICmpInst::ICMP_SLE: Out << "ICmpInst::ICMP_SLE"; break;
case ICmpInst::ICMP_UGE: Out << "ICmpInst::ICMP_UGE"; break;
case ICmpInst::ICMP_SGE: Out << "ICmpInst::ICMP_SGE"; break;
case ICmpInst::ICMP_ULT: Out << "ICmpInst::ICMP_ULT"; break;
case ICmpInst::ICMP_SLT: Out << "ICmpInst::ICMP_SLT"; break;
case ICmpInst::ICMP_UGT: Out << "ICmpInst::ICMP_UGT"; break;
case ICmpInst::ICMP_SGT: Out << "ICmpInst::ICMP_SGT"; break;
default: Out << "ICmpInst::BAD_ICMP_PREDICATE"; break;
}
Out << ", " << opNames[0] << ", " << opNames[1] << ", \"";
printEscapedString(I->getName());
Expand Down