Changes in directory llvm/lib/VMCore:
ConstantFolding.cpp updated: 1.93.2.3 -> 1.93.2.4 Constants.cpp updated: 1.163.2.3 -> 1.163.2.4 Instruction.cpp updated: 1.53.2.2 -> 1.53.2.3 Instructions.cpp updated: 1.42.2.3 -> 1.42.2.4 --- Log message: Initial patch for DIV -> SDIV/UDIV --- Diffs of the changes: (+64 -28) ConstantFolding.cpp | 75 ++++++++++++++++++++++++++++++++++++---------------- Constants.cpp | 9 ++++-- Instruction.cpp | 6 ++-- Instructions.cpp | 2 - 4 files changed, 64 insertions(+), 28 deletions(-) Index: llvm/lib/VMCore/ConstantFolding.cpp diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.93.2.3 llvm/lib/VMCore/ConstantFolding.cpp:1.93.2.4 --- llvm/lib/VMCore/ConstantFolding.cpp:1.93.2.3 Thu Oct 19 19:34:44 2006 +++ llvm/lib/VMCore/ConstantFolding.cpp Thu Oct 19 23:27:18 2006 @@ -40,7 +40,8 @@ virtual Constant *add(const Constant *V1, const Constant *V2) const = 0; virtual Constant *sub(const Constant *V1, const Constant *V2) const = 0; virtual Constant *mul(const Constant *V1, const Constant *V2) const = 0; - virtual Constant *div(const Constant *V1, const Constant *V2) const = 0; + virtual Constant *udiv(const Constant *V1, const Constant *V2) const = 0; + virtual Constant *sdiv(const Constant *V1, const Constant *V2) const = 0; virtual Constant *rem(const Constant *V1, const Constant *V2) const = 0; virtual Constant *op_and(const Constant *V1, const Constant *V2) const = 0; virtual Constant *op_or (const Constant *V1, const Constant *V2) const = 0; @@ -106,8 +107,11 @@ virtual Constant *mul(const Constant *V1, const Constant *V2) const { return SubClassName::Mul((const ArgType *)V1, (const ArgType *)V2); } - virtual Constant *div(const Constant *V1, const Constant *V2) const { - return SubClassName::Div((const ArgType *)V1, (const ArgType *)V2); + virtual Constant *udiv(const Constant *V1, const Constant *V2) const { + return SubClassName::UDiv((const ArgType *)V1, (const ArgType *)V2); + } + virtual Constant *sdiv(const Constant *V1, const Constant *V2) const { + return SubClassName::SDiv((const ArgType *)V1, (const ArgType *)V2); } virtual Constant *rem(const Constant *V1, const Constant *V2) const { return SubClassName::Rem((const ArgType *)V1, (const ArgType *)V2); @@ -178,16 +182,17 @@ // Default "noop" implementations //===--------------------------------------------------------------------===// - static Constant *Add(const ArgType *V1, const ArgType *V2) { return 0; } - static Constant *Sub(const ArgType *V1, const ArgType *V2) { return 0; } - static Constant *Mul(const ArgType *V1, const ArgType *V2) { return 0; } - static Constant *Div(const ArgType *V1, const ArgType *V2) { return 0; } - static Constant *Rem(const ArgType *V1, const ArgType *V2) { return 0; } - static Constant *And(const ArgType *V1, const ArgType *V2) { return 0; } - static Constant *Or (const ArgType *V1, const ArgType *V2) { return 0; } - static Constant *Xor(const ArgType *V1, const ArgType *V2) { return 0; } - static Constant *Shl(const ArgType *V1, const ArgType *V2) { return 0; } - static Constant *Shr(const ArgType *V1, const ArgType *V2) { return 0; } + static Constant *Add (const ArgType *V1, const ArgType *V2) { return 0; } + static Constant *Sub (const ArgType *V1, const ArgType *V2) { return 0; } + static Constant *Mul (const ArgType *V1, const ArgType *V2) { return 0; } + static Constant *SDiv(const ArgType *V1, const ArgType *V2) { return 0; } + static Constant *UDiv(const ArgType *V1, const ArgType *V2) { return 0; } + static Constant *Rem (const ArgType *V1, const ArgType *V2) { return 0; } + static Constant *And (const ArgType *V1, const ArgType *V2) { return 0; } + static Constant *Or (const ArgType *V1, const ArgType *V2) { return 0; } + static Constant *Xor (const ArgType *V1, const ArgType *V2) { return 0; } + static Constant *Shl (const ArgType *V1, const ArgType *V2) { return 0; } + static Constant *Shr (const ArgType *V1, const ArgType *V2) { return 0; } static Constant *LessThan(const ArgType *V1, const ArgType *V2) { return 0; } @@ -373,8 +378,11 @@ static Constant *Mul(const ConstantPacked *V1, const ConstantPacked *V2) { return EvalVectorOp(V1, V2, ConstantExpr::getMul); } - static Constant *Div(const ConstantPacked *V1, const ConstantPacked *V2) { - return EvalVectorOp(V1, V2, ConstantExpr::getDiv); + static Constant *UDiv(const ConstantPacked *V1, const ConstantPacked *V2) { + return EvalVectorOp(V1, V2, ConstantExpr::getUDiv); + } + static Constant *SDiv(const ConstantPacked *V1, const ConstantPacked *V2) { + return EvalVectorOp(V1, V2, ConstantExpr::getSDiv); } static Constant *Rem(const ConstantPacked *V1, const ConstantPacked *V2) { return EvalVectorOp(V1, V2, ConstantExpr::getRem); @@ -493,8 +501,20 @@ DEF_CAST(Double, ConstantFP , double) #undef DEF_CAST - static Constant *Div(const ConstantInt *V1, const ConstantInt *V2) { - if (V2->isNullValue()) return 0; + static Constant *UDiv(const ConstantInt *V1, const ConstantInt *V2) { + if (V2->isNullValue()) + return 0; + if (V2->isAllOnesValue() && // MIN_INT / -1 + (BuiltinType)V1->getRawValue() == -(BuiltinType)V1->getRawValue()) + return 0; + BuiltinType R = + (BuiltinType)V1->getRawValue() / (BuiltinType)V2->getRawValue(); + return ConstantInt::get(*Ty, R); + } + + static Constant *SDiv(const ConstantInt *V1, const ConstantInt *V2) { + if (V2->isNullValue()) + return 0; if (V2->isAllOnesValue() && // MIN_INT / -1 (BuiltinType)V1->getZExtValue() == -(BuiltinType)V1->getZExtValue()) return 0; @@ -615,7 +635,14 @@ (BuiltinType)V2->getValue()); return ConstantFP::get(*Ty, Result); } - static Constant *Div(const ConstantFP *V1, const ConstantFP *V2) { + static Constant *UDiv(const ConstantFP *V1, const ConstantFP *V2) { + BuiltinType inf = std::numeric_limits<BuiltinType>::infinity(); + if (V2->isExactlyValue(0.0)) return ConstantFP::get(*Ty, inf); + if (V2->isExactlyValue(-0.0)) return ConstantFP::get(*Ty, -inf); + BuiltinType R = (BuiltinType)V1->getValue() / (BuiltinType)V2->getValue(); + return ConstantFP::get(*Ty, R); + } + static Constant *SDiv(const ConstantFP *V1, const ConstantFP *V2) { BuiltinType inf = std::numeric_limits<BuiltinType>::infinity(); if (V2->isExactlyValue(0.0)) return ConstantFP::get(*Ty, inf); if (V2->isExactlyValue(-0.0)) return ConstantFP::get(*Ty, -inf); @@ -1224,7 +1251,8 @@ case Instruction::Add: C = ConstRules::get(V1, V2).add(V1, V2); break; case Instruction::Sub: C = ConstRules::get(V1, V2).sub(V1, V2); break; case Instruction::Mul: C = ConstRules::get(V1, V2).mul(V1, V2); break; - case Instruction::Div: C = ConstRules::get(V1, V2).div(V1, V2); break; + case Instruction::UDiv: C = ConstRules::get(V1, V2).udiv(V1, V2); break; + case Instruction::SDiv: C = ConstRules::get(V1, V2).sdiv(V1, V2); break; case Instruction::Rem: C = ConstRules::get(V1, V2).rem(V1, V2); break; case Instruction::And: C = ConstRules::get(V1, V2).op_and(V1, V2); break; case Instruction::Or: C = ConstRules::get(V1, V2).op_or (V1, V2); break; @@ -1307,7 +1335,8 @@ case Instruction::Mul: case Instruction::And: return Constant::getNullValue(V1->getType()); - case Instruction::Div: + case Instruction::UDiv: + case Instruction::SDiv: case Instruction::Rem: if (!isa<UndefValue>(V2)) // undef/X -> 0 return Constant::getNullValue(V1->getType()); @@ -1358,7 +1387,8 @@ if (CI->getZExtValue() == 1) return const_cast<Constant*>(V1); // X * 1 == X break; - case Instruction::Div: + case Instruction::UDiv: + case Instruction::SDiv: if (const ConstantInt *CI = dyn_cast<ConstantInt>(V2)) if (CI->getZExtValue() == 1) return const_cast<Constant*>(V1); // X / 1 == X @@ -1419,7 +1449,8 @@ case Instruction::Shl: case Instruction::Shr: case Instruction::Sub: - case Instruction::Div: + case Instruction::SDiv: + case Instruction::UDiv: case Instruction::Rem: default: // These instructions cannot be flopped around. break; Index: llvm/lib/VMCore/Constants.cpp diff -u llvm/lib/VMCore/Constants.cpp:1.163.2.3 llvm/lib/VMCore/Constants.cpp:1.163.2.4 --- llvm/lib/VMCore/Constants.cpp:1.163.2.3 Thu Oct 19 19:34:44 2006 +++ llvm/lib/VMCore/Constants.cpp Thu Oct 19 23:27:18 2006 @@ -420,8 +420,11 @@ Constant *ConstantExpr::getMul(Constant *C1, Constant *C2) { return get(Instruction::Mul, C1, C2); } -Constant *ConstantExpr::getDiv(Constant *C1, Constant *C2) { - return get(Instruction::Div, C1, C2); +Constant *ConstantExpr::getUDiv(Constant *C1, Constant *C2) { + return get(Instruction::UDiv, C1, C2); +} +Constant *ConstantExpr::getSDiv(Constant *C1, Constant *C2) { + return get(Instruction::SDiv, C1, C2); } Constant *ConstantExpr::getRem(Constant *C1, Constant *C2) { return get(Instruction::Rem, C1, C2); @@ -1437,7 +1440,7 @@ #ifndef NDEBUG switch (Opcode) { case Instruction::Add: case Instruction::Sub: - case Instruction::Mul: case Instruction::Div: + case Instruction::Mul: case Instruction::UDiv: case Instruction::SDiv: case Instruction::Rem: assert(C1->getType() == C2->getType() && "Op types should be identical!"); assert((C1->getType()->isInteger() || C1->getType()->isFloatingPoint() || Index: llvm/lib/VMCore/Instruction.cpp diff -u llvm/lib/VMCore/Instruction.cpp:1.53.2.2 llvm/lib/VMCore/Instruction.cpp:1.53.2.3 --- llvm/lib/VMCore/Instruction.cpp:1.53.2.2 Thu Oct 19 19:34:44 2006 +++ llvm/lib/VMCore/Instruction.cpp Thu Oct 19 23:27:18 2006 @@ -94,7 +94,8 @@ case Add: return "add"; case Sub: return "sub"; case Mul: return "mul"; - case Div: return "div"; + case UDiv: return "udiv"; + case SDiv: return "sdiv"; case Rem: return "rem"; // Logical operators... @@ -221,7 +222,8 @@ /// bool Instruction::isTrapping(unsigned op) { switch(op) { - case Div: + case SDiv: + case UDiv: case Rem: case Load: case Store: Index: llvm/lib/VMCore/Instructions.cpp diff -u llvm/lib/VMCore/Instructions.cpp:1.42.2.3 llvm/lib/VMCore/Instructions.cpp:1.42.2.4 --- llvm/lib/VMCore/Instructions.cpp:1.42.2.3 Thu Oct 19 19:34:44 2006 +++ llvm/lib/VMCore/Instructions.cpp Thu Oct 19 23:27:18 2006 @@ -1022,7 +1022,7 @@ #ifndef NDEBUG switch (iType) { case Add: case Sub: - case Mul: case Div: + case Mul: case UDiv: case SDiv: case Rem: assert(getType() == LHS->getType() && "Arithmetic operation should return same type as operands!"); _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits