Skip to content

Commit 588af0f

Browse files
kddnewtonmeta-codesync[bot]
authored andcommitted
Legalize AArch64 Select stack inputs in target selection
Summary: Move the AArch64 stack-input legalization for `Select` out of the post-generation fixed-point rewrite pass and into target selection. This preserves the existing behavior of lowering all stack-backed `Select` inputs through virtual registers while leaving the immediate `Select` legalization in postgen, where generated `Move(Imm)` instructions can still participate in later postgen rewrites. Reviewed By: alexmalyshev Differential Revision: D109608870 fbshipit-source-id: f06d6c4be7f4a55479aadc5d0d529f3f63689d4a
1 parent dd01791 commit 588af0f

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

cinderx/Jit/lir/postgen.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ RewriteResult rewriteLoadSecondCallResult(instr_iter_t instr_iter) {
523523
// - Call: late-created by PostRegAllocRewrite via setOpcode()
524524
// - Negate/Invert: handled by AArch64 target selection
525525
// - Inc/Dec: handled by AArch64 target selection
526+
// - Select: handled by AArch64 target selection
526527
// - EpilogueEnd: special return-value handling
527528
// - Pop: stack output, not input
528529
bool lowerStackInputToVreg(instr_iter_t instr_iter, size_t idx) {
@@ -570,8 +571,6 @@ RewriteResult rewriteSingleStackInputToVreg(
570571
switch (instr->opcode()) {
571572
case Instruction::kPush:
572573
return rewriteSingleStackInputToVreg(instr_iter, 0);
573-
case Instruction::kSelect:
574-
return rewriteAllStackInputsToVreg(instr_iter);
575574
default:
576575
return kUnchanged;
577576
}

cinderx/Jit/lir/target_select.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,18 @@ void legalizeA64UnaryStackInput(BasicBlock* block, instr_iter_t instr_iter) {
231231
moveA64StackInputToVreg(block, instr_iter, 0);
232232
}
233233

234+
/* AArch64 Select lowers to register-only csel. */
235+
void legalizeA64SelectStackInputs(BasicBlock* block, instr_iter_t instr_iter) {
236+
Instruction* instr = instr_iter->get();
237+
JIT_DCHECK(instr->isSelect(), "Expected Select, got {}", instr->opname());
238+
239+
for (size_t i = 0; i < instr->getNumInputs(); i++) {
240+
if (instr->getInput(i)->isStack()) {
241+
moveA64StackInputToVreg(block, instr_iter, i);
242+
}
243+
}
244+
}
245+
234246
/* AArch64 Inc/Dec only operate on registers. Rewrite stack updates through a
235247
* virtual register so register allocation handles the temporary.
236248
*/
@@ -558,6 +570,9 @@ void selectA64Opcodes(Function* func) {
558570
case Instruction::kInvert:
559571
legalizeA64UnaryStackInput(block, cur_iter);
560572
break;
573+
case Instruction::kSelect:
574+
legalizeA64SelectStackInputs(block, cur_iter);
575+
break;
561576
case Instruction::kInc:
562577
case Instruction::kDec:
563578
legalizeA64StackInputForIncDec(block, cur_iter);

0 commit comments

Comments
 (0)