[llvm] [X86][APX] Fix issues of suppressing APX for relocation (PR #139285)

Shengchen Kan via llvm-commits llvm-commits at lists.llvm.org
Sun May 11 21:46:38 PDT 2025


================
@@ -79,11 +78,32 @@ static void suppressEGPRRegClass(MachineFunction &MF, MachineInstr &MI,
   MRI->setRegClass(Reg, NewRC);
 }
 
+// Suppress EGPR in operand 0 of uses to avoid APX relocation types emitted. The
+// register in operand 0 of instruction with relocation may be replaced with
+// operand 0 of uses which may be EGPR. That may lead to emit APX relocation
+// types which breaks the backward compatibility with builtin linkers on
+// existing OS. For example, the register in operand 0 of instruction with
+// relocation is used in PHI instruction, and it may be replaced with operand 0
+// of PHI instruction after PHI elimination and Machine Copy Propagation pass.
+static void suppressEGPRRegClassInRegAndUses(MachineRegisterInfo *MRI,
+                                             MachineInstr &MI,
+                                             const X86Subtarget &ST,
+                                             unsigned int OpNum) {
+  suppressEGPRRegClass(MRI, MI, ST, OpNum);
+  Register Reg = MI.getOperand(OpNum).getReg();
+  for (MachineInstr &Use : MRI->use_instructions(Reg)) {
+    const unsigned UseOpNum = 0;
+    if (Use.getOperand(UseOpNum).isReg())
----------------
KanRobert wrote:

IIRC, for the existing optimizations and cg, the common register class will be used, aka. gr64 + gr64_norex2  -> gr64_norex2. If we find this problem here, probably it's brought by the APX suppressing patches. 

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


More information about the llvm-commits mailing list