[llvm] f5ebc1a - [AMDGPU] Apply target flag specifier when lowering MO_ExternalSymbol operands (#202389)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 30 20:02:40 PDT 2026


Author: Arseniy Obolenskiy
Date: 2026-07-01T05:02:35+02:00
New Revision: f5ebc1a2e48605f01f9464eb5e833862790e3499

URL: https://github.com/llvm/llvm-project/commit/f5ebc1a2e48605f01f9464eb5e833862790e3499
DIFF: https://github.com/llvm/llvm-project/commit/f5ebc1a2e48605f01f9464eb5e833862790e3499.diff

LOG: [AMDGPU] Apply target flag specifier when lowering MO_ExternalSymbol operands (#202389)

The MO_ExternalSymbol case in AMDGPUMCInstLower dropped the operand
target flags emitting the wrong relocation type

Added: 
    llvm/test/CodeGen/AMDGPU/mcinstlower-external-symbol-reloc.mir

Modified: 
    llvm/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp b/llvm/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp
index ffd33922ec511..3f0fb64be4886 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp
@@ -103,7 +103,8 @@ bool AMDGPUMCInstLower::lowerOperand(const MachineOperand &MO,
   }
   case MachineOperand::MO_ExternalSymbol: {
     MCSymbol *Sym = Ctx.getOrCreateSymbol(StringRef(MO.getSymbolName()));
-    const MCSymbolRefExpr *Expr = MCSymbolRefExpr::create(Sym, Ctx);
+    const MCExpr *Expr =
+        MCSymbolRefExpr::create(Sym, getSpecifier(MO.getTargetFlags()), Ctx);
     MCOp = MCOperand::createExpr(Expr);
     return true;
   }

diff  --git a/llvm/test/CodeGen/AMDGPU/mcinstlower-external-symbol-reloc.mir b/llvm/test/CodeGen/AMDGPU/mcinstlower-external-symbol-reloc.mir
new file mode 100644
index 0000000000000..e881d5851a4c8
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/mcinstlower-external-symbol-reloc.mir
@@ -0,0 +1,19 @@
+# RUN: llc -mtriple=amdgcn -mcpu=gfx900 -start-after=prologepilog %s -o - | FileCheck --check-prefix=ASM %s
+# RUN: llc -mtriple=amdgcn -mcpu=gfx900 -start-after=prologepilog -filetype=obj %s -o %t.o && llvm-readobj -r %t.o | FileCheck --check-prefix=ELF %s
+
+# AMDGPUMCInstLower must apply the operand's target flag specifier when
+# lowering an MO_ExternalSymbol operand, just like it does for
+# MO_GlobalAddress.
+
+# ASM: s_mov_b32 s0, external_sym at abs32@lo
+
+# ELF: R_AMDGPU_ABS32_LO external_sym{{$}}
+
+---
+name: external_symbol_reloc
+tracksRegLiveness: true
+body: |
+  bb.0:
+    $sgpr0 = S_MOV_B32 target-flags(amdgpu-abs32-lo) &external_sym, implicit-def $scc
+    S_ENDPGM 0
+...


        


More information about the llvm-commits mailing list