Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
[X86] Refine X86DAGToDAGISel::isSExtAbsoluteSymbolRef() (#76191)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aeubanks authored Jan 19, 2024
1 parent cd05ade commit 86eaf60
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
16 changes: 10 additions & 6 deletions llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3188,12 +3188,16 @@ bool X86DAGToDAGISel::isSExtAbsoluteSymbolRef(unsigned Width, SDNode *N) const {
if (!GA)
return false;

std::optional<ConstantRange> CR = GA->getGlobal()->getAbsoluteSymbolRange();
if (!CR)
return Width == 32 && TM.getCodeModel() == CodeModel::Small;

return CR->getSignedMin().sge(-1ull << Width) &&
CR->getSignedMax().slt(1ull << Width);
auto *GV = GA->getGlobal();
std::optional<ConstantRange> CR = GV->getAbsoluteSymbolRange();
if (CR)
return CR->getSignedMin().sge(-1ull << Width) &&
CR->getSignedMax().slt(1ull << Width);
// 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.
return Width == 32 && !TM.isLargeGlobalValue(GV);
}

X86::CondCode X86DAGToDAGISel::getCondFromNode(SDNode *N) const {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
; RUN: llc < %s | FileCheck %s --check-prefix=CHECK-SMALL
; RUN: llc --code-model=medium < %s | FileCheck %s --check-prefix=CHECK-MEDIUM
; RUN: llc --code-model=medium -large-data-threshold=100 < %s | FileCheck %s --check-prefix=CHECK-SMALL
; RUN: llc --code-model=medium < %s | FileCheck %s --check-prefix=CHECK-LARGE
; RUN: llc --code-model=large -large-data-threshold=100 < %s | FileCheck %s --check-prefix=CHECK-SMALL
; RUN: llc --code-model=large < %s | FileCheck %s --check-prefix=CHECK-LARGE
; RUN: llc --code-model=kernel < %s | FileCheck %s --check-prefix=CHECK-SMALL

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

define void @foo(i64 %b) {
; CHECK-MEDIUM: cmpq %rax, %rdi
; CHECK-LARGE: cmpq %rax, %rdi
; CHECK-SMALL: cmpq $a, %rdi
entry:
%cmp = icmp eq i64 %b, ptrtoint (ptr @a to i64)
Expand Down

0 comments on commit 86eaf60

Please sign in to comment.