A problem on returning value for functions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

A problem on returning value for functions

杨勇勇
Hi, 

I write a backend and come cross an abnormal problem. Here I give a example to describe it:

///////////////////////////////////////////////////////////////////////////////////////////
// A simple C function
int  foo()
{
  return 1234;
}
/////////////////////////////////////////////////////////////////////////////////////////

When compiling foo() into my target ISA, I would expect codes like:

/////////////////////////////////////////////////////////////////////////////////////////
...
movi  r0, #1234  // prepare r0 to return value 1234.
...
ret     // return to caller.
////////////////////////////////////////////////////////////////////////////////////////

The headache is when I pass option -O0 to llc, the generated codes are correct. However, if I omit -O0 and use default compiling options, the instruction "movi  r0, #1234" does not show.

I have already checked DAGs using options -view-xxxxx-dags and they all seem OK.

I do not have any clue right now. Please help me.

Thank you.

--
杨勇勇 (Yang Yong-Yong)

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: A problem on returning value for functions

Tim Northover-2
Hi,

> The headache is when I pass option -O0 to llc, the generated codes are
> correct. However, if I omit -O0 and use default compiling options, the
> instruction "movi  r0, #1234" does not show.

It's probably being eliminated as dead code. You want to make sure
that during ISelLowering your RET instruction has %R0 as one of its
operands (check in the -view-isel-dags step).

That's the most likely cause anyway. If not, posting the DAG might
help, or the output of "llc -debug" on an equivalent .ll file.

Cheers.

Tim.
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: A problem on returning value for functions

杨勇勇
Thank you, this is very instructive. I soon realized I forgot to add SDNPVariadic in my node definition of return operator.
And thus even though the  LowerReturn() is implemented properly, the instructions for passing return value is eliminated.

Regards.

2013/7/9 Tim Northover <[hidden email]>
Hi,

> The headache is when I pass option -O0 to llc, the generated codes are
> correct. However, if I omit -O0 and use default compiling options, the
> instruction "movi  r0, #1234" does not show.

It's probably being eliminated as dead code. You want to make sure
that during ISelLowering your RET instruction has %R0 as one of its
operands (check in the -view-isel-dags step).

That's the most likely cause anyway. If not, posting the DAG might
help, or the output of "llc -debug" on an equivalent .ll file.

Cheers.

Tim.



--
杨勇勇 (Yang Yong-Yong)

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev