This is the mail archive of the gcc-patches@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]

Patch to fix loop REG_NONNEG note generation


The documentation for REG_NONNEG says:

  The register @var{op} is known to have a nonnegative value when this
  insn is reached.  This is used so that decrement and branch until zero
  instructions, such as the m68k dbra, can be matched.

Compiling:

  int
  func (int a, int b)
    {
    int c;
    int d;
    int i;

    c = a;
    d = 0;

    for (i = 1000; i >= 0; i -= 1)
      {
        d += c + i;
        subr ();
      }

   return d;
   }

on x86 with -O2 -dL without this patch generates:

  ...

  (jump_insn 24 23 49 (set (pc)
          (if_then_else (ge (reg:CCNO 17 flags)
                  (const_int 0 [0x0]))
              (label_ref 27)
              (pc))) -1 (nil)
      (expr_list:REG_NONNEG (nil)
          (expr_list:REG_NONNEG (nil)
              (nil))))

and with this patch:

  ...

  (jump_insn 24 23 49 (set (pc)
          (if_then_else (ge (reg:CCNO 17 flags)
                  (const_int 0 [0x0]))
              (label_ref 27)
              (pc))) -1 (nil)
      (expr_list:REG_NONNEG (reg/v:SI 30)
          (nil)))

This patch passes make bootstrap and make check on FreeBSD-3.4 x86.

ChangeLog:

Mon Jun 12 01:33:11 EDT 2000  John Wehle  (john@feith.com)

	* loop.c (check_dbra_loop): Specify the register when
	generating REG_NONNEG notes and don't generate duplicates.

Enjoy!

-- John Wehle
------------------8<------------------------8<------------------------
*** gcc/loop.c.ORIGINAL	Tue Jun  6 00:03:42 2000
--- gcc/loop.c	Mon Jun 12 01:23:51 2000
*************** check_dbra_loop (loop, insn_count)
*** 7835,7843 ****
  	      % (-INTVAL (bl->biv->add_val))) == 0)
  	{
  	  /* register always nonnegative, add REG_NOTE to branch */
! 	  REG_NOTES (PREV_INSN (loop_end))
! 	    = gen_rtx_EXPR_LIST (REG_NONNEG, NULL_RTX,
! 				 REG_NOTES (PREV_INSN (loop_end)));
  	  bl->nonneg = 1;
  
  	  return 1;
--- 7835,7844 ----
  	      % (-INTVAL (bl->biv->add_val))) == 0)
  	{
  	  /* register always nonnegative, add REG_NOTE to branch */
! 	  if (! find_reg_note (jump, REG_NONNEG, NULL_RTX))
! 	    REG_NOTES (jump)
! 	      = gen_rtx_EXPR_LIST (REG_NONNEG, bl->biv->dest_reg,
! 				   REG_NOTES (jump));
  	  bl->nonneg = 1;
  
  	  return 1;
*************** check_dbra_loop (loop, insn_count)
*** 7860,7868 ****
  	      && ! reg_set_between_p (bl->biv->dest_reg, p, loop_start)
  	      && INTVAL (bl->biv->add_val) == -1)
  	    {
! 	      REG_NOTES (PREV_INSN (loop_end))
! 		= gen_rtx_EXPR_LIST (REG_NONNEG, NULL_RTX,
! 				     REG_NOTES (PREV_INSN (loop_end)));
  	      bl->nonneg = 1;
  
  	      return 1;
--- 7861,7870 ----
  	      && ! reg_set_between_p (bl->biv->dest_reg, p, loop_start)
  	      && INTVAL (bl->biv->add_val) == -1)
  	    {
! 	      if (! find_reg_note (jump, REG_NONNEG, NULL_RTX))
! 		REG_NOTES (jump)
! 		  = gen_rtx_EXPR_LIST (REG_NONNEG, bl->biv->dest_reg,
! 				       REG_NOTES (jump));
  	      bl->nonneg = 1;
  
  	      return 1;
*************** check_dbra_loop (loop, insn_count)
*** 8260,8266 ****
  		      /* Increment of LABEL_NUSES done above.  */
  		      /* Register is now always nonnegative,
  			 so add REG_NONNEG note to the branch.  */
! 		      REG_NOTES (tem) = gen_rtx_EXPR_LIST (REG_NONNEG, NULL_RTX,
  							   REG_NOTES (tem));
  		    }
  		  bl->nonneg = 1;
--- 8262,8268 ----
  		      /* Increment of LABEL_NUSES done above.  */
  		      /* Register is now always nonnegative,
  			 so add REG_NONNEG note to the branch.  */
! 		      REG_NOTES (tem) = gen_rtx_EXPR_LIST (REG_NONNEG, reg,
  							   REG_NOTES (tem));
  		    }
  		  bl->nonneg = 1;
-------------------------------------------------------------------------
|   Feith Systems  |   Voice: 1-215-646-8000  |  Email: john@feith.com  |
|    John Wehle    |     Fax: 1-215-540-5495  |                         |
-------------------------------------------------------------------------


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