[llvm] [llvm] Allow GOTPCREL replacements for negative offsets (PR #72308)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 14 12:29:30 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mc

Author: None (PiJoules)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/72308.diff


2 Files Affected:

- (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (-5) 
- (modified) llvm/test/MC/MachO/cstexpr-gotpcrel-64.ll (+13) 


``````````diff
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 8637d0658c2c905..15ff39883680369 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -3513,12 +3513,7 @@ static void handleIndirectSymViaGOTPCRel(AsmPrinter &AP, const MCExpr **ME,
   //
   //    gotpcrelcst := <offset from @foo base> + <cst>
   //
-  // If gotpcrelcst is positive it means that we can safely fold the pc rel
-  // displacement into the GOTPCREL. We can also can have an extra offset <cst>
-  // if the target knows how to encode it.
   int64_t GOTPCRelCst = Offset + MV.getConstant();
-  if (GOTPCRelCst < 0)
-    return;
   if (!AP.getObjFileLowering().supportGOTPCRelWithOffset() && GOTPCRelCst != 0)
     return;
 
diff --git a/llvm/test/MC/MachO/cstexpr-gotpcrel-64.ll b/llvm/test/MC/MachO/cstexpr-gotpcrel-64.ll
index 5fd1a962af467fe..18f9d97c4a876d9 100644
--- a/llvm/test/MC/MachO/cstexpr-gotpcrel-64.ll
+++ b/llvm/test/MC/MachO/cstexpr-gotpcrel-64.ll
@@ -99,3 +99,16 @@ define void @foo() {
 ; X86-NOGOT-EQUIV-LABEL: _c:
 ; X86-NOGOT-EQUIV:   .quad _b
 @c = global ptr @b
+
+; X86-LABEL: table_with_negative_offset:
+; X86-NEXT:    .long   _a at GOTPCREL+4294967292
+ at table_with_negative_offset = dso_local unnamed_addr constant [3 x i32] [
+  i32 trunc (
+    i64 sub (
+      i64 ptrtoint (ptr @b to i64),
+      i64 ptrtoint (ptr getelementptr inbounds ([3 x i32], ptr @table_with_negative_offset, i32 0, i32 2) to i64)
+    )
+    to i32),
+  i32 0,
+  i32 0
+], align 4

``````````

</details>


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


More information about the llvm-commits mailing list