For 64bit address, the multiply would expand to several instructions. As for most time, the size is PowerOf 2. So we can use left-shift to do this.
Signed-off-by: Ruiling Song <[email protected]> --- backend/src/llvm/llvm_passes.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/backend/src/llvm/llvm_passes.cpp b/backend/src/llvm/llvm_passes.cpp index 367a2c3..c5f3ffe 100644 --- a/backend/src/llvm/llvm_passes.cpp +++ b/backend/src/llvm/llvm_passes.cpp @@ -276,8 +276,6 @@ namespace gbe uint32_t align = getAlignmentByte(unit, elementType); size += getPadding(size, align); - Constant* newConstSize = - ConstantInt::get(IntegerType::get(GEPInst->getContext(), ptrSize), size); Value *operand = GEPInst->getOperand(op); @@ -308,13 +306,22 @@ namespace gbe } } #endif - Value* tmpMul = operand; + Value* tmpOffset = operand; if (size != 1) { - tmpMul = BinaryOperator::Create(Instruction::Mul, newConstSize, operand, - "", GEPInst); + if (isPowerOf<2>(size)) { + Constant* shiftAmnt = + ConstantInt::get(IntegerType::get(GEPInst->getContext(), ptrSize), logi2(size)); + tmpOffset = BinaryOperator::Create(Instruction::Shl, operand, shiftAmnt, + "", GEPInst); + } else{ + Constant* sizeConst = + ConstantInt::get(IntegerType::get(GEPInst->getContext(), ptrSize), size); + tmpOffset = BinaryOperator::Create(Instruction::Mul, sizeConst, operand, + "", GEPInst); + } } currentAddrInst = - BinaryOperator::Create(Instruction::Add, currentAddrInst, tmpMul, + BinaryOperator::Create(Instruction::Add, currentAddrInst, tmpOffset, "", GEPInst); } -- 2.4.1 _______________________________________________ Beignet mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/beignet
