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

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 14 12:31:10 PST 2023


Author: PiJoules
Date: 2023-11-14T12:31:06-08:00
New Revision: d19616fc66008ad128ecd21536c6e52992bea4e6

URL: https://github.com/llvm/llvm-project/commit/d19616fc66008ad128ecd21536c6e52992bea4e6
DIFF: https://github.com/llvm/llvm-project/commit/d19616fc66008ad128ecd21536c6e52992bea4e6.diff

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

Added: 
    

Modified: 
    llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/test/MC/MachO/cstexpr-gotpcrel-64.ll

Removed: 
    


################################################################################
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


        


More information about the llvm-commits mailing list