Skip to content

Commit dc42069

Browse files
kddnewtonmeta-codesync[bot]
authored andcommitted
Legalize AArch64 unary stack inputs in target selection
Summary: Move the AArch64 stack-input legalization for unary `Negate` and `Invert` out of the post-generation fixed-point rewrite pass and into target selection. Reviewed By: alexmalyshev Differential Revision: D109608869 fbshipit-source-id: 39491038e241657dc172badd6876615bdf7438d4
1 parent 0e18a43 commit dc42069

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

cinderx/Jit/lir/postgen.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ RewriteResult rewriteLoadSecondCallResult(instr_iter_t instr_iter) {
521521
// - MovZX/MovSX/MovSXD: specialized sign/zero-extending loads from stack
522522
// - Lea: takes the ADDRESS of a stack slot, not the value
523523
// - Call: late-created by PostRegAllocRewrite via setOpcode()
524+
// - Negate/Invert: handled by AArch64 target selection
524525
// - Inc/Dec: handled by AArch64 target selection
525526
// - EpilogueEnd: special return-value handling
526527
// - Pop: stack output, not input
@@ -567,8 +568,6 @@ RewriteResult rewriteSingleStackInputToVreg(
567568
}
568569

569570
switch (instr->opcode()) {
570-
case Instruction::kNegate:
571-
case Instruction::kInvert:
572571
case Instruction::kPush:
573572
return rewriteSingleStackInputToVreg(instr_iter, 0);
574573
case Instruction::kSelect:

cinderx/Jit/lir/target_select.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,26 @@ void legalizeA64GuardFPInput(BasicBlock* block, instr_iter_t instr_iter) {
200200
kGuardVarIndex, std::make_unique<Operand>(move, Operand::kLinked));
201201
}
202202

203+
/* AArch64 unary arithmetic instructions only operate on registers. */
204+
void legalizeA64UnaryStackInput(BasicBlock* block, instr_iter_t instr_iter) {
205+
Instruction* instr = instr_iter->get();
206+
JIT_DCHECK(
207+
instr->isNegate() || instr->isInvert(),
208+
"Expected Negate or Invert, got {}",
209+
instr->opname());
210+
211+
Operand* input = instr->getInput(0);
212+
if (!input->isStack()) {
213+
return;
214+
}
215+
216+
PhyLocation loc = input->getStackSlot();
217+
DataType dt = input->dataType();
218+
Instruction* move = block->allocateInstrBefore(
219+
instr_iter, Instruction::kMove, OutVReg{dt}, Stk{loc, dt});
220+
instr->setInput(0, std::make_unique<Operand>(move, Operand::kLinked));
221+
}
222+
203223
/* AArch64 Inc/Dec only operate on registers. Rewrite stack updates through a
204224
* virtual register so register allocation handles the temporary.
205225
*/
@@ -525,6 +545,10 @@ void selectA64Opcodes(Function* func) {
525545
legalizeA64GuardFPInput(block, cur_iter);
526546
selectA64Guard(block, cur_iter, use_counts);
527547
break;
548+
case Instruction::kNegate:
549+
case Instruction::kInvert:
550+
legalizeA64UnaryStackInput(block, cur_iter);
551+
break;
528552
case Instruction::kInc:
529553
case Instruction::kDec:
530554
legalizeA64StackInputForIncDec(block, cur_iter);

0 commit comments

Comments
 (0)