diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2006-11-08 06:47:33 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2006-11-08 06:47:33 +0000 |
commit | fdff938a7e4988da80be038acb1c6717d61b531a (patch) | |
tree | 2270b132b8a1fe22f63b56653ebf71dac480ad84 /llvm/lib/VMCore/Constants.cpp | |
parent | 41f6c7cfb24169288c69d0dc5abf5518c142b76e (diff) | |
download | bcm5719-llvm-fdff938a7e4988da80be038acb1c6717d61b531a.tar.gz bcm5719-llvm-fdff938a7e4988da80be038acb1c6717d61b531a.zip |
For 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.
llvm-svn: 31542
Diffstat (limited to 'llvm/lib/VMCore/Constants.cpp')
-rw-r--r-- | llvm/lib/VMCore/Constants.cpp | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp index bcfd3879dbe..ee855ca7322 100644 --- a/llvm/lib/VMCore/Constants.cpp +++ b/llvm/lib/VMCore/Constants.cpp @@ -498,20 +498,11 @@ Constant *ConstantExpr::getSetGE(Constant *C1, Constant *C2) { 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 @@ namespace llvm { 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 @@ namespace llvm { 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::getPtrPtrFromArrayPtr(Constant *C) { 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 @@ Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) { 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::getSelectTy(const Type *ReqTy, Constant *C, 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!"); |