[llvm] [AMDGPU] Support global address in V/S_MOV_B64 lowering (PR #203527)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 6 06:44:55 PDT 2026


================
@@ -126,6 +127,51 @@ 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) {
+  assert(SrcOp.isGlobal() && "Expected a global address operand");
+  const GlobalValue *GV = SrcOp.getGlobal();
+  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;
+  } else if (!(SrcFlags &
+               (SIInstrInfo::MO_ABS32_LO | SIInstrInfo::MO_ABS32_HI))) {
+    // No explicit relocation flags set; infer from target properties.
+    if (!ST.isAmdPalOS() && !ST.isMesa3DOS()) {
+      const SITargetLowering *TLI = ST.getTargetLowering();
+      if (TLI->shouldEmitFixup(GV) || TLI->shouldEmitPCReloc(GV)) {
+        LoReloc = SIInstrInfo::MO_REL32_LO;
+        HiReloc = SIInstrInfo::MO_REL32_HI;
+      }
+    }
+  }
----------------
arsenm wrote:

```suggestion
  }
```
This feels wrong. It shouldn't need to be re-lowering the underlying global and inferring the flags, the flags should have been there to begin with

https://github.com/llvm/llvm-project/pull/203527


More information about the llvm-commits mailing list