[Beignet] [PATCH 1/2] GBE: use shl instead of multiply as possible.
Yang Rong
rong.r.yang at intel.com
Tue Feb 7 08:23:32 UTC 2017
i32 multiply and i64 multiply need several instructions, use the shl
instruction when one source is pow of 2 constant.
Signed-off-by: Yang Rong <rong.r.yang at intel.com>
---
backend/src/llvm/llvm_gen_backend.cpp | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp
index 0b2169c..5c5266c 100644
--- a/backend/src/llvm/llvm_gen_backend.cpp
+++ b/backend/src/llvm/llvm_gen_backend.cpp
@@ -3272,6 +3272,25 @@ namespace gbe
case Instruction::Sub:
case Instruction::FSub: ctx.SUB(type, dst, src0, src1); break;
case Instruction::Mul:
+ {
+ //LLVM always put constant to src1, but also add the src0 constant check.
+ ConstantInt *c = dyn_cast<ConstantInt>(I.getOperand(0));
+ int index = 0;
+ if (c == NULL) {
+ c = dyn_cast<ConstantInt>(I.getOperand(0));
+ index = 1;
+ }
+ if (c != NULL && isPowerOf<2>(c->getSExtValue())) {
+ c = ConstantInt::get(c->getType(), logi2(c->getZExtValue()));
+ if(index == 0)
+ ctx.SHL(type, dst, src1, this->getRegister(c));
+ else
+ ctx.SHL(type, dst, src0, this->getRegister(c));
+ } else {
+ ctx.MUL(type, dst, src0, src1);
+ }
+ break;
+ }
case Instruction::FMul: ctx.MUL(type, dst, src0, src1); break;
case Instruction::URem: ctx.REM(getUnsignedType(ctx, I.getType()), dst, src0, src1); break;
case Instruction::SRem:
--
2.7.4
More information about the Beignet
mailing list