Page MenuHomePhabricator

[InlineASM][x86] Fix call external function in pic
AbandonedPublic

Authored by xiangzhangllvm on Aug 13 2021, 3:20 AM.

Details

Summary

This is a back end fix for https://reviews.llvm.org/D107523 [[Inline asm] Correct the constrain for function call in inline asm]
llvm-dev link: https://lists.llvm.org/pipermail/llvm-dev/2021-August/152144.html

The following code will generate one more time load for “sincos” with cmd “clang -fasm-blocks t.c -fpic -S -emit-llvm” + “llc t.ll”
t.c:

1 extern void sincos ();
2 void foo (){
3    __asm{
4    call  sincos
5    ret };
6 }

t.ll:

 1 define void @foo() #0 {
 2 entry:
 3   call void asm sideeffect inteldialect "call qword ptr ${0:P}\0A\09ret", "*m,~{dirflag},~{fpsr},~{flags}"(void (...)* @sincos) #2, !srcloc !5
4   ret void
5 }

t.s:

1         movq    sincos@GOTPCREL(%rip), %rax        // now the rax has been the function address  “sincos”
2 #APP
3       callq   *(%rax)                           //  the call should directly read the %rax, should not “load” it again, it should be “callq *%rax” or better code “call sincos@plt”
4        retq
5 #NO_APP

Diff Detail

Unit TestsFailed

TimeTest
60 msx64 debian > Clang.CodeGen::ms-inline-asm-functions.c
Script: -- : 'RUN: at line 2'; /var/lib/buildkite-agent/builds/llvm-project/build/bin/clang -cc1 -internal-isystem /var/lib/buildkite-agent/builds/llvm-project/build/lib/clang/14.0.0/include -nostdsysteminc /var/lib/buildkite-agent/builds/llvm-project/clang/test/CodeGen/ms-inline-asm-functions.c -triple i386-pc-windows-msvc -fms-extensions -S -o - | /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck /var/lib/buildkite-agent/builds/llvm-project/clang/test/CodeGen/ms-inline-asm-functions.c
70 msx64 debian > LLVM.CodeGen/X86::semantic-interposition-asm.ll
Script: -- : 'RUN: at line 2'; /var/lib/buildkite-agent/builds/llvm-project/build/bin/llc -mtriple=x86_64 -relocation-model=static < /var/lib/buildkite-agent/builds/llvm-project/llvm/test/CodeGen/X86/semantic-interposition-asm.ll | /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck --check-prefixes=COMMON,STATIC /var/lib/buildkite-agent/builds/llvm-project/llvm/test/CodeGen/X86/semantic-interposition-asm.ll
70 msx64 windows > Clang.CodeGen::ms-inline-asm-functions.c
Script: -- : 'RUN: at line 2'; c:\ws\w5\llvm-project\premerge-checks\build\bin\clang.exe -cc1 -internal-isystem c:\ws\w5\llvm-project\premerge-checks\build\lib\clang\14.0.0\include -nostdsysteminc C:\ws\w5\llvm-project\premerge-checks\clang\test\CodeGen\ms-inline-asm-functions.c -triple i386-pc-windows-msvc -fms-extensions -S -o - | c:\ws\w5\llvm-project\premerge-checks\build\bin\filecheck.exe C:\ws\w5\llvm-project\premerge-checks\clang\test\CodeGen\ms-inline-asm-functions.c
130 msx64 windows > LLVM.CodeGen/X86::semantic-interposition-asm.ll
Script: -- : 'RUN: at line 2'; c:\ws\w5\llvm-project\premerge-checks\build\bin\llc.exe -mtriple=x86_64 -relocation-model=static < C:\ws\w5\llvm-project\premerge-checks\llvm\test\CodeGen\X86\semantic-interposition-asm.ll | c:\ws\w5\llvm-project\premerge-checks\build\bin\filecheck.exe --check-prefixes=COMMON,STATIC C:\ws\w5\llvm-project\premerge-checks\llvm\test\CodeGen\X86\semantic-interposition-asm.ll

Event Timeline

xiangzhangllvm created this revision.Aug 13 2021, 3:20 AM
xiangzhangllvm requested review of this revision.Aug 13 2021, 3:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 13 2021, 3:20 AM
xiangzhangllvm edited the summary of this revision. (Show Details)Aug 13 2021, 3:21 AM
xiangzhangllvm edited the summary of this revision. (Show Details)Aug 14 2021, 3:49 AM
xiangzhangllvm abandoned this revision.Aug 24 2021, 7:00 PM