Skip to content

Commit 86eaf60

Browse files
authored
[X86] Refine X86DAGToDAGISel::isSExtAbsoluteSymbolRef() (#76191)
We just need to check if the global is large or not. In the kernel code model, globals are in the negative 2GB of the address space, so globals can be a sign extended 32-bit immediate. In other code models, small globals are in the low 2GB of the address space, so sign extending them is equivalent to zero extending them.
1 parent cd05ade commit 86eaf60

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

llvm/lib/Target/X86/X86ISelDAGToDAG.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3188,12 +3188,16 @@ bool X86DAGToDAGISel::isSExtAbsoluteSymbolRef(unsigned Width, SDNode *N) const {
31883188
if (!GA)
31893189
return false;
31903190

3191-
std::optional<ConstantRange> CR = GA->getGlobal()->getAbsoluteSymbolRange();
3192-
if (!CR)
3193-
return Width == 32 && TM.getCodeModel() == CodeModel::Small;
3194-
3195-
return CR->getSignedMin().sge(-1ull << Width) &&
3196-
CR->getSignedMax().slt(1ull << Width);
3191+
auto *GV = GA->getGlobal();
3192+
std::optional<ConstantRange> CR = GV->getAbsoluteSymbolRange();
3193+
if (CR)
3194+
return CR->getSignedMin().sge(-1ull << Width) &&
3195+
CR->getSignedMax().slt(1ull << Width);
3196+
// In the kernel code model, globals are in the negative 2GB of the address
3197+
// space, so globals can be a sign extended 32-bit immediate.
3198+
// In other code models, small globals are in the low 2GB of the address
3199+
// space, so sign extending them is equivalent to zero extending them.
3200+
return Width == 32 && !TM.isLargeGlobalValue(GV);
31973201
}
31983202

31993203
X86::CondCode X86DAGToDAGISel::getCondFromNode(SDNode *N) const {

llvm/test/CodeGen/X86/relocimm-small-model.ll renamed to llvm/test/CodeGen/X86/relocimm-code-model.ll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
; RUN: llc < %s | FileCheck %s --check-prefix=CHECK-SMALL
2-
; RUN: llc --code-model=medium < %s | FileCheck %s --check-prefix=CHECK-MEDIUM
2+
; RUN: llc --code-model=medium -large-data-threshold=100 < %s | FileCheck %s --check-prefix=CHECK-SMALL
3+
; RUN: llc --code-model=medium < %s | FileCheck %s --check-prefix=CHECK-LARGE
4+
; RUN: llc --code-model=large -large-data-threshold=100 < %s | FileCheck %s --check-prefix=CHECK-SMALL
5+
; RUN: llc --code-model=large < %s | FileCheck %s --check-prefix=CHECK-LARGE
6+
; RUN: llc --code-model=kernel < %s | FileCheck %s --check-prefix=CHECK-SMALL
37

48
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
59
target triple = "x86_64-unknown-linux-gnu"
@@ -9,7 +13,7 @@ target triple = "x86_64-unknown-linux-gnu"
913
declare void @f()
1014

1115
define void @foo(i64 %b) {
12-
; CHECK-MEDIUM: cmpq %rax, %rdi
16+
; CHECK-LARGE: cmpq %rax, %rdi
1317
; CHECK-SMALL: cmpq $a, %rdi
1418
entry:
1519
%cmp = icmp eq i64 %b, ptrtoint (ptr @a to i64)

0 commit comments

Comments
 (0)