[llvm] [PowerPC] 32-bit large code-model support for toc-data (PR #85129)

Chen Zheng via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 9 17:58:52 PDT 2024


================
@@ -1272,25 +1284,33 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
     EmitToStreamer(*OutStreamer, TmpInst);
     return;
   }
+  case PPC::ADDItocL:
   case PPC::ADDItocL8: {
-    // Transform %xd = ADDItocL8 %xs, @sym
+    // Transform %xd = ADDItocL %xs, @sym
     LowerPPCMachineInstrToMCInst(MI, TmpInst, *this);
 
-    // Change the opcode to ADDI8. If the global address is external, then
-    // generate a TOC entry and reference that. Otherwise, reference the
-    // symbol directly.
-    TmpInst.setOpcode(PPC::ADDI8);
+    unsigned Op = MI->getOpcode();
+
+    // Change the opcode to load address for tocdata
+    TmpInst.setOpcode(Op == PPC::ADDItocL8 ? PPC::ADDI8 : PPC::LA);
 
     const MachineOperand &MO = MI->getOperand(2);
-    assert((MO.isGlobal() || MO.isCPI()) && "Invalid operand for ADDItocL8.");
+    if (Op == PPC::ADDItocL8)
+      assert((MO.isGlobal() || MO.isCPI()) && "Invalid operand for ADDItocL8.");
+    else
+      assert(MO.isGlobal() && "Invalid operand for ADDItocL.");
----------------
chenzheng1030 wrote:

Code format:
```
assert((Op == PPC::ADDItocL8) ? (MO.isGlobal() || MO.isCPI()) : MO.isGlobal() && "Invalid operand for ADDItocL8.");
```

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


More information about the llvm-commits mailing list