Skip to content

Commit fcf5a54

Browse files
kddnewtonmeta-codesync[bot]
authored andcommitted
Do not use xor-ing on aarch64
Summary: In most x86_64 microarchitectures, xor reg, reg has an optimization to make it faster. On most aarch64, it does not. Instead, the idiom is to use the zero-register and mov it, as in mov reg, xzr. This commit does that instead. Reviewed By: alexmalyshev Differential Revision: D94685862 fbshipit-source-id: 9648b9839d01558937d96edbb59de545b9191ab2
1 parent aede985 commit fcf5a54

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

cinderx/Jit/codegen/autogen.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,14 +2058,21 @@ void translateMove(Environ* env, const Instruction* instr) {
20582058
loadToReg(as, output, ptr);
20592059
break;
20602060
}
2061-
case lir::OperandType::kImm:
2061+
case lir::OperandType::kImm: {
20622062
// Loading a constant immediate into a register.
2063+
auto constant = input->getConstant();
2064+
20632065
if (output->isVecD()) {
2064-
as->fmov(AT::getVecD(output), input->getConstant());
2066+
as->fmov(AT::getVecD(output), constant);
2067+
} else if (constant == 0) {
2068+
as->mov(
2069+
AT::getGpWiden(output),
2070+
AT::getGpWiden(output->dataType(), a64::xzr.id()));
20652071
} else {
2066-
as->mov(AT::getGpWiden(output), input->getConstant());
2072+
as->mov(AT::getGpWiden(output), constant);
20672073
}
20682074
break;
2075+
}
20692076
case lir::OperandType::kNone:
20702077
case lir::OperandType::kVreg:
20712078
case lir::OperandType::kLabel:

cinderx/Jit/lir/postalloc.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ RewriteResult rewriteBranchInstrs(Function* function) {
456456
// rewrite move instructions
457457
// optimize move instruction in the following cases:
458458
// 1. remove the move instruction when source and destination are the same
459-
// 2. rewrite move instruction to xor when the source operand is 0.
459+
// 2. rewrite move instruction to xor when the source operand is 0 on x86_64.
460460
RewriteResult optimizeMoveInstrs(instr_iter_t instr_iter) {
461461
auto instr = instr_iter->get();
462462
auto instr_opcode = instr->opcode();
@@ -474,6 +474,7 @@ RewriteResult optimizeMoveInstrs(instr_iter_t instr_iter) {
474474
return kRemoved;
475475
}
476476

477+
#if defined(CINDER_X86_64)
477478
if (in->isImm() && !in->isFp() && in->getConstant() == 0 && out->isReg()) {
478479
auto in_opnd = dynamic_cast<Operand*>(in);
479480
JIT_CHECK(
@@ -488,6 +489,7 @@ RewriteResult optimizeMoveInstrs(instr_iter_t instr_iter) {
488489
instr->addOperands(PhyReg{reg, data_type}, PhyReg{reg, data_type});
489490
return kChanged;
490491
}
492+
#endif
491493

492494
return kUnchanged;
493495
}

0 commit comments

Comments
 (0)