From 475a5a0983befa7c2ab2249992c9dd84c4dfcc34 Mon Sep 17 00:00:00 2001 From: Lu Guanqun Date: Thu, 24 Jan 2013 12:22:08 +0800 Subject: [PATCH] fix the wrong zero extend instruction handling This helps to fix the problem facing Xing Homer. When we encounter 'zext' instruction, we should take the soruce type as an unsigned type, otherwise we're just sign extend the number, which is not what we want. For the implementation, I'm reusing getUnsignedType() and this expects an integer to be accepted, and this conforms to the spec of LLVM. This patch doesn't trigger regression. I'll provide the corresponding test case later. Signed-off-by: Lu Guanqun Reviewed-by: Homer Hsing Reviewed-by: Zhigang Gong --- backend/src/llvm/llvm_gen_backend.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp index b69d5b6..5c26f75 100644 --- a/backend/src/llvm/llvm_gen_backend.cpp +++ b/backend/src/llvm/llvm_gen_backend.cpp @@ -225,17 +225,23 @@ namespace gbe /*! Get number of element to process dealing either with a vector or a scalar * value */ - static ir::Type getVectorInfo(const ir::Context &ctx, Type *llvmType, Value *value, uint32_t &elemNum) + static ir::Type getVectorInfo(const ir::Context &ctx, Type *llvmType, Value *value, uint32_t &elemNum, bool useUnsigned = false) { ir::Type type; if (llvmType->isVectorTy() == true) { VectorType *vectorType = cast(llvmType); Type *elementType = vectorType->getElementType(); elemNum = vectorType->getNumElements(); - type = getType(ctx, elementType); + if (useUnsigned) + type = getUnsignedType(ctx, elementType); + else + type = getType(ctx, elementType); } else { elemNum = 1; - type = getType(ctx, llvmType); + if (useUnsigned) + type = getUnsignedType(ctx, llvmType); + else + type = getType(ctx, llvmType); } return type; } @@ -1351,7 +1357,12 @@ namespace gbe Type *llvmDstType = I.getType(); Type *llvmSrcType = I.getOperand(0)->getType(); const ir::Type dstType = getVectorInfo(ctx, llvmDstType, &I, elemNum); - const ir::Type srcType = getVectorInfo(ctx, llvmSrcType, &I, elemNum); + ir::Type srcType; + if (I.getOpcode() == Instruction::ZExt) { + srcType = getVectorInfo(ctx, llvmSrcType, &I, elemNum, true); + } else { + srcType = getVectorInfo(ctx, llvmSrcType, &I, elemNum); + } // We use a select (0,1) not a convert when the destination is a boolean if (srcType == ir::TYPE_BOOL) { -- 2.7.4