[Bug c/41302] New: Cast of return value from uint32 to pointer cannot be optimized by a jump to called rtn.

2009-09-07 Thread dferbas at etech dot cz
Called fn returns value in d0 (non pointer), but findZipEntry should return
value in a0 (address register). So in that case optimization cannot be done by
simply jumping to the called fn.

typedef u_int32_t   w_word;
typedef struct *z_zipEntry;

z_zipEntry findZipEntry(z_zipFile dir, w_byte *name) {

return (z_zipEntry) ht_read(dir->ht, (w_word)name);
}


findZipEntry:
move.l 4(%sp),%a0
move.l 8(%a0),4(%sp)

jra ht_read

There should be:
jbsr ht_read
move.l %d0,%a0
rts


-- 
   Summary: Cast of return value from uint32 to pointer cannot be
optimized by a jump to called rtn.
   Product: gcc
   Version: 4.3.3
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: dferbas at etech dot cz


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41302



[Bug target/41302] Cast of return value from uint32 to pointer cannot be optimized by a jump to called rtn.

2009-09-22 Thread dferbas at etech dot cz


--- Comment #2 from dferbas at etech dot cz  2009-09-22 22:39 ---
We tried to modify the m68k variant of sibcall fn. But we have a problem with
compilation. Is there anyone who can test if following is OK ?

/* Implement TARGET_FUNCTION_OK_FOR_SIBCALL_P.  We cannot use sibcalls
   for nested functions because we use the static chain register for
   indirect calls.  */


static bool
m68k_ok_for_sibcall_p (tree decl, tree exp)
{
  tree func;
  rtx a, b;

  enum m68k_function_kind kind;


  if (TREE_OPERAND (exp, 2))
return false;


  /* --- incorporated from x386 ---
   * This addresses issue when 1 fn returns a pointer in an address  
register
   * it is casted and the other fn returns a value in data register. */
  if (decl)
func = decl;
  else
{
  func = TREE_TYPE (TREE_OPERAND (exp, 0));
  if (POINTER_TYPE_P (func))
func = TREE_TYPE (func);
}

  /* Check that the return value locations are the same.  Like
 if we are returning floats on the 80387 register stack, we cannot
 make a sibcall from a function that doesn't return a float to a
 function that does or, conversely, from a function that does return
 a float to a function that doesn't; the necessary stack adjustment
 would not be executed.  This is also the place we notice
 differences in the return value ABI.  Note that it is ok for one
 of the functions to have void return type as long as the return
 value of the other is passed in a register.  */
  a = m68k_function_value (TREE_TYPE (exp), func);
  b = m68k_function_value (TREE_TYPE (DECL_RESULT (current_function_decl)),
   current_function_decl);


  if (VOID_TYPE_P (TREE_TYPE (DECL_RESULT (current_function_decl
  ;
  else if (!rtx_equal_p (a, b))
return false;   
  /* --- */


  kind = m68k_get_function_kind (current_function_decl);
  if (kind == m68k_fk_normal_function)
/* We can always sibcall from a normal function, because it's
   undefined if it is calling an interrupt function.  */
return true;


  /* Otherwise we can only sibcall if the function kind is known to be
 the same.  */
  if (decl && m68k_get_function_kind (decl) == kind)
return true;


  return false;
}


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41302