[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
Mon Nov 6 20:31:25 PST 2023


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 3c11ac51180ffebe7d71b8773ec03275aec2eb7a eac1c19a52b089c1f4175403b4c9bbfba0e839a1 -- llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index d2e30adad..02a2d4d88 100644
--- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -68,8 +68,8 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/Process.h"
-#include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/Threading.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/TargetParser/Triple.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
@@ -1597,10 +1597,9 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
     unsigned OpNum = IsMIADDI8 ? 2 : 1;
     const MachineOperand &MO = MI->getOperand(OpNum);
     if ((MO.getTargetFlags() & PPCII::MO_TPREL_FLAG) != 0) {
-      assert(
-          Subtarget->hasAIXSmallLocalExecTLS() &&
-          "addi, or load/stores 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
@@ -1645,8 +1644,8 @@ const MCExpr *PPCAsmPrinter::getAdjustedLocalExecExpr(const MachineOperand &MO,
          "Only local-exec accesses are handled!");
   MCSymbolRefExpr::VariantKind RefKind = MCSymbolRefExpr::VK_PPC_AIX_TLSLE;
 
-  const MCExpr *Expr = MCSymbolRefExpr::create(getSymbol(GValue), RefKind,
-                                               OutContext);
+  const MCExpr *Expr =
+      MCSymbolRefExpr::create(getSymbol(GValue), RefKind, OutContext);
 
   bool IsGlobalADeclaration = GValue->isDeclarationForLinker();
   // Find the GlobalVariable that corresponds to the particular TLS variable
@@ -1666,9 +1665,8 @@ const MCExpr *PPCAsmPrinter::getAdjustedLocalExecExpr(const MachineOperand &MO,
   // For when TLS variables are extern, this is safe to do because we can
   // assume that the address of extern TLS variables are zero.
   if ((FinalAddress < 32768) || IsGlobalADeclaration)
-    Expr = MCBinaryExpr::createAdd(Expr,
-                                   MCConstantExpr::create(Offset, OutContext),
-                                   OutContext);
+    Expr = MCBinaryExpr::createAdd(
+        Expr, MCConstantExpr::create(Offset, OutContext), OutContext);
   else {
     // Handle the written offset for cases where:
     //   address of the TLS variable + the offset is greater than 32KB.
@@ -1680,9 +1678,10 @@ const MCExpr *PPCAsmPrinter::getAdjustedLocalExecExpr(const MachineOperand &MO,
     // [-32768,32768).
     if (FinalAddress & 0x8000)
       FinalAddress = FinalAddress - 0x10000;
-    assert((FinalAddress < 32768) || (FinalAddress >= -32768) &&
-           "Expecting the final address for local-exec TLS variables to be "
-           "between [-32768,32768)!");
+    assert((FinalAddress < 32768) ||
+           (FinalAddress >= -32768) &&
+               "Expecting the final address for local-exec TLS variables to be "
+               "between [-32768,32768)!");
     // Get the offset that is actually written out in assembly by adding back
     // the original address of the TLS variable.
     ptrdiff_t WrittenOffset = FinalAddress - TLSVarAddress;
diff --git a/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp b/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
index 1c4432017..32e0015e0 100644
--- a/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
+++ b/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
@@ -7591,8 +7591,7 @@ static void foldADDIForLocalExecAccesses(SDNode *N, SelectionDAG *DAG) {
   // This transformation is only performed if the first operand of the
   // addi is the thread pointer.
   SDValue TPRegNode = InitialADDI.getOperand(0);
-  RegisterSDNode *TPReg =
-      dyn_cast_or_null<RegisterSDNode>(TPRegNode.getNode());
+  RegisterSDNode *TPReg = dyn_cast_or_null<RegisterSDNode>(TPRegNode.getNode());
   if (!TPReg)
     return;
   if (TPReg->getReg() != Subtarget.getThreadPointerRegister())
@@ -7800,9 +7799,8 @@ void PPCDAGToDAGISel::PeepholePPC64() {
         GlobalAddressSDNode *GA = dyn_cast<GlobalAddressSDNode>(ImmOpnd);
         if (!GA)
           continue;
-        ImmOpnd = CurDAG->getTargetGlobalAddress(GA->getGlobal(), SDLoc(GA),
-                                                 MVT::i64, Offset,
-                                                 GA->getTargetFlags());
+        ImmOpnd = CurDAG->getTargetGlobalAddress(
+            GA->getGlobal(), SDLoc(GA), MVT::i64, Offset, GA->getTargetFlags());
       }
     }
 

``````````

</details>


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


More information about the llvm-commits mailing list