llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

"-mlongcall" is not effective in ppc64

Open ukalappa-mips opened this issue 4 years ago • 9 comments

For the following code ,

#include<stdlib.h>
#include<math.h>
int callcos(int loops)
{
    int i;
    double x = 0.0;

    for (i = 0; i < loops; ++i) {
        x += cos(2.44);
     printf("Test "); 
     
    }   
    return(x < 100.4);
}

and command-line used

clang -mcpu=e6500 -mno-altivec -D_VX_CPU=_VX_PPCE6500 -mlong-double-64 -mhard-float -mabi=elfv2 -D__ppc -D__ppc__ -m64 -D__ppc64__  --target=ppc64 -mcmodel=medium -fno-strict-aliasing -ftls-model=local-exec -fno-builtin -fno-unwind-tables -fno-asynchronous-unwind-tables -nostdlibinc -nostdinc++  -Wno-unused-command-line-argument  -mlongcall -S   

call to cos was relatively even used "-mlongcall". like

addis 3, 2, .LCPI0_2@toc@ha
lfd 1, .LCPI0_2@toc@l(3)
bl cos 
nop 

and not the case for printf like

addis 3, 2, .L.str@toc@ha
addi 3, 3, .L.str@toc@l
addis 4, 2, .LC0@toc@ha
ld 4, .LC0@toc@l(4)
mr 12, 4
mtctr 4
bctrl

We think it's the llvm issue (inconsistent) and needs to be fixed .

ukalappa-mips avatar Apr 18 '22 09:04 ukalappa-mips

@llvm/issue-subscribers-backend-powerpc

llvmbot avatar Apr 18 '22 13:04 llvmbot

Can you try removing -fno-builtin?

; With '-fno-builtin'
addis 3, 2, .LCPI0_2@toc@ha
lfd 1, .LCPI0_2@toc@l(3)
bl cos
nop
lfd 0, 104(31)
fadd 0, 0, 1
stfd 0, 104(31)
addis 3, 2, .L.str@toc@ha
addi 3, 3, .L.str@toc@l
bl printf
nop

; Without '-fno-builtin'
mr	3, 2
std 3, 24(1)
addis 3, 2, .LC0@toc@ha
ld 3, .LC0@toc@l(3)
addis 4, 2, .LCPI0_2@toc@ha
addi 4, 4, .LCPI0_2@toc@l
lfd 1, 0(4)
mr	12, 3
mtctr 3
bctrl
ld 2, 24(1)
lfd 0, 104(31)
fadd 0, 0, 1
stfd 0, 104(31)
mr	3, 2
std 3, 24(1)
addis 3, 2, .L.str@toc@ha
addi 3, 3, .L.str@toc@l
addis 4, 2, .LC1@toc@ha
ld 4, .LC1@toc@l(4)
mr	12, 4
mtctr 4
bctrl

ecnelises avatar Apr 19 '22 06:04 ecnelises

@ecnelises ,thank you for the suggestions ,yes that works ,but its still the issue and we used "no-builtin" options for others reasons too .

ukalappa-mips avatar Apr 19 '22 07:04 ukalappa-mips

Seems like this might be an issue with fast-isel. It should produce indirect calls with -mllvm --fast-isel=false.

nemanjai avatar Apr 19 '22 10:04 nemanjai

I think it should be fine to bail from FISel when lowering a call and long calls are requested on the command line. This should accomplish that:

diff --git a/llvm/lib/Target/PowerPC/PPCFastISel.cpp b/llvm/lib/Target/PowerPC/PPCFastISel.cpp
index e7cd107c5046..4299746f6e38 100644
--- a/llvm/lib/Target/PowerPC/PPCFastISel.cpp
+++ b/llvm/lib/Target/PowerPC/PPCFastISel.cpp
@@ -1555,8 +1555,8 @@ bool PPCFastISel::fastLowerCall(CallLoweringInfo &CLI) {
   if (!Callee && !Symbol)
     return false;
 
-  // Allow SelectionDAG isel to handle tail calls.
-  if (IsTailCall)
+  // Allow SelectionDAG isel to handle tail calls and long calls.
+  if (IsTailCall || Subtarget->useLongCalls())
     return false;
 
   // Let SDISel handle vararg functions.

nemanjai avatar Apr 19 '22 10:04 nemanjai

@nemanjai ,thank you will commit the changes or you want us to do so?

ukalappa-mips avatar Apr 19 '22 10:04 ukalappa-mips

Posted the patch for review at https://reviews.llvm.org/D123997

nemanjai avatar Apr 19 '22 11:04 nemanjai

Hi Nemanja,

Please can you check-in the changes .

Thank you ~Umesh

On Tue, Apr 19, 2022 at 4:53 PM Nemanja Ivanovic @.***> wrote:

Posted the patch for review at https://reviews.llvm.org/D123997

— Reply to this email directly, view it on GitHub https://github.com/llvm/llvm-project/issues/54960#issuecomment-1102524821, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYY5RH5OLCZXJM7ORPNAD6DVF2JRVANCNFSM5TVNTGMA . You are receiving this because you authored the thread.Message ID: @.***>

ukalappa-mips avatar May 02 '22 15:05 ukalappa-mips

@UmeshKalappa0: Could you please elaborate?

EugeneZelenko avatar Jul 20 '23 14:07 EugeneZelenko