From 8069a76100a7c6f1bbbdaf69af2ad8f3f606f668 Mon Sep 17 00:00:00 2001 From: Anthony Pesch Date: Wed, 23 Mar 2016 18:59:14 -0700 Subject: [PATCH] move select condition out of arg0 to optimize register allocation when select is true --- src/jit/backend/x64/x64_emitter.cc | 16 +++++++++++----- src/jit/ir/ir_builder.cc | 12 ++++-------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/jit/backend/x64/x64_emitter.cc b/src/jit/backend/x64/x64_emitter.cc index ce55f58f..7e2877b3 100644 --- a/src/jit/backend/x64/x64_emitter.cc +++ b/src/jit/backend/x64/x64_emitter.cc @@ -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) { diff --git a/src/jit/ir/ir_builder.cc b/src/jit/ir/ir_builder.cc index 8014dcb9..9c643391 100644 --- a/src/jit/ir/ir_builder.cc +++ b/src/jit/ir/ir_builder.cc @@ -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; }