From 3822ff5c71478c7c90a50ca57045fb676fcb5005 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Wed, 8 Nov 2006 06:47:33 +0000 Subject: 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31542 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ExecutionEngine/Interpreter/Execution.cpp | 69 +++++++++++++++++++-------- 1 file changed, 50 insertions(+), 19 deletions(-) (limited to 'lib/ExecutionEngine/Interpreter/Execution.cpp') diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp index cf41abd646..da1fe54dfa 100644 --- a/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -72,8 +72,10 @@ static GenericValue executeSetGEInst(GenericValue Src1, GenericValue Src2, const Type *Ty); static GenericValue executeShlInst(GenericValue Src1, GenericValue Src2, const Type *Ty); -static GenericValue executeShrInst(GenericValue Src1, GenericValue Src2, - const Type *Ty); +static GenericValue executeLShrInst(GenericValue Src1, GenericValue Src2, + const Type *Ty); +static GenericValue executeAShrInst(GenericValue Src1, GenericValue Src2, + const Type *Ty); static GenericValue executeSelectInst(GenericValue Src1, GenericValue Src2, GenericValue Src3); @@ -161,10 +163,14 @@ GenericValue Interpreter::getConstantExprValue (ConstantExpr *CE, return executeShlInst(getOperandValue(CE->getOperand(0), SF), getOperandValue(CE->getOperand(1), SF), CE->getOperand(0)->getType()); - case Instruction::Shr: - return executeShrInst(getOperandValue(CE->getOperand(0), SF), - getOperandValue(CE->getOperand(1), SF), - CE->getOperand(0)->getType()); + case Instruction::LShr: + return executeLShrInst(getOperandValue(CE->getOperand(0), SF), + getOperandValue(CE->getOperand(1), SF), + CE->getOperand(0)->getType()); + case Instruction::AShr: + return executeAShrInst(getOperandValue(CE->getOperand(0), SF), + getOperandValue(CE->getOperand(1), SF), + CE->getOperand(0)->getType()); case Instruction::Select: return executeSelectInst(getOperandValue(CE->getOperand(0), SF), getOperandValue(CE->getOperand(1), SF), @@ -943,6 +949,10 @@ void Interpreter::visitCallSite(CallSite CS) { #define IMPLEMENT_SHIFT(OP, TY) \ case Type::TY##TyID: Dest.TY##Val = Src1.TY##Val OP Src2.UByteVal; break +#define IMPLEMENT_SIGNLESS_SHIFT(OP, TY1, TY2) \ + case Type::TY2##TyID: \ + IMPLEMENT_SHIFT(OP, TY1) + static GenericValue executeShlInst(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; @@ -961,20 +971,31 @@ static GenericValue executeShlInst(GenericValue Src1, GenericValue Src2, return Dest; } -static GenericValue executeShrInst(GenericValue Src1, GenericValue Src2, - const Type *Ty) { +static GenericValue executeLShrInst(GenericValue Src1, GenericValue Src2, + const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_SHIFT(>>, UByte); - IMPLEMENT_SHIFT(>>, SByte); - IMPLEMENT_SHIFT(>>, UShort); - IMPLEMENT_SHIFT(>>, Short); - IMPLEMENT_SHIFT(>>, UInt); - IMPLEMENT_SHIFT(>>, Int); - IMPLEMENT_SHIFT(>>, ULong); - IMPLEMENT_SHIFT(>>, Long); + IMPLEMENT_SIGNLESS_SHIFT(>>, UByte, SByte); + IMPLEMENT_SIGNLESS_SHIFT(>>, UShort, Short); + IMPLEMENT_SIGNLESS_SHIFT(>>, UInt, Int); + IMPLEMENT_SIGNLESS_SHIFT(>>, ULong, Long); default: - std::cout << "Unhandled type for Shr instruction: " << *Ty << "\n"; + std::cout << "Unhandled type for LShr instruction: " << *Ty << "\n"; + abort(); + } + return Dest; +} + +static GenericValue executeAShrInst(GenericValue Src1, GenericValue Src2, + const Type *Ty) { + GenericValue Dest; + switch (Ty->getTypeID()) { + IMPLEMENT_SIGNLESS_SHIFT(>>, SByte, UByte); + IMPLEMENT_SIGNLESS_SHIFT(>>, Short, UShort); + IMPLEMENT_SIGNLESS_SHIFT(>>, Int, UInt); + IMPLEMENT_SIGNLESS_SHIFT(>>, Long, ULong); + default: + std::cout << "Unhandled type for AShr instruction: " << *Ty << "\n"; abort(); } return Dest; @@ -990,13 +1011,23 @@ void Interpreter::visitShl(ShiftInst &I) { SetValue(&I, Dest, SF); } -void Interpreter::visitShr(ShiftInst &I) { +void Interpreter::visitLShr(ShiftInst &I) { + ExecutionContext &SF = ECStack.back(); + const Type *Ty = I.getOperand(0)->getType(); + GenericValue Src1 = getOperandValue(I.getOperand(0), SF); + GenericValue Src2 = getOperandValue(I.getOperand(1), SF); + GenericValue Dest; + Dest = executeLShrInst (Src1, Src2, Ty); + SetValue(&I, Dest, SF); +} + +void Interpreter::visitAShr(ShiftInst &I) { ExecutionContext &SF = ECStack.back(); const Type *Ty = I.getOperand(0)->getType(); GenericValue Src1 = getOperandValue(I.getOperand(0), SF); GenericValue Src2 = getOperandValue(I.getOperand(1), SF); GenericValue Dest; - Dest = executeShrInst (Src1, Src2, Ty); + Dest = executeAShrInst (Src1, Src2, Ty); SetValue(&I, Dest, SF); } -- cgit v1.2.3-18-g5258