Commit f8360baf by Nicolas Capens

Optimize constant operand order.

Constant operands of commutative operations preferably go on the right hand side to avoid requiring an extra register for two operand instructions. Also, Subzero assumes constants in pointer arithmetic are on the right hand side to consider optimizing it into an addressing mode. Change-Id: Ife5a471903d5f4bef0c19b6c908d75715f06bfec Reviewed-on: https://swiftshader-review.googlesource.com/8548Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent f549e3b6
......@@ -589,12 +589,31 @@ namespace sw
::basicBlock->appendInst(br);
}
static bool isCommutative(Ice::InstArithmetic::OpKind op)
{
switch(op)
{
case Ice::InstArithmetic::Add:
case Ice::InstArithmetic::Fadd:
case Ice::InstArithmetic::Mul:
case Ice::InstArithmetic::Fmul:
case Ice::InstArithmetic::And:
case Ice::InstArithmetic::Or:
case Ice::InstArithmetic::Xor:
return true;
default:
return false;
}
}
static Value *createArithmetic(Ice::InstArithmetic::OpKind op, Value *lhs, Value *rhs)
{
assert(lhs->getType() == rhs->getType() || (llvm::isa<Ice::Constant>(rhs) && (op == Ice::InstArithmetic::Shl || Ice::InstArithmetic::Lshr || Ice::InstArithmetic::Ashr)));
bool swapOperands = llvm::isa<Ice::Constant>(lhs) && isCommutative(op);
Ice::Variable *result = ::function->makeVariable(lhs->getType());
Ice::InstArithmetic *arithmetic = Ice::InstArithmetic::create(::function, op, result, lhs, rhs);
Ice::InstArithmetic *arithmetic = Ice::InstArithmetic::create(::function, op, result, swapOperands ? rhs : lhs, swapOperands ? lhs : rhs);
::basicBlock->appendInst(arithmetic);
return V(result);
......
pnacl-subzero @ 8bd18e1b
Subproject commit dbf81e0c0e364173176159e0e2548e9948b197a4
Subproject commit 8bd18e1be3eb25d60a4696bb948ab41f6ce6afd6
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment