diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 8637d0658c2c90..15ff3988368036 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 := + // - // 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 - // 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 5fd1a962af467f..18f9d97c4a876d 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