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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 13 additions & 0 deletions llvm/test/MC/MachO/cstexpr-gotpcrel-64.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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