move select condition out of arg0 to optimize register allocation when select is true

This commit is contained in:
Anthony Pesch 2016-03-23 18:59:14 -07:00
parent 05388bca6f
commit 8069a76100
2 changed files with 15 additions and 13 deletions

View File

@ -906,13 +906,19 @@ EMITTER(FTRUNC) {
EMITTER(SELECT) {
const Xbyak::Reg result = e.GetRegister(instr);
const Xbyak::Reg cond = e.GetRegister(instr->arg0());
const Xbyak::Reg a = e.GetRegister(instr->arg1());
const Xbyak::Reg b = e.GetRegister(instr->arg2());
const Xbyak::Reg a = e.GetRegister(instr->arg0());
const Xbyak::Reg b = e.GetRegister(instr->arg1());
const Xbyak::Reg cond = e.GetRegister(instr->arg2());
// convert result to Reg32e to please xbyak
CHECK_GE(result.getBit(), 32);
Xbyak::Reg32e result_32e(result.getIdx(), result.getBit());
e.test(cond, cond);
e.cmovnz(result.cvt32(), a);
e.cmovz(result.cvt32(), b);
if (result_32e != a) {
e.cmovnz(result_32e, a);
}
e.cmovz(result_32e, b);
}
EMITTER(CMP) {

View File

@ -217,16 +217,12 @@ Instr *IRBuilder::FTrunc(Value *v, ValueType dest_type) {
}
Instr *IRBuilder::Select(Value *cond, Value *t, Value *f) {
CHECK_EQ(t->type(), f->type());
if (cond->type() != VALUE_I8) {
cond = CmpNE(cond, AllocConstant(0));
}
CHECK(IsIntType(cond->type()) && IsIntType(t->type()) && t->type() == f->type());
Instr *instr = AppendInstr(OP_SELECT, t->type());
instr->set_arg0(cond);
instr->set_arg1(t);
instr->set_arg2(f);
instr->set_arg0(t);
instr->set_arg1(f);
instr->set_arg2(cond);
return instr;
}