x86 direct return correctness

Richard Henderson rth@cygnus.com
Sun Feb 6 05:20:00 GMT 2000


We were being less than through in deciding when just a return insn
would do.  And were completely broken for stdcall.



r~


        * i386.c (ix86_can_use_return_insn_p): Fail for large poped args
        and for non-empty stack frames.
        * i386.md (return): Expand to return-pop as needed.

Index: i386.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/i386/i386.c,v
retrieving revision 1.135
diff -c -p -d -r1.135 i386.c
*** i386.c	2000/02/06 09:47:28	1.135
--- i386.c	2000/02/06 13:08:50
*************** symbolic_reference_mentioned_p (op)
*** 1555,1569 ****
  int
  ix86_can_use_return_insn_p ()
  {
  #ifdef NON_SAVING_SETJMP
    if (NON_SAVING_SETJMP && current_function_calls_setjmp)
      return 0;
  #endif
  
!   if (! reload_completed)
      return 0;
  
!   return ix86_nsaved_regs () == 0 || ! frame_pointer_needed;
  }
  
  static char *pic_label_name;
--- 1555,1583 ----
  int
  ix86_can_use_return_insn_p ()
  {
+   HOST_WIDE_INT tsize;
+   int nregs;
+ 
  #ifdef NON_SAVING_SETJMP
    if (NON_SAVING_SETJMP && current_function_calls_setjmp)
      return 0;
  #endif
+ #ifdef FUNCTION_BLOCK_PROFILER_EXIT
+   if (profile_block_flag == 2)
+     return 0;
+ #endif
  
!   if (! reload_completed || frame_pointer_needed)
      return 0;
  
!   /* Don't allow more than 32 pop, since that's all we can do
!      with one instruction.  */
!   if (current_function_pops_args
!       && current_function_args_size >= 32768)
!     return 0;
! 
!   tsize = ix86_compute_frame_size (get_frame_size (), &nregs, NULL, NULL);
!   return tsize == 0 && nregs == 0;
  }
  
  static char *pic_label_name;
Index: i386.md
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/i386/i386.md,v
retrieving revision 1.135
diff -c -p -d -r1.135 i386.md
*** i386.md	2000/02/06 09:47:49	1.135
--- i386.md	2000/02/06 13:08:51
***************
*** 7218,7224 ****
  (define_expand "return"
    [(return)]
    "ix86_can_use_return_insn_p ()"
!   "")
  
  (define_insn "return_internal"
    [(return)]
--- 7218,7232 ----
  (define_expand "return"
    [(return)]
    "ix86_can_use_return_insn_p ()"
!   "
! {
!   if (current_function_pops_args)
!     {
!       rtx popc = GEN_INT (current_function_pops_args);
!       emit_jump_insn (gen_return_pop_internal (popc));
!       DONE;
!     }
! }")
  
  (define_insn "return_internal"
    [(return)]


More information about the Gcc-patches mailing list