[llvm] [AMDGPU] Support global address in V/S_MOV_B64 lowering (PR #203527)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 14 06:12:33 PDT 2026
================
@@ -126,6 +127,39 @@ static bool canRemat(const MachineInstr &MI) {
return false;
}
+// Split relocation flags for 64-bit global-address materialization into a
+// common base and the hi/lo relocation variants.
+static std::tuple<unsigned, unsigned, unsigned>
+splitGlobalAddressRelocFlags(const GCNSubtarget &ST,
+ const MachineOperand &SrcOp) {
+ unsigned SrcFlags = SrcOp.getTargetFlags();
+
+ // Infer the relocation type from the existing flags on the global operand.
+ // The relocation type should have been determined earlier in the pipeline.
+ unsigned LoReloc = SIInstrInfo::MO_ABS32_LO;
+ unsigned HiReloc = SIInstrInfo::MO_ABS32_HI;
+
+ if (SrcFlags & SIInstrInfo::MO_REL32) {
+ LoReloc = SIInstrInfo::MO_REL32_LO;
+ HiReloc = SIInstrInfo::MO_REL32_HI;
+ } else if (SrcFlags & SIInstrInfo::MO_GOTPCREL32_LO) {
+ LoReloc = SIInstrInfo::MO_GOTPCREL32_LO;
+ HiReloc = SIInstrInfo::MO_GOTPCREL32_HI;
+ } else if (SrcFlags & SIInstrInfo::MO_GOTPCREL64) {
+ // For 64-bit GOT-relative, use the 64-bit relocation.
+ LoReloc = SIInstrInfo::MO_GOTPCREL64;
+ HiReloc = SIInstrInfo::MO_GOTPCREL64;
+ }
+
+ unsigned BaseFlags =
+ SrcFlags & ~(SIInstrInfo::MO_ABS32_LO | SIInstrInfo::MO_ABS32_HI |
+ SIInstrInfo::MO_REL32_LO | SIInstrInfo::MO_REL32_HI |
+ SIInstrInfo::MO_GOTPCREL32_LO |
+ SIInstrInfo::MO_GOTPCREL32_HI | SIInstrInfo::MO_GOTPCREL64);
+
+ return std::make_tuple(BaseFlags, LoReloc, HiReloc);
----------------
jayfoad wrote:
Nit you can write this as
```suggestion
return std::tuple(BaseFlags, LoReloc, HiReloc);
```
or even better
```suggestion
return {BaseFlags, LoReloc, HiReloc};
```
https://github.com/llvm/llvm-project/pull/203527
More information about the llvm-commits
mailing list