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

Phoebe Wang via llvm-commits llvm-commits at lists.llvm.org
Sun May 11 17:47:33 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())
----------------
phoebewang wrote:

Why operand 0 instead of the operand uses the same register?

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


More information about the llvm-commits mailing list