[PowerPC][Future] Remove redundant r2 save and restore for indirect call
authorVictor Huang <wei.huang@ibm.com>
Wed, 22 Apr 2020 15:55:34 +0000 (10:55 -0500)
committerVictor Huang <wei.huang@ibm.com>
Wed, 22 Apr 2020 17:05:51 +0000 (12:05 -0500)
commit02141a17aea0603b89baee14febea6a3b89474d1
tree5b59616f73742f9efeafe8adf9cee85ff7edf6ad
parent6bec6a97552d939e4fb13165bd4a5440d908c6c0
[PowerPC][Future] Remove redundant r2 save and restore for indirect call

Currently an indirect call produces the following sequence on PCRelative mode:

extern void function( );
extern void (*ptrfunc) ( );

void g() {
    ptrfunc=function;
}

void f() {
    (*ptrfunc) ( );
}

Producing

paddi 3, 0, .LC0@PCREL, 1
ld 3, 0(3)
std 2, 24(1)
ld 12, 0(3)
mtctr 12
bctrl
ld 2, 24(1)

Though the caller does not use or preserve r2, it is still saved and restored
across a function call. This patch is added to remove these redundant save and
restores for indirect calls.

Differential Revision: https://reviews.llvm.org/D77749
llvm/lib/Target/PowerPC/PPCISelLowering.cpp
llvm/test/CodeGen/PowerPC/pcrel-call-linkage-with-calls.ll
llvm/test/CodeGen/PowerPC/pcrel-got-indirect.ll
llvm/test/CodeGen/PowerPC/pcrel-indirect-call.ll [new file with mode: 0644]