Skip to content

Commit

Permalink
[llvm] Allow GOTPCREL replacements for negative offsets (llvm#72308)
Browse files Browse the repository at this point in the history
  • Loading branch information
PiJoules authored and zahiraam committed Nov 20, 2023
1 parent 48a223c commit e0718d2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
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

0 comments on commit e0718d2

Please sign in to comment.