summaryrefslogtreecommitdiff
path: root/backend/src/llvm
diff options
context:
space:
mode:
authorYang Rong <rong.r.yang@intel.com>2017-02-07 16:23:32 +0800
committerYang Rong <rong.r.yang@intel.com>2017-02-10 18:17:44 +0800
commit0c6e7e6f935dd00213de5e870345d2204379e304 (patch)
tree474d31c44658f161465018a646d287d461942a6e /backend/src/llvm
parentd425e64f3e02583257cc28184d1b3a2293f29179 (diff)
downloadbeignet-0c6e7e6f935dd00213de5e870345d2204379e304.tar.gz
GBE: use shl instead of multiply as possible.
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@intel.com> Reviewed-by: Ruiling Song <ruiling.song@intel.com>
Diffstat (limited to 'backend/src/llvm')
-rw-r--r--backend/src/llvm/llvm_gen_backend.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp
index 0b2169c0..5c5266c7 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: