Changes in directory llvm/lib/VMCore:
ConstantFolding.cpp updated: 1.97 -> 1.98 Constants.cpp updated: 1.169 -> 1.170 Instruction.cpp updated: 1.56 -> 1.57 Instructions.cpp updated: 1.45 -> 1.46 --- Log message: For PR950: http://llvm.org/PR950 : This patch converts the old SHR instruction into two instructions, AShr (Arithmetic) and LShr (Logical). The Shr instructions now are not dependent on the sign of their operands. --- Diffs of the changes: (+52 -61) ConstantFolding.cpp | 62 +++++++++++++++++++++++++++------------------------- Constants.cpp | 37 ++++++++++++++----------------- Instruction.cpp | 3 +- Instructions.cpp | 11 --------- 4 files changed, 52 insertions(+), 61 deletions(-) Index: llvm/lib/VMCore/ConstantFolding.cpp diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.97 llvm/lib/VMCore/ConstantFolding.cpp:1.98 --- llvm/lib/VMCore/ConstantFolding.cpp:1.97 Thu Nov 2 02:18:15 2006 +++ llvm/lib/VMCore/ConstantFolding.cpp Wed Nov 8 00:47:33 2006 @@ -50,7 +50,8 @@ virtual Constant *op_or (const Constant *V1, const Constant *V2) const = 0; virtual Constant *op_xor(const Constant *V1, const Constant *V2) const = 0; virtual Constant *shl(const Constant *V1, const Constant *V2) const = 0; - virtual Constant *shr(const Constant *V1, const Constant *V2) const = 0; + virtual Constant *lshr(const Constant *V1, const Constant *V2) const = 0; + virtual Constant *ashr(const Constant *V1, const Constant *V2) const = 0; virtual Constant *lessthan(const Constant *V1, const Constant *V2) const =0; virtual Constant *equalto(const Constant *V1, const Constant *V2) const = 0; @@ -140,8 +141,11 @@ virtual Constant *shl(const Constant *V1, const Constant *V2) const { return SubClassName::Shl((const ArgType *)V1, (const ArgType *)V2); } - virtual Constant *shr(const Constant *V1, const Constant *V2) const { - return SubClassName::Shr((const ArgType *)V1, (const ArgType *)V2); + virtual Constant *lshr(const Constant *V1, const Constant *V2) const { + return SubClassName::LShr((const ArgType *)V1, (const ArgType *)V2); + } + virtual Constant *ashr(const Constant *V1, const Constant *V2) const { + return SubClassName::AShr((const ArgType *)V1, (const ArgType *)V2); } virtual Constant *lessthan(const Constant *V1, const Constant *V2) const { @@ -207,7 +211,8 @@ 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 *LShr(const ArgType *V1, const ArgType *V2) { return 0; } + static Constant *AShr(const ArgType *V1, const ArgType *V2) { return 0; } static Constant *LessThan(const ArgType *V1, const ArgType *V2) { return 0; } @@ -420,12 +425,6 @@ static Constant *Xor(const ConstantPacked *V1, const ConstantPacked *V2) { return EvalVectorOp(V1, V2, ConstantExpr::getXor); } - static Constant *Shl(const ConstantPacked *V1, const ConstantPacked *V2) { - return EvalVectorOp(V1, V2, ConstantExpr::getShl); - } - static Constant *Shr(const ConstantPacked *V1, const ConstantPacked *V2) { - return EvalVectorOp(V1, V2, ConstantExpr::getShr); - } static Constant *LessThan(const ConstantPacked *V1, const ConstantPacked *V2){ return 0; } @@ -581,9 +580,13 @@ return ConstantInt::get(*Ty, R); } - static Constant *Shr(const ConstantInt *V1, const ConstantInt *V2) { - BuiltinType R = - (BuiltinType)V1->getZExtValue() >> (BuiltinType)V2->getZExtValue(); + static Constant *LShr(const ConstantInt *V1, const ConstantInt *V2) { + BuiltinType R = BuiltinType(V1->getZExtValue() >> V2->getZExtValue()); + return ConstantInt::get(*Ty, R); + } + + static Constant *AShr(const ConstantInt *V1, const ConstantInt *V2) { + BuiltinType R = BuiltinType(V1->getSExtValue() >> V2->getZExtValue()); return ConstantInt::get(*Ty, R); } }; @@ -1278,7 +1281,8 @@ 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; case Instruction::Shl: C = ConstRules::get(V1, V2).shl(V1, V2); break; - case Instruction::Shr: C = ConstRules::get(V1, V2).shr(V1, V2); break; + case Instruction::LShr: C = ConstRules::get(V1, V2).lshr(V1, V2); break; + case Instruction::AShr: C = ConstRules::get(V1, V2).ashr(V1, V2); break; case Instruction::SetEQ: C = ConstRules::get(V1, V2).equalto(V1, V2); break; case Instruction::SetLT: C = ConstRules::get(V1, V2).lessthan(V1, V2);break; case Instruction::SetGT: C = ConstRules::get(V1, V2).lessthan(V2, V1);break; @@ -1366,21 +1370,20 @@ return const_cast<Constant*>(V2); // X / undef -> undef case Instruction::Or: // X | undef -> -1 return ConstantInt::getAllOnesValue(V1->getType()); - case Instruction::Shr: - if (!isa<UndefValue>(V2)) { - if (V1->getType()->isSigned()) - return const_cast<Constant*>(V1); // undef >>s X -> undef - // undef >>u X -> 0 - } else if (isa<UndefValue>(V1)) { - return const_cast<Constant*>(V1); // undef >> undef -> undef - } else { - if (V1->getType()->isSigned()) - return const_cast<Constant*>(V1); // X >>s undef -> X - } - return Constant::getNullValue(V1->getType());// X >>u undef -> 0 - + case Instruction::LShr: + if (isa<UndefValue>(V2) && isa<UndefValue>(V1)) + return const_cast<Constant*>(V1); // undef lshr undef -> undef + return Constant::getNullValue(V1->getType()); // X lshr undef -> 0 + // undef lshr X -> 0 + case Instruction::AShr: + if (!isa<UndefValue>(V2)) + return const_cast<Constant*>(V1); // undef ashr X --> undef + else if (isa<UndefValue>(V1)) + return const_cast<Constant*>(V1); // undef ashr undef -> undef + else + return const_cast<Constant*>(V1); // X ashr undef --> X case Instruction::Shl: - // undef << X -> 0 X << undef -> 0 + // undef << X -> 0 or X << undef -> 0 return Constant::getNullValue(V1->getType()); } } @@ -1466,7 +1469,8 @@ return ConstantFoldBinaryInstruction(Opcode, V2, V1); case Instruction::Shl: - case Instruction::Shr: + case Instruction::LShr: + case Instruction::AShr: case Instruction::Sub: case Instruction::SDiv: case Instruction::UDiv: Index: llvm/lib/VMCore/Constants.cpp diff -u llvm/lib/VMCore/Constants.cpp:1.169 llvm/lib/VMCore/Constants.cpp:1.170 --- llvm/lib/VMCore/Constants.cpp:1.169 Wed Nov 1 19:53:58 2006 +++ llvm/lib/VMCore/Constants.cpp Wed Nov 8 00:47:33 2006 @@ -498,20 +498,11 @@ Constant *ConstantExpr::getShl(Constant *C1, Constant *C2) { return get(Instruction::Shl, C1, C2); } -Constant *ConstantExpr::getShr(Constant *C1, Constant *C2) { - return get(Instruction::Shr, C1, C2); +Constant *ConstantExpr::getLShr(Constant *C1, Constant *C2) { + return get(Instruction::LShr, C1, C2); } - -Constant *ConstantExpr::getUShr(Constant *C1, Constant *C2) { - if (C1->getType()->isUnsigned()) return getShr(C1, C2); - return getCast(getShr(getCast(C1, - C1->getType()->getUnsignedVersion()), C2), C1->getType()); -} - -Constant *ConstantExpr::getSShr(Constant *C1, Constant *C2) { - if (C1->getType()->isSigned()) return getShr(C1, C2); - return getCast(getShr(getCast(C1, - C1->getType()->getSignedVersion()), C2), C1->getType()); +Constant *ConstantExpr::getAShr(Constant *C1, Constant *C2) { + return get(Instruction::AShr, C1, C2); } /// getWithOperandReplaced - Return a constant expression identical to this @@ -1330,7 +1321,9 @@ return new UnaryConstantExpr(Instruction::Cast, V.second[0], Ty); if ((V.first >= Instruction::BinaryOpsBegin && V.first < Instruction::BinaryOpsEnd) || - V.first == Instruction::Shl || V.first == Instruction::Shr) + V.first == Instruction::Shl || + V.first == Instruction::LShr || + V.first == Instruction::AShr) return new BinaryConstantExpr(V.first, V.second[0], V.second[1]); if (V.first == Instruction::Select) return new SelectConstantExpr(V.second[0], V.second[1], V.second[2]); @@ -1364,7 +1357,8 @@ OldC->getOperand(2)); break; case Instruction::Shl: - case Instruction::Shr: + case Instruction::LShr: + case Instruction::AShr: New = ConstantExpr::getShiftTy(NewTy, OldC->getOpcode(), OldC->getOperand(0), OldC->getOperand(1)); break; @@ -1453,7 +1447,8 @@ Constant *ConstantExpr::getTy(const Type *ReqTy, unsigned Opcode, Constant *C1, Constant *C2) { - if (Opcode == Instruction::Shl || Opcode == Instruction::Shr) + if (Opcode == Instruction::Shl || Opcode == Instruction::LShr || + Opcode == Instruction::AShr) return getShiftTy(ReqTy, Opcode, C1, C2); // Check the operands for consistency first assert(Opcode >= Instruction::BinaryOpsBegin && @@ -1521,9 +1516,10 @@ assert(C1->getType() == C2->getType() && "Op types should be identical!"); break; case Instruction::Shl: - case Instruction::Shr: + case Instruction::LShr: + case Instruction::AShr: assert(C2->getType() == Type::UByteTy && "Shift should be by ubyte!"); - assert((C1->getType()->isInteger() || isa<PackedType>(C1->getType())) && + assert(C1->getType()->isInteger() && "Tried to create a shift operation on a non-integer type!"); break; default: @@ -1558,8 +1554,9 @@ Constant *ConstantExpr::getShiftTy(const Type *ReqTy, unsigned Opcode, Constant *C1, Constant *C2) { // Check the operands for consistency first - assert((Opcode == Instruction::Shl || - Opcode == Instruction::Shr) && + assert((Opcode == Instruction::Shl || + Opcode == Instruction::LShr || + Opcode == Instruction::AShr) && "Invalid opcode in binary constant expression"); assert(C1->getType()->isIntegral() && C2->getType() == Type::UByteTy && "Invalid operand types for Shift constant expr!"); Index: llvm/lib/VMCore/Instruction.cpp diff -u llvm/lib/VMCore/Instruction.cpp:1.56 llvm/lib/VMCore/Instruction.cpp:1.57 --- llvm/lib/VMCore/Instruction.cpp:1.56 Wed Nov 1 19:53:58 2006 +++ llvm/lib/VMCore/Instruction.cpp Wed Nov 8 00:47:33 2006 @@ -128,7 +128,8 @@ case Select: return "select"; case Call: return "call"; case Shl: return "shl"; - case Shr: return "shr"; + case LShr: return "lshr"; + case AShr: return "ashr"; case VAArg: return "va_arg"; case ExtractElement: return "extractelement"; case InsertElement: return "insertelement"; Index: llvm/lib/VMCore/Instructions.cpp diff -u llvm/lib/VMCore/Instructions.cpp:1.45 llvm/lib/VMCore/Instructions.cpp:1.46 --- llvm/lib/VMCore/Instructions.cpp:1.45 Wed Nov 1 19:53:58 2006 +++ llvm/lib/VMCore/Instructions.cpp Wed Nov 8 00:47:33 2006 @@ -1222,17 +1222,6 @@ return false; } - -//===----------------------------------------------------------------------===// -// ShiftInst Class -//===----------------------------------------------------------------------===// - -/// isLogicalShift - Return true if this is a logical shift left or a logical -/// shift right. -bool ShiftInst::isLogicalShift() const { - return getOpcode() == Instruction::Shl || getType()->isUnsigned(); -} - //===----------------------------------------------------------------------===// // CastInst Class //===----------------------------------------------------------------------===// _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits