This is an archive of the discontinued LLVM Phabricator instance.

[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

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