Changes in directory llvm/lib/VMCore:
ConstantFolding.cpp updated: 1.93.2.7 -> 1.93.2.8 Constants.cpp updated: 1.163.2.8 -> 1.163.2.9 Instruction.cpp updated: 1.53.2.4 -> 1.53.2.5 Instructions.cpp updated: 1.42.2.5 -> 1.42.2.6 --- Log message: --- Diffs of the changes: (+75 -31) ConstantFolding.cpp | 78 +++++++++++++++++++++++++++++++++++++--------------- Constants.cpp | 18 ++++++++---- Instruction.cpp | 8 ++++- Instructions.cpp | 2 - 4 files changed, 75 insertions(+), 31 deletions(-) Index: llvm/lib/VMCore/ConstantFolding.cpp diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.93.2.7 llvm/lib/VMCore/ConstantFolding.cpp:1.93.2.8 --- llvm/lib/VMCore/ConstantFolding.cpp:1.93.2.7 Sun Oct 22 18:27:21 2006 +++ llvm/lib/VMCore/ConstantFolding.cpp Mon Oct 23 13:13:27 2006 @@ -40,10 +40,12 @@ 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 *urem(const Constant *V1, const Constant *V2) const = 0; + virtual Constant *srem(const Constant *V1, const Constant *V2) const = 0; + virtual Constant *frem(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 *fdiv(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; virtual Constant *op_xor(const Constant *V1, const Constant *V2) const = 0; @@ -114,11 +116,17 @@ virtual Constant *sdiv(const Constant *V1, const Constant *V2) const { return SubClassName::SDiv((const ArgType *)V1, (const ArgType *)V2); } + virtual Constant *urem(const Constant *V1, const Constant *V2) const { + return SubClassName::URem((const ArgType *)V1, (const ArgType *)V2); + } + virtual Constant *srem(const Constant *V1, const Constant *V2) const { + return SubClassName::SRem((const ArgType *)V1, (const ArgType *)V2); + } virtual Constant *fdiv(const Constant *V1, const Constant *V2) const { return SubClassName::FDiv((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); + virtual Constant *frem(const Constant *V1, const Constant *V2) const { + return SubClassName::FRem((const ArgType *)V1, (const ArgType *)V2); } virtual Constant *op_and(const Constant *V1, const Constant *V2) const { return SubClassName::And((const ArgType *)V1, (const ArgType *)V2); @@ -186,18 +194,20 @@ // 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 *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 *URem(const ArgType *V1, const ArgType *V2) { return 0; } + static Constant *SRem(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 *SDiv(const ArgType *V1, const ArgType *V2) { return 0; } static Constant *UDiv(const ArgType *V1, const ArgType *V2) { return 0; } static Constant *FDiv(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 *FRem(const ArgType *V1, const ArgType *V2) { return 0; } static Constant *LessThan(const ArgType *V1, const ArgType *V2) { return 0; } @@ -389,11 +399,17 @@ static Constant *SDiv(const ConstantPacked *V1, const ConstantPacked *V2) { return EvalVectorOp(V1, V2, ConstantExpr::getSDiv); } + static Constant *URem(const ConstantPacked *V1, const ConstantPacked *V2) { + return EvalVectorOp(V1, V2, ConstantExpr::getURem); + } + static Constant *SRem(const ConstantPacked *V1, const ConstantPacked *V2) { + return EvalVectorOp(V1, V2, ConstantExpr::getSRem); + } static Constant *FDiv(const ConstantPacked *V1, const ConstantPacked *V2) { return EvalVectorOp(V1, V2, ConstantExpr::getFDiv); } - static Constant *Rem(const ConstantPacked *V1, const ConstantPacked *V2) { - return EvalVectorOp(V1, V2, ConstantExpr::getRem); + static Constant *FRem(const ConstantPacked *V1, const ConstantPacked *V2) { + return EvalVectorOp(V1, V2, ConstantExpr::getFRem); } static Constant *And(const ConstantPacked *V1, const ConstantPacked *V2) { return EvalVectorOp(V1, V2, ConstantExpr::getAnd); @@ -520,6 +536,17 @@ return ConstantInt::get(*Ty, R); } + static Constant *URem(const ConstantInt *V1, + const ConstantInt *V2) { + if (V2->isNullValue()) return 0; // X / 0 + if (V2->isAllOnesValue() && // MIN_INT / -1 + (BuiltinType)V1->getZExtValue() == -(BuiltinType)V1->getZExtValue()) + return 0; + BuiltinType R = + (BuiltinType)V1->getZExtValue() % (BuiltinType)V2->getZExtValue(); + return ConstantInt::get(*Ty, R); + } + static Constant *SDiv(const ConstantInt *V1, const ConstantInt *V2) { if (V2->isNullValue()) return 0; @@ -531,14 +558,14 @@ return ConstantInt::get(*Ty, R); } - static Constant *Rem(const ConstantInt *V1, + static Constant *SRem(const ConstantInt *V1, const ConstantInt *V2) { if (V2->isNullValue()) return 0; // X / 0 if (V2->isAllOnesValue() && // MIN_INT / -1 - (BuiltinType)V1->getZExtValue() == -(BuiltinType)V1->getZExtValue()) + (BuiltinType)V1->getSExtValue() == -(BuiltinType)V1->getSExtValue()) return 0; BuiltinType R = - (BuiltinType)V1->getZExtValue() % (BuiltinType)V2->getZExtValue(); + (BuiltinType)V1->getSExtValue() % (BuiltinType)V2->getSExtValue(); return ConstantInt::get(*Ty, R); } @@ -637,7 +664,7 @@ DEF_CAST(Double, ConstantFP , double) #undef DEF_CAST - static Constant *Rem(const ConstantFP *V1, const ConstantFP *V2) { + static Constant *FRem(const ConstantFP *V1, const ConstantFP *V2) { if (V2->isNullValue()) return 0; BuiltinType Result = std::fmod((BuiltinType)V1->getValue(), (BuiltinType)V2->getValue()); @@ -1252,10 +1279,12 @@ 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::URem: C = ConstRules::get(V1, V2).urem(V1, V2); break; + case Instruction::SRem: C = ConstRules::get(V1, V2).srem(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::FDiv: C = ConstRules::get(V1, V2).fdiv(V1, V2); break; - case Instruction::Rem: C = ConstRules::get(V1, V2).rem(V1, V2); break; + case Instruction::FRem: C = ConstRules::get(V1, V2).frem(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; case Instruction::Xor: C = ConstRules::get(V1, V2).op_xor(V1, V2); break; @@ -1337,10 +1366,12 @@ case Instruction::Mul: case Instruction::And: return Constant::getNullValue(V1->getType()); + case Instruction::URem: + case Instruction::SRem: case Instruction::UDiv: case Instruction::SDiv: case Instruction::FDiv: - case Instruction::Rem: + case Instruction::FRem: if (!isa<UndefValue>(V2)) // undef/X -> 0 return Constant::getNullValue(V1->getType()); return const_cast<Constant*>(V2); // X/undef -> undef @@ -1396,7 +1427,8 @@ if (CI->getZExtValue() == 1) return const_cast<Constant*>(V1); // X / 1 == X break; - case Instruction::Rem: + case Instruction::URem: + case Instruction::SRem: if (const ConstantInt *CI = dyn_cast<ConstantInt>(V2)) if (CI->getZExtValue() == 1) return Constant::getNullValue(CI->getType()); // X % 1 == 0 @@ -1452,10 +1484,12 @@ case Instruction::Shl: case Instruction::Shr: case Instruction::Sub: + case Instruction::URem: + case Instruction::SRem: case Instruction::SDiv: case Instruction::UDiv: case Instruction::FDiv: - case Instruction::Rem: + case Instruction::FRem: default: // These instructions cannot be flopped around. break; } Index: llvm/lib/VMCore/Constants.cpp diff -u llvm/lib/VMCore/Constants.cpp:1.163.2.8 llvm/lib/VMCore/Constants.cpp:1.163.2.9 --- llvm/lib/VMCore/Constants.cpp:1.163.2.8 Sun Oct 22 03:59:01 2006 +++ llvm/lib/VMCore/Constants.cpp Mon Oct 23 13:13:27 2006 @@ -425,11 +425,17 @@ Constant *ConstantExpr::getSDiv(Constant *C1, Constant *C2) { return get(Instruction::SDiv, C1, C2); } +Constant *ConstantExpr::getURem(Constant *C1, Constant *C2) { + return get(Instruction::URem, C1, C2); +} +Constant *ConstantExpr::getSRem(Constant *C1, Constant *C2) { + return get(Instruction::SRem, C1, C2); +} Constant *ConstantExpr::getFDiv(Constant *C1, Constant *C2) { return get(Instruction::FDiv, C1, C2); } -Constant *ConstantExpr::getRem(Constant *C1, Constant *C2) { - return get(Instruction::Rem, C1, C2); +Constant *ConstantExpr::getFRem(Constant *C1, Constant *C2) { + return get(Instruction::FRem, C1, C2); } Constant *ConstantExpr::getAnd(Constant *C1, Constant *C2) { return get(Instruction::And, C1, C2); @@ -1310,7 +1316,7 @@ break; default: assert(OldC->getOpcode() >= Instruction::BinaryOpsBegin && - OldC->getOpcode() < Instruction::BinaryOpsEnd); + OldC->getOpcode() < Instruction::BinaryOpsEnd); New = ConstantExpr::getTy(NewTy, OldC->getOpcode(), OldC->getOperand(0), OldC->getOperand(1)); break; @@ -1396,8 +1402,8 @@ if (Opcode == Instruction::Shl || Opcode == Instruction::Shr) return getShiftTy(ReqTy, Opcode, C1, C2); // Check the operands for consistency first - assert((Opcode >= Instruction::BinaryOpsBegin && - Opcode < Instruction::BinaryOpsEnd) && + assert(Opcode >= Instruction::BinaryOpsBegin && + Opcode < Instruction::BinaryOpsEnd && "Invalid opcode in binary constant expression"); assert(C1->getType() == C2->getType() && "Operand types in binary constant expression should match"); @@ -1416,9 +1422,9 @@ #ifndef NDEBUG switch (Opcode) { case Instruction::Add: case Instruction::Sub: + case Instruction::URem: case Instruction::SRem: case Instruction::FRem: case Instruction::Mul: case Instruction::UDiv: case Instruction::SDiv: case Instruction::FDiv: - case Instruction::Rem: assert(C1->getType() == C2->getType() && "Op types should be identical!"); assert((C1->getType()->isInteger() || C1->getType()->isFloatingPoint() || isa<PackedType>(C1->getType())) && Index: llvm/lib/VMCore/Instruction.cpp diff -u llvm/lib/VMCore/Instruction.cpp:1.53.2.4 llvm/lib/VMCore/Instruction.cpp:1.53.2.5 --- llvm/lib/VMCore/Instruction.cpp:1.53.2.4 Sun Oct 22 03:59:01 2006 +++ llvm/lib/VMCore/Instruction.cpp Mon Oct 23 13:13:27 2006 @@ -94,10 +94,12 @@ case Add: return "add"; case Sub: return "sub"; case Mul: return "mul"; + case URem: return "urem"; + case SRem: return "srem"; case UDiv: return "udiv"; case SDiv: return "sdiv"; case FDiv: return "fdiv"; - case Rem: return "rem"; + case FRem: return "frem"; // Logical operators... case And: return "and"; @@ -223,10 +225,12 @@ /// bool Instruction::isTrapping(unsigned op) { switch(op) { + case URem: + case SRem: case UDiv: case SDiv: case FDiv: - case Rem: + case FRem: case Load: case Store: case Call: Index: llvm/lib/VMCore/Instructions.cpp diff -u llvm/lib/VMCore/Instructions.cpp:1.42.2.5 llvm/lib/VMCore/Instructions.cpp:1.42.2.6 --- llvm/lib/VMCore/Instructions.cpp:1.42.2.5 Sun Oct 22 03:59:01 2006 +++ llvm/lib/VMCore/Instructions.cpp Mon Oct 23 13:13:27 2006 @@ -1022,8 +1022,8 @@ #ifndef NDEBUG switch (iType) { case Add: case Sub: + case URem: case SRem: case FRem: case Mul: case UDiv: case SDiv: case FDiv: - case Rem: assert(getType() == LHS->getType() && "Arithmetic operation should return same type as operands!"); assert((getType()->isInteger() || getType()->isFloatingPoint() || _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits