This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Understand BLKmode and returning structure in register.


Hello,
I came across an issue regarding BLKmode and returning structure in register.  For following code,  I try to return the structure in register instead of memory. 
 
extern void abort();
typedef struct {
  short x;
  short y;
} COMPLEX;
 
COMPLEX foo (void) __attribute__ ((noinline));
COMPLEX foo (void)
{
  COMPLEX  x;  
 
  x.x = -7;
  x.y = -7;
 
  return x;
}
 

int main(){
  COMPLEX x = foo();
  if(x.y != -7)
    abort();
}

 
In foo function, compute_record_mode function will set the mode for struct COMPLEX as BLKmode partly because STRICT_ALIGNMENT is 1 on my target. In TARGET_RETURN_IN_MEMORY hook, I return 1 for BLKmode type and 0 otherwise for small size (<8) (like MIPS). Thus, this structure is still returned through memory, which is not very efficient. More importantly, ABI is NOT FIXED under such situation. If an assembly code programmer writes a function returning a structure. How does he know the structure will be treated as BLKmode or otherwise? So he doesn't know whether to pass result through memory or register. Do I understand correctly?

On the other hand, if I return 0 only according to struct type's size regardless BLKmode or not, GCC will produces very inefficient code. For example, stack setup code in foo is still generated even it is totally unnecessary.

Only when I set STRICT_ALIGNMENT to 0, the structure can be passed through register in an efficient way. Unfortunately, our machine is strictly aligned and I cannot really do that. 

Any suggestion? 

Thanks,
Bingfeng Mei
Broadcom UK 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]