Skip to content

Commit 98a7d20

Browse files
kddnewtonmeta-codesync[bot]
authored andcommitted
Use kObject for address loads in rewriteMoveAbsoluteAddress
Summary: The `rewriteMoveAbsoluteAddress` postgen pass on AArch64 lowers absolute memory address operands into a two-instruction sequence: first loading the address into a virtual register, then using an indirect load through that register. Previously the intermediate `Move(Imm → vreg)` used `DataType::k64bit`, which meant the branch relaxation pass did not recognize it as a pointer-width operand and could not select optimal instruction sequences (e.g. `adr`/`adrp+add`/`ldr` instead of `movz+movk` chains). Changing to `DataType::kObject` allows the value to flow through branch relaxation correctly, since the relaxation pass keys on the data type to determine whether an immediate load is a candidate for address-relative encoding. Reviewed By: alexmalyshev Differential Revision: D103072904 fbshipit-source-id: cb00a2fecccfe8adee41ece6294d2b770793de56
1 parent 870e469 commit 98a7d20

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

cinderx/Jit/lir/postgen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,8 @@ RewriteResult rewriteMoveAbsoluteAddress(instr_iter_t instr_iter) {
697697
auto addr_move = block->allocateInstrBefore(
698698
instr_iter,
699699
Instruction::kMove,
700-
OutVReg{DataType::k64bit},
701-
Imm{addr, DataType::k64bit});
700+
OutVReg{DataType::kObject},
701+
Imm{addr, DataType::kObject});
702702

703703
// Replace the Mem input with Ind{addr_vreg, offset=0}. For a simple
704704
// Ind with no index and offset 0, ptrIndirect resolves to ptr(base)

cinderx/RuntimeTests/lir_postgen_test.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,24 @@ BB %6
150150
EXPECT_EQ(runPostGenRewrite(lir_input_str), expected_lir_str.c_str());
151151
}
152152

153+
#if defined(CINDER_AARCH64)
154+
TEST_F(LIRPostGenerationRewriteTest, MoveAbsoluteAddressUsesObjectDataType) {
155+
const char* lir_input_str = R"(Function:
156+
BB %0
157+
%10:Object = Move [0x12345]
158+
Return %10
159+
)";
160+
161+
const char* expected_lir_str = R"(Function:
162+
BB %0
163+
%12:Object = Move 74565(0x12345):Object
164+
%10:Object = Move [%12:Object]:Object
165+
Return %10:Object
166+
167+
)";
168+
169+
EXPECT_EQ(runPostGenRewrite(lir_input_str), expected_lir_str);
170+
}
171+
#endif
172+
153173
} // namespace jit::lir

0 commit comments

Comments
 (0)