Skip to content

Commit d19616f

Browse files
authored
[llvm] Allow GOTPCREL replacements for negative offsets (#72308)
1 parent 5c22b90 commit d19616f

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3513,12 +3513,7 @@ static void handleIndirectSymViaGOTPCRel(AsmPrinter &AP, const MCExpr **ME,
35133513
//
35143514
// gotpcrelcst := <offset from @foo base> + <cst>
35153515
//
3516-
// If gotpcrelcst is positive it means that we can safely fold the pc rel
3517-
// displacement into the GOTPCREL. We can also can have an extra offset <cst>
3518-
// if the target knows how to encode it.
35193516
int64_t GOTPCRelCst = Offset + MV.getConstant();
3520-
if (GOTPCRelCst < 0)
3521-
return;
35223517
if (!AP.getObjFileLowering().supportGOTPCRelWithOffset() && GOTPCRelCst != 0)
35233518
return;
35243519

llvm/test/MC/MachO/cstexpr-gotpcrel-64.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,16 @@ define void @foo() {
9999
; X86-NOGOT-EQUIV-LABEL: _c:
100100
; X86-NOGOT-EQUIV: .quad _b
101101
@c = global ptr @b
102+
103+
; X86-LABEL: table_with_negative_offset:
104+
; X86-NEXT: .long _a@GOTPCREL+4294967292
105+
@table_with_negative_offset = dso_local unnamed_addr constant [3 x i32] [
106+
i32 trunc (
107+
i64 sub (
108+
i64 ptrtoint (ptr @b to i64),
109+
i64 ptrtoint (ptr getelementptr inbounds ([3 x i32], ptr @table_with_negative_offset, i32 0, i32 2) to i64)
110+
)
111+
to i32),
112+
i32 0,
113+
i32 0
114+
], align 4

0 commit comments

Comments
 (0)