[Beignet] [PATCH] GBE: use shift for PowerOf2 size when lowering GEP.
Yang, Rong R
rong.r.yang at intel.com
Mon Feb 6 09:02:21 UTC 2017
This patch looks good to me.
As discuss, we would better add the similar optimize in GEN selection, because GEP lower is a part of PowerOf 2 multiply. I will add it later.
> -----Original Message-----
> From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of
> Ruiling Song
> Sent: Monday, January 23, 2017 13:32
> To: beignet at lists.freedesktop.org
> Cc: Song, Ruiling <ruiling.song at intel.com>
> Subject: [Beignet] [PATCH] GBE: use shift for PowerOf2 size when lowering
> GEP.
>
> 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 <ruiling.song at intel.com>
> ---
> 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
> Beignet at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/beignet
More information about the Beignet
mailing list