From 687b83ceabafe81970cd4639e7f0c89036402081 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 5 Dec 2020 23:13:28 -0800 Subject: [PATCH] [X86FastISel] Fix MO_GOTPCREL GlobalValue reference in static relocation model This fixes the bug referenced by 5582a7987662a92eda5d883b88fc4586e755acf5 which was exposed by 961f31d8ad14c66829991522d73e14b5a96ff6d4. With this change, `movq src@GOTPCREL, %rcx` => `movq src@GOTPCREL(%rip), %rcx` --- llvm/lib/Target/X86/X86FastISel.cpp | 2 +- llvm/test/CodeGen/X86/fast-isel-mem.ll | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Target/X86/X86FastISel.cpp b/llvm/lib/Target/X86/X86FastISel.cpp index a8db3d4..caf1581 100644 --- a/llvm/lib/Target/X86/X86FastISel.cpp +++ b/llvm/lib/Target/X86/X86FastISel.cpp @@ -784,7 +784,7 @@ bool X86FastISel::handleConstantAddresses(const Value *V, X86AddressMode &AM) { RC = &X86::GR32RegClass; } - if (Subtarget->isPICStyleRIPRel()) + if (Subtarget->isPICStyleRIPRel() || GVFlags == X86II::MO_GOTPCREL) StubAM.Base.Reg = X86::RIP; LoadReg = createResultReg(RC); diff --git a/llvm/test/CodeGen/X86/fast-isel-mem.ll b/llvm/test/CodeGen/X86/fast-isel-mem.ll index 3f1d9ca..42f2101 100644 --- a/llvm/test/CodeGen/X86/fast-isel-mem.ll +++ b/llvm/test/CodeGen/X86/fast-isel-mem.ll @@ -1,7 +1,8 @@ ; RUN: llc < %s -fast-isel -mtriple=i386-apple-darwin -mcpu=generic | FileCheck %s ; RUN: llc < %s -fast-isel -mtriple=i386-apple-darwin -mcpu=atom | FileCheck -check-prefix=ATOM %s +; RUN: llc < %s -fast-isel -fast-isel-abort=3 -mtriple=x86_64 | FileCheck -check-prefix=ELF64 %s -@src = external global i32 +@src = external dso_preemptable global i32 ; rdar://6653118 define i32 @loadgv() nounwind { @@ -26,6 +27,14 @@ entry: ; ATOM: movl %eax, (%ecx) ; ATOM: ret +;; dso_preemptable src is loaded via GOT indirection. +; ELF64-LABEL: loadgv: +; ELF64: movq src@GOTPCREL(%rip), %rcx +; ELF64-NEXT: movl (%rcx), %eax +; ELF64-NEXT: addl (%rcx), %eax +; ELF64-NEXT: movl %eax, (%rcx) +; ELF64-NEXT: retq + } %stuff = type { i32 (...)** } -- 2.7.4