[llvm] [AIX][TLS] Optimize the -maix-small-local-exec-tls local-exec access sequence for non-zero offsets (PR #71485)

via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 9 08:44:14 PST 2023


================
@@ -1534,17 +1570,54 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
     EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::EnforceIEIO));
     return;
   }
+  case PPC::LBZ:
+  case PPC::LBZ8:
+  case PPC::LHA:
+  case PPC::LHA8:
+  case PPC::LHZ:
+  case PPC::LHZ8:
+  case PPC::LWZ:
+  case PPC::LWZ8:
+  case PPC::STB:
+  case PPC::STB8:
+  case PPC::STH:
+  case PPC::STH8:
+  case PPC::STW:
+  case PPC::STW8:
+  case PPC::LFS:
+  case PPC::STFS:
+  case PPC::LFD:
+  case PPC::STFD:
   case PPC::ADDI8: {
-    // The faster non-TOC-based local-exec sequence is represented by `addi`
-    // with an immediate operand having the MO_TPREL_FLAG. Such an instruction
-    // does not otherwise arise.
-    const MachineOperand &MO = MI->getOperand(2);
+    // A faster non-TOC-based local-exec sequence is represented by `addi`
+    // or a load/store instruction (that directly loads or stores off of the
+    // thread pointer) with an immediate operand having the MO_TPREL_FLAG.
+    // Such instructions do not otherwise arise.
+    bool IsMIADDI8 = MI->getOpcode() == PPC::ADDI8;
+    unsigned OpNum = IsMIADDI8 ? 2 : 1;
+    const MachineOperand &MO = MI->getOperand(OpNum);
     if ((MO.getTargetFlags() & PPCII::MO_TPREL_FLAG) != 0) {
-      assert(
-          Subtarget->hasAIXSmallLocalExecTLS() &&
-          "addi with thread-pointer only expected with local-exec small TLS");
+      assert(Subtarget->hasAIXSmallLocalExecTLS() &&
+             "addi, or load/stores with thread-pointer only expected with "
+             "local-exec small TLS");
+
+      int64_t Offset = MO.getOffset();
+      // Non-zero offsets for loads/stores require special handling and are
+      // handled here. For `addi`, all offsets are handled here.
+      if (!Offset && !IsMIADDI8)
----------------
stephenpeckham wrote:

Same comment as above:  I would use `if (Offset || IsMIADDI8) {...`

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


More information about the llvm-commits mailing list