Skip to content

Commit c64334f

Browse files
authored
[X86][FastISel] Support medium code model in more places (#75375)
The medium code model is basically identical to the small code model except that large objects cannot be referenced with 32-bit offsets.
1 parent e065841 commit c64334f

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

llvm/lib/Target/X86/X86FastISel.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,8 @@ bool X86FastISel::handleConstantAddresses(const Value *V, X86AddressMode &AM) {
711711
// Handle constant address.
712712
if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
713713
// Can't handle alternate code models yet.
714-
if (TM.getCodeModel() != CodeModel::Small)
714+
if (TM.getCodeModel() != CodeModel::Small &&
715+
TM.getCodeModel() != CodeModel::Medium)
715716
return false;
716717

717718
// Can't handle large objects yet.
@@ -1050,7 +1051,8 @@ bool X86FastISel::X86SelectCallAddress(const Value *V, X86AddressMode &AM) {
10501051
// Handle constant address.
10511052
if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
10521053
// Can't handle alternate code models yet.
1053-
if (TM.getCodeModel() != CodeModel::Small)
1054+
if (TM.getCodeModel() != CodeModel::Small &&
1055+
TM.getCodeModel() != CodeModel::Medium)
10541056
return false;
10551057

10561058
// RIP-relative addresses can't have additional register operands.
@@ -3774,7 +3776,8 @@ unsigned X86FastISel::X86MaterializeFP(const ConstantFP *CFP, MVT VT) {
37743776

37753777
// Can't handle alternate code models yet.
37763778
CodeModel::Model CM = TM.getCodeModel();
3777-
if (CM != CodeModel::Small && CM != CodeModel::Large)
3779+
if (CM != CodeModel::Small && CM != CodeModel::Medium &&
3780+
CM != CodeModel::Large)
37783781
return 0;
37793782

37803783
// Get opcode and regclass of the output for the given load instruction.
@@ -3812,7 +3815,7 @@ unsigned X86FastISel::X86MaterializeFP(const ConstantFP *CFP, MVT VT) {
38123815
PICBase = getInstrInfo()->getGlobalBaseReg(FuncInfo.MF);
38133816
else if (OpFlag == X86II::MO_GOTOFF)
38143817
PICBase = getInstrInfo()->getGlobalBaseReg(FuncInfo.MF);
3815-
else if (Subtarget->is64Bit() && TM.getCodeModel() == CodeModel::Small)
3818+
else if (Subtarget->is64Bit() && TM.getCodeModel() != CodeModel::Large)
38163819
PICBase = X86::RIP;
38173820

38183821
// Create the load from the constant pool.
@@ -3842,8 +3845,11 @@ unsigned X86FastISel::X86MaterializeFP(const ConstantFP *CFP, MVT VT) {
38423845
}
38433846

38443847
unsigned X86FastISel::X86MaterializeGV(const GlobalValue *GV, MVT VT) {
3845-
// Can't handle alternate code models yet.
3846-
if (TM.getCodeModel() != CodeModel::Small)
3848+
// Can't handle large GlobalValues yet.
3849+
if (TM.getCodeModel() != CodeModel::Small &&
3850+
TM.getCodeModel() != CodeModel::Medium)
3851+
return 0;
3852+
if (!isa<GlobalObject>(GV) || TM.isLargeGlobalObject(cast<GlobalObject>(GV)))
38473853
return 0;
38483854

38493855
// Materialize addresses with LEA/MOV instructions.

llvm/test/CodeGen/X86/fast-isel-constpool.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
22
; RUN: llc -mtriple=x86_64-apple-darwin -fast-isel -code-model=small < %s | FileCheck %s
3+
; RUN: llc -mtriple=x86_64-apple-darwin -fast-isel -code-model=medium < %s | FileCheck %s
34
; RUN: llc -mtriple=x86_64-apple-darwin -fast-isel -code-model=large < %s | FileCheck %s --check-prefix=LARGE
45
; RUN: llc -mtriple=x86_64 -fast-isel -code-model=large -relocation-model=pic < %s | FileCheck %s --check-prefix=LARGE_PIC
56
; RUN: llc -mtriple=x86_64-apple-darwin -fast-isel -code-model=small -mattr=avx < %s | FileCheck %s --check-prefix=AVX
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=x86_64-linux-gnu -fast-isel -fast-isel-abort=3 -code-model=medium -large-data-threshold=5 < %s | FileCheck %s
3+
; RUN: llc -mtriple=x86_64-linux-gnu -fast-isel -code-model=medium -large-data-threshold=3 < %s -o /dev/null \
4+
; RUN: -pass-remarks-output=- -pass-remarks-filter=sdagisel | FileCheck %s --check-prefix=FALLBACK --implicit-check-not=missed
5+
6+
declare void @foo()
7+
8+
define void @call_foo() {
9+
; CHECK-LABEL: call_foo:
10+
; CHECK: # %bb.0:
11+
; CHECK-NEXT: pushq %rax
12+
; CHECK-NEXT: .cfi_def_cfa_offset 16
13+
; CHECK-NEXT: callq foo@PLT
14+
; CHECK-NEXT: popq %rax
15+
; CHECK-NEXT: .cfi_def_cfa_offset 8
16+
; CHECK-NEXT: retq
17+
call void @foo()
18+
ret void
19+
}
20+
21+
@g = internal global i32 42
22+
23+
; FALLBACK: FastISel missed terminator
24+
; FALLBACK: in function: g_addr
25+
26+
define ptr @g_addr() {
27+
; CHECK-LABEL: g_addr:
28+
; CHECK: # %bb.0:
29+
; CHECK-NEXT: movabsq $g, %rax
30+
; CHECK-NEXT: retq
31+
ret ptr @g
32+
}
33+
34+
; FALLBACK: FastISel missed
35+
; FALLBACK: in function: load_g
36+
37+
define i32 @load_g() {
38+
; CHECK-LABEL: load_g:
39+
; CHECK: # %bb.0:
40+
; CHECK-NEXT: movl g, %eax
41+
; CHECK-NEXT: retq
42+
%i = load i32, ptr @g
43+
ret i32 %i
44+
}

0 commit comments

Comments
 (0)