[all-commits] [llvm/llvm-project] 570871: [X86] Don't convert local function foo in the same...
Fangrui Song via All-commits
all-commits at lists.llvm.org
Mon Sep 30 22:46:29 PDT 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 570871eab530524e98781238a48897a881834211
https://github.com/llvm/llvm-project/commit/570871eab530524e98781238a48897a881834211
Author: Fangrui Song <i at maskray.me>
Date: 2024-09-30 (Mon, 30 Sep 2024)
Changed paths:
M llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
M llvm/test/CodeGen/X86/fold-add.ll
Log Message:
-----------
[X86] Don't convert local function foo in the same section to foo(%rip) when the offset is near INT32_MIN
```
define internal void @foo() {
ret void
}
define i64 @main() {
ret i64 add (i64 ptrtoint (ptr @foo to i64), i64 -2147483626)
}
```
When `foo` is a local symbol, `foo` and `main` are in the same section,
and `offset` is near INT32_MIN, referencing `foo+offset` in `main` with
RIP-relative addressing needs `leaq .text+offset1(%rip), %rax` where
`offset1 < offset`, and `offset1` might underflow.
(https://discourse.llvm.org/t/arithmetic-referencing-dso-local-function-causes-compilation-error-on-linux-x64/80033):
Don't use RIP-relative addressing if the negative offset is near
INT32_MIN. Arbitrarily reuse the magic number in isOffsetSuitableForCodeModel to
guard against the edge case when `address(current_instruction)-foo < 4GiB-16MiB`.
If the difference is larger than 4GiB-16MiB, `ret i64 add (i64 ptrtoint
(ptr @foo to i64), i64 -2**32+256MiB)` would still cause the assembly
issue, such cases are unrealistic.
Pull Request: https://github.com/llvm/llvm-project/pull/98438
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list