[llvm] bef6841 - [X86][FastISel] Support materializing floating-point constants for large code model & PIC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 23 08:36:25 PDT 2020


Author: Fangrui Song
Date: 2020-08-23T08:36:18-07:00
New Revision: bef684154d400df5cfd935a18ed7312a582fe5eb

URL: https://github.com/llvm/llvm-project/commit/bef684154d400df5cfd935a18ed7312a582fe5eb
DIFF: https://github.com/llvm/llvm-project/commit/bef684154d400df5cfd935a18ed7312a582fe5eb.diff

LOG: [X86][FastISel] Support materializing floating-point constants for large code model & PIC

The following program miscompiles because rL216012 added static
relocation model support but not for PIC.

```
// clang -fpic -mcmodel=large -O0 a.cc
double foo() { return 42.0; }
```

This patch adds PIC support.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D86024

Added: 
    

Modified: 
    llvm/lib/Target/X86/X86FastISel.cpp
    llvm/test/CodeGen/X86/fast-isel-constpool.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/X86FastISel.cpp b/llvm/lib/Target/X86/X86FastISel.cpp
index b305940139c0..f0bd821f77d0 100644
--- a/llvm/lib/Target/X86/X86FastISel.cpp
+++ b/llvm/lib/Target/X86/X86FastISel.cpp
@@ -3793,7 +3793,7 @@ unsigned X86FastISel::X86MaterializeFP(const ConstantFP *CFP, MVT VT) {
       .addConstantPoolIndex(CPI, 0, OpFlag);
     MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
                                       TII.get(Opc), ResultReg);
-    addDirectMem(MIB, AddrReg);
+    addRegReg(MIB, AddrReg, false, PICBase, false);
     MachineMemOperand *MMO = FuncInfo.MF->getMachineMemOperand(
         MachinePointerInfo::getConstantPool(*FuncInfo.MF),
         MachineMemOperand::MOLoad, DL.getPointerSize(), Alignment);

diff  --git a/llvm/test/CodeGen/X86/fast-isel-constpool.ll b/llvm/test/CodeGen/X86/fast-isel-constpool.ll
index f1aacc7ceab4..a2ce3d58e43b 100644
--- a/llvm/test/CodeGen/X86/fast-isel-constpool.ll
+++ b/llvm/test/CodeGen/X86/fast-isel-constpool.ll
@@ -1,6 +1,7 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
 ; RUN: llc -mtriple=x86_64-apple-darwin -fast-isel -code-model=small < %s | FileCheck %s
 ; RUN: llc -mtriple=x86_64-apple-darwin -fast-isel -code-model=large < %s | FileCheck %s --check-prefix=LARGE
+; RUN: llc -mtriple=x86_64 -fast-isel -code-model=large -relocation-model=pic < %s | FileCheck %s --check-prefix=LARGE_PIC
 ; RUN: llc -mtriple=x86_64-apple-darwin -fast-isel -code-model=small -mattr=avx < %s | FileCheck %s --check-prefix=AVX
 ; RUN: llc -mtriple=x86_64-apple-darwin -fast-isel -code-model=large -mattr=avx < %s | FileCheck %s --check-prefix=LARGE_AVX
 ; RUN: llc -mtriple=x86_64-apple-darwin -fast-isel -code-model=small -mattr=avx512f < %s | FileCheck %s --check-prefix=AVX
@@ -25,6 +26,16 @@ define float @constpool_float(float %x) {
 ; LARGE-NEXT:    addss (%rax), %xmm0
 ; LARGE-NEXT:    retq
 ;
+; LARGE_PIC-LABEL: constpool_float:
+; LARGE_PIC:       # %bb.0:
+; LARGE_PIC-NEXT:  .L0$pb:
+; LARGE_PIC-NEXT:    leaq .L0$pb(%rip), %rax
+; LARGE_PIC-NEXT:    movabsq $_GLOBAL_OFFSET_TABLE_-.L0$pb, %rcx
+; LARGE_PIC-NEXT:    addq %rax, %rcx
+; LARGE_PIC-NEXT:    movabsq $.LCPI0_0 at GOTOFF, %rax
+; LARGE_PIC-NEXT:    addss (%rax,%rcx), %xmm0
+; LARGE_PIC-NEXT:    retq
+;
 ; AVX-LABEL: constpool_float:
 ; AVX:       ## %bb.0:
 ; AVX-NEXT:    vmovss {{.*#+}} xmm1 = mem[0],zero,zero,zero


        


More information about the llvm-commits mailing list