Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit b677a87

Browse files
committed
[FastISel][X86] Add large code model support for materializing floating-point constants.
In the large code model for X86 floating-point constants are placed in the constant pool and materialized by loading from it. Since the constant pool could be far away, a PC relative load might not work. Therefore we first materialize the address of the constant pool with a movabsq and then load from there the floating-point value. Fixes <rdar://problem/17674628>. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215595 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 0701e5d commit b677a87

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

lib/Target/X86/X86FastISel.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -3163,7 +3163,8 @@ unsigned X86FastISel::X86MaterializeFP(const ConstantFP *CFP, MVT VT) {
31633163
return TargetMaterializeFloatZero(CFP);
31643164

31653165
// Can't handle alternate code models yet.
3166-
if (TM.getCodeModel() != CodeModel::Small)
3166+
CodeModel::Model CM = TM.getCodeModel();
3167+
if (CM != CodeModel::Small && CM != CodeModel::Large)
31673168
return 0;
31683169

31693170
// Get opcode and regclass of the output for the given load instruction.
@@ -3219,6 +3220,21 @@ unsigned X86FastISel::X86MaterializeFP(const ConstantFP *CFP, MVT VT) {
32193220
unsigned CPI = MCP.getConstantPoolIndex(CFP, Align);
32203221
unsigned ResultReg = createResultReg(RC);
32213222

3223+
if (CM == CodeModel::Large) {
3224+
unsigned AddrReg = createResultReg(&X86::GR64RegClass);
3225+
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(X86::MOV64ri),
3226+
AddrReg)
3227+
.addConstantPoolIndex(CPI, 0, OpFlag);
3228+
MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3229+
TII.get(Opc), ResultReg);
3230+
addDirectMem(MIB, AddrReg);
3231+
MachineMemOperand *MMO = FuncInfo.MF->getMachineMemOperand(
3232+
MachinePointerInfo::getConstantPool(), MachineMemOperand::MOLoad,
3233+
TM.getSubtargetImpl()->getDataLayout()->getPointerSize(), Align);
3234+
MIB->addMemOperand(*FuncInfo.MF, MMO);
3235+
return ResultReg;
3236+
}
3237+
32223238
addConstantPoolReference(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
32233239
TII.get(Opc), ResultReg),
32243240
CPI, PICBase, OpFlag);
+20-16
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
; RUN: llc < %s -fast-isel | FileCheck %s
2-
; CHECK: LCPI0_0(%rip)
1+
; RUN: llc -mtriple=x86_64-apple-darwin -fast-isel -code-model=small < %s | FileCheck %s
2+
; RUN: llc -mtriple=x86_64-apple-darwin -fast-isel -code-model=large < %s | FileCheck %s --check-prefix=LARGE
33

4-
; Make sure fast isel uses rip-relative addressing when required.
5-
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
6-
target triple = "x86_64-apple-darwin9.0"
4+
; Make sure fast isel uses rip-relative addressing for the small code model.
5+
define float @constpool_float(float %x) {
6+
; CHECK-LABEL: constpool_float
7+
; CHECK: LCPI0_0(%rip)
78

8-
define i32 @f0(double %x) nounwind {
9-
entry:
10-
%retval = alloca i32 ; <i32*> [#uses=2]
11-
%x.addr = alloca double ; <double*> [#uses=2]
12-
store double %x, double* %x.addr
13-
%tmp = load double* %x.addr ; <double> [#uses=1]
14-
%cmp = fcmp olt double %tmp, 8.500000e-01 ; <i1> [#uses=1]
15-
%conv = zext i1 %cmp to i32 ; <i32> [#uses=1]
16-
store i32 %conv, i32* %retval
17-
%0 = load i32* %retval ; <i32> [#uses=1]
18-
ret i32 %0
9+
; LARGE-LABEL: constpool_float
10+
; LARGE: movabsq $LCPI0_0, %rax
11+
%1 = fadd float %x, 16.50e+01
12+
ret float %1
13+
}
14+
15+
define double @constpool_double(double %x) nounwind {
16+
; CHECK-LABEL: constpool_double
17+
; CHECK: LCPI1_0(%rip)
18+
19+
; LARGE-LABEL: constpool_double
20+
; LARGE: movabsq $LCPI1_0, %rax
21+
%1 = fadd double %x, 8.500000e-01
22+
ret double %1
1923
}

0 commit comments

Comments
 (0)