Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[llvm] Allow GOTPCREL replacements for negative offsets #72308

Merged
merged 1 commit into from
Nov 14, 2023

Conversation

PiJoules
Copy link
Contributor

No description provided.

@llvmbot llvmbot added the mc Machine (object) code label Nov 14, 2023
@llvmbot
Copy link
Member

llvmbot commented Nov 14, 2023

@llvm/pr-subscribers-mc

Author: None (PiJoules)

Changes

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 --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@GOTPCREL+4294967292
+@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

@PiJoules PiJoules merged commit d19616f into llvm:main Nov 14, 2023
3 of 4 checks passed
@PiJoules PiJoules deleted the allow-gotpcrel-negative-offsets branch November 14, 2023 21:31
zahiraam pushed a commit to zahiraam/llvm-project that referenced this pull request Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mc Machine (object) code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants