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]
Other format: [Raw text]

Re: [PATCH] Do not copy LOOP_CONTs


Oops, I had a functionally equivalent patch, but
it seems I forgot to send this one.

>This
>happens when the loop condition is in the same insn as the loop
>branch, e.g. with insns like

(define_insn "blt"
  [(set (pc) (if_then_else (lt:SI (match_operand) (match_operand))
                            (label_ref)
                            (pc)))]
 ...)


That's a red herring, such patterns are quite common.  The important
bit is that we got no VTOP note because this is a do-while loop.



-- 
--------------------------
SuperH
2430 Aztec West / Almondsbury / BRISTOL / BS32 4AQ
T:+44 1454 462330
The SH64 subtargets -m5-32media-nofpu, -m5-32media-nofpu -ml, -m5-64media,
-m5-64media -ml, -m5-64media-nofpu, -m5-64media-nofpu -ml, -m5 and -m5 -ml
show regressions for execute/loop-4b.c at optimization levels
-O3 -fomit-frame-pointer -funroll-loops and -O3 -fomit-frame-pointer
-funroll-all-loops -finline-functions.

find_and_verify_loop aborts because it sees a NOTE_INSN_LOOP_CONT
note without a matching NOTE_INSN_LOOP_BEG note.  The stray note
was generated during a previous loop unrolling pass, in this code:

unroll.c:2258
      for (insn = copy_notes_from; insn != loop_end; insn = NEXT_INSN (insn))
        {
          /* VTOP notes are valid only before the loop exit test.
             If placed anywhere else, loop may generate bad code.
             There is no need to test for NOTE_INSN_LOOP_CONT notes
             here, since COPY_NOTES_FROM will be at most one or two (for cc0)
             instructions before the last insn in the loop, and if the
             end test is that short, there will be a VTOP note between
             the CONT note and the test.  */
          if (GET_CODE (insn) == NOTE
              && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED
              && NOTE_LINE_NUMBER (insn) != NOTE_INSN_BASIC_BLOCK
              && NOTE_LINE_NUMBER (insn) != NOTE_INSN_LOOP_VTOP)
            emit_note (NOTE_SOURCE_FILE (insn), NOTE_LINE_NUMBER (insn));
        }   

(gdb) call debug_rtx_list(loop->start,10)
(note 18 101 19 NOTE_INSN_LOOP_BEG)

(code_label 19 18 73 3 "" [1 uses])

(note 73 19 23 [bb 1] NOTE_INSN_BASIC_BLOCK)

(insn 23 73 24 0x401bac80 (set (reg:SI 162)
        (ashift:SI (subreg/s:SI (reg/v:DI 160) 0)
            (const_int 1 [0x1]))) -1 (nil)
    (nil))

(insn 24 23 28 0x401bac80 (set (reg/v:DI 160)
        (sign_extend:DI (reg:SI 162))) -1 (nil)
    (nil))

(insn 28 24 29 0x401bac80 (set (reg:SI 164)
        (plus:SI (subreg/s:SI (reg/v:DI 161) 0)
            (const_int 268435456 [0x10000000]))) -1 (nil)
    (nil))

(insn 29 28 31 0x401bac80 (set (reg/v:DI 161)
        (sign_extend:DI (reg:SI 164))) -1 (nil)
    (nil))

(note 31 29 36 NOTE_INSN_LOOP_CONT)

(jump_insn 36 31 42 0x401bac80 (set (pc)
        (if_then_else (gt (reg:DI 166)
                (reg/v:DI 161))
            (label_ref 19)
            (pc))) -1 (nil)
    (nil))

(note 42 36 77 NOTE_INSN_LOOP_END)

The assumption that there would be a VTOP note if the test is short
is wrong because the loop is of the do - while style, and hence
the exit test is run only at the end.

Tue Jul 23 17:53:22 2002  J"orn Rennecke <joern.rennecke@superh.com>

	* unroll.c (copy_loop_body): Don't copy NOTE_INSN_LOOP_CONT.

Index: unroll.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/unroll.c,v
retrieving revision 1.171
diff -p -r1.171 unroll.c
*** unroll.c	22 Jul 2002 00:29:56 -0000	1.171
--- unroll.c	23 Jul 2002 16:46:09 -0000
*************** copy_loop_body (loop, copy_start, copy_e
*** 2259,2273 ****
  	{
  	  /* VTOP notes are valid only before the loop exit test.
  	     If placed anywhere else, loop may generate bad code.
! 	     There is no need to test for NOTE_INSN_LOOP_CONT notes
! 	     here, since COPY_NOTES_FROM will be at most one or two (for cc0)
! 	     instructions before the last insn in the loop, and if the
! 	     end test is that short, there will be a VTOP note between
! 	     the CONT note and the test.  */
  	  if (GET_CODE (insn) == NOTE
  	      && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED
  	      && NOTE_LINE_NUMBER (insn) != NOTE_INSN_BASIC_BLOCK
! 	      && NOTE_LINE_NUMBER (insn) != NOTE_INSN_LOOP_VTOP)
  	    emit_note (NOTE_SOURCE_FILE (insn), NOTE_LINE_NUMBER (insn));
  	}
      }
--- 2259,2273 ----
  	{
  	  /* VTOP notes are valid only before the loop exit test.
  	     If placed anywhere else, loop may generate bad code.
! 	     Although COPY_NOTES_FROM will be at most one or two (for cc0)
! 	     instructions before the last insn in the loop, COPY_NOTES_FROM
! 	     can be a NOTE_INSN_LOOP_CONST note if there is no VTOP note,
! 	     as in a do .. while loop.  */
  	  if (GET_CODE (insn) == NOTE
  	      && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED
  	      && NOTE_LINE_NUMBER (insn) != NOTE_INSN_BASIC_BLOCK
! 	      && NOTE_LINE_NUMBER (insn) != NOTE_INSN_LOOP_VTOP
! 	      && NOTE_LINE_NUMBER (insn) != NOTE_INSN_LOOP_CONT)
  	    emit_note (NOTE_SOURCE_FILE (insn), NOTE_LINE_NUMBER (insn));
  	}
      }

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