[PATCH] D138615: [llvm] Teach FastISel for AArch64 about tagged globals
Leonard Chan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 23 14:49:33 PST 2022
leonardchan created this revision.
leonardchan added reviewers: pcc, vitalybuka, eugenis.
leonardchan added a project: LLVM.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: All.
leonardchan requested review of this revision.
This addresses https://github.com/llvm/llvm-project/issues/57750. For some globals, the tag wasn't propagated correctly because the necessary `movk` wasn't emitted sometimes.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D138615
Files:
llvm/lib/Target/AArch64/AArch64FastISel.cpp
Index: llvm/lib/Target/AArch64/AArch64FastISel.cpp
===================================================================
--- llvm/lib/Target/AArch64/AArch64FastISel.cpp
+++ llvm/lib/Target/AArch64/AArch64FastISel.cpp
@@ -496,6 +496,20 @@
ADRPReg)
.addGlobalAddress(GV, 0, AArch64II::MO_PAGE | OpFlags);
+ if (OpFlags & AArch64II::MO_TAGGED) {
+ // MO_TAGGED on the page indicates a tagged address. Set the tag now.
+ // We do so by creating a MOVK that sets bits 48-63 of the register to
+ // (global address + 0x100000000 - PC) >> 48. This assumes that we're in
+ // the small code model so we can assume a binary size of <= 4GB, which
+ // makes the untagged PC relative offset positive. The binary must also be
+ // loaded into address range [0, 2^48). Both of these properties need to
+ // be ensured at runtime when using tagged addresses.
+ BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD, TII.get(AArch64::MOVKXi), ADRPReg)
+ .addReg(ADRPReg)
+ .addGlobalAddress(GV, /*Offset=*/0x100000000, AArch64II::MO_PREL | AArch64II::MO_G3)
+ .addImm(48);
+ }
+
ResultReg = createResultReg(&AArch64::GPR64spRegClass);
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD, TII.get(AArch64::ADDXri),
ResultReg)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138615.477616.patch
Type: text/x-patch
Size: 1316 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221123/531808e6/attachment.bin>
More information about the llvm-commits
mailing list