Don't rewrite ConstantExpr::get.

llvm-svn: 30552
This commit is contained in:
Nick Lewycky 2006-09-21 01:05:35 +00:00
parent d74c55f483
commit fde9c308b2
1 changed files with 19 additions and 43 deletions

View File

@ -524,66 +524,42 @@ Value *PredicateSimplifier::resolve(SetCondInst *SCI,
const PropertySet &KP) { const PropertySet &KP) {
// Attempt to resolve the SetCondInst to a boolean. // Attempt to resolve the SetCondInst to a boolean.
static ConstantBool *True = ConstantBool::True,
*False = ConstantBool::False;
Value *SCI0 = resolve(SCI->getOperand(0), KP), Value *SCI0 = resolve(SCI->getOperand(0), KP),
*SCI1 = resolve(SCI->getOperand(1), KP); *SCI1 = resolve(SCI->getOperand(1), KP);
ConstantIntegral *CI1 = dyn_cast<ConstantIntegral>(SCI0), PropertySet::ConstPropertyIterator NE =
*CI2 = dyn_cast<ConstantIntegral>(SCI1); KP.findProperty(PropertySet::NE, SCI0, SCI1);
if (!CI1 || !CI2) { if (NE != KP.Properties.end()) {
PropertySet::ConstPropertyIterator NE = switch (SCI->getOpcode()) {
KP.findProperty(PropertySet::NE, SCI0, SCI1); case Instruction::SetEQ: return ConstantBool::False;
case Instruction::SetNE: return ConstantBool::True;
if (NE != KP.Properties.end()) { case Instruction::SetLE:
switch (SCI->getOpcode()) { case Instruction::SetGE:
case Instruction::SetEQ: return False; case Instruction::SetLT:
case Instruction::SetNE: return True; case Instruction::SetGT:
case Instruction::SetLE: break;
case Instruction::SetGE: default:
case Instruction::SetLT: assert(0 && "Unknown opcode in SetCondInst.");
case Instruction::SetGT: break;
break;
default:
assert(0 && "Unknown opcode in SetCondInst.");
break;
}
} }
return SCI;
} }
uint64_t I1 = CI1->getRawValue(), I2 = CI2->getRawValue();
switch(SCI->getOpcode()) {
case Instruction::SetLE: if (I1 <= I2) return True; else return False;
case Instruction::SetGE: if (I1 >= I2) return True; else return False;
case Instruction::SetEQ: if (I1 == I2) return True; else return False;
case Instruction::SetLT: if (I1 < I2) return True; else return False;
case Instruction::SetGT: if (I1 > I2) return True; else return False;
case Instruction::SetNE: if (I1 != I2) return True; else return False;
default:
assert(0 && "Unknown opcode in SetContInst.");
break;
}
return SCI; return SCI;
} }
Value *PredicateSimplifier::resolve(BinaryOperator *BO, Value *PredicateSimplifier::resolve(BinaryOperator *BO,
const PropertySet &KP) { const PropertySet &KP) {
if (SetCondInst *SCI = dyn_cast<SetCondInst>(BO))
return resolve(SCI, KP);
Value *lhs = resolve(BO->getOperand(0), KP), Value *lhs = resolve(BO->getOperand(0), KP),
*rhs = resolve(BO->getOperand(1), KP); *rhs = resolve(BO->getOperand(1), KP);
ConstantIntegral *CI1 = dyn_cast<ConstantIntegral>(lhs); ConstantIntegral *CI1 = dyn_cast<ConstantIntegral>(lhs);
ConstantIntegral *CI2 = dyn_cast<ConstantIntegral>(rhs); ConstantIntegral *CI2 = dyn_cast<ConstantIntegral>(rhs);
if (!CI1 || !CI2) return BO; if (CI1 && CI2) return ConstantExpr::get(BO->getOpcode(), CI1, CI2);
if (SetCondInst *SCI = dyn_cast<SetCondInst>(BO))
return resolve(SCI, KP);
Value *V = ConstantExpr::get(BO->getOpcode(), CI1, CI2);
if (V) return V;
return BO; return BO;
} }