[lld] [lld][LoongArch] GOT indirection to PC relative optimization (PR #123743)

Zhaoxin Yang via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 28 23:56:59 PDT 2025


================
@@ -1222,6 +1243,30 @@ RelExpr LoongArch::adjustTlsExpr(RelType type, RelExpr expr) const {
   return expr;
 }
 
+static bool pairForGotRels(ArrayRef<Relocation> relocs) {
+  // Check if R_LARCH_GOT_PC_HI20 and R_LARCH_GOT_PC_LO12 always appear in
+  // pairs.
+  size_t i = 0;
+  const size_t size = relocs.size();
+  for (; i != size; ++i) {
+    if (relocs[i].type == R_LARCH_GOT_PC_HI20) {
+      if (i + 1 < size && relocs[i + 1].type == R_LARCH_GOT_PC_LO12) {
+        ++i;
+        continue;
+      }
+      if (relaxable(relocs, i) && i + 2 < size &&
+          relocs[i + 2].type == R_LARCH_GOT_PC_LO12) {
+        i += 2;
+        continue;
+      }
----------------
ylzsx wrote:

In fact, I believe that test "loongarch-relax-pc-hi20-lo12.s" has already covered this case.

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


More information about the llvm-commits mailing list