Fix Bug: ConstProp/2003-05-12-DivideError.ll

llvm-svn: 6125
This commit is contained in:
Chris Lattner 2003-05-12 15:26:25 +00:00
parent 007c69ddf8
commit 26891626fc
1 changed files with 13 additions and 1 deletions

View File

@ -461,9 +461,21 @@ struct DirectIntRules
: public DirectRules<ConstantClass, BuiltinType, Ty,
DirectIntRules<ConstantClass, BuiltinType, Ty> > {
static Constant *Div(const ConstantClass *V1, const ConstantClass *V2) {
if (V2->isNullValue()) return 0;
if (V2->isAllOnesValue() && // MIN_INT / -1
(BuiltinType)V1->getValue() == -(BuiltinType)V1->getValue())
return 0;
BuiltinType R = (BuiltinType)V1->getValue() / (BuiltinType)V2->getValue();
return ConstantClass::get(*Ty, R);
}
static Constant *Rem(const ConstantClass *V1,
const ConstantClass *V2) {
if (V2->isNullValue()) return 0;
if (V2->isNullValue()) return 0; // X / 0
if (V2->isAllOnesValue() && // MIN_INT / -1
(BuiltinType)V1->getValue() == -(BuiltinType)V1->getValue())
return 0;
BuiltinType R = (BuiltinType)V1->getValue() % (BuiltinType)V2->getValue();
return ConstantClass::get(*Ty, R);
}