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]

gcse.c patch for cc0 constant propagation


Hi Richard.

As per our conversation... I was debugging a test case which caused a
crash in the constant propagation code (gcse.c:cprop_insn):

  Exhibit A:
  	#ifdef HAVE_cc0
  	  /* Similar code for machines that use a pair of CC0 setter and
  	     conditional jump insn.  */
  	  else if (alter_jumps
  		   && GET_CODE (PATTERN (insn)) == SET
  		   && SET_DEST (PATTERN (insn)) == cc0_rtx
  		   && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN
  		   && condjump_p (NEXT_INSN (insn))
  		   && ! simplejump_p (NEXT_INSN (insn)))
  	    changed |= cprop_cc0_jump (insn, reg_used, src);
  	#endif

I started with the following instruction.

  	(insn 1108 1106 1109 (set (cc0)
  		(compare (reg/v:SI 58)
  		    (const_int 8 [0x8]))) 13 {cmpsi} (nil)
  	    (expr_list:REG_EQUAL (compare (const_int 10 [0xa])
  		    (const_int 8 [0x8]))
  		(nil)))

 	(jump_insn 1109 1108 13048 (set (pc)
  		(if_then_else (ge (cc0)
  			(const_int 0 [0x0]))
  		    (label_ref 1112)
  		    (pc))) 41 {jump-2} (nil)
  	    (nil))

Which got rewritten by cprop_cc0_jump() into:

  	(note 1108 1106 1109 NOTE_INSN_DELETED 0)

  	(jump_insn 1109 1108 14676 (set (pc)
  		(label_ref 1112)) -1 (nil)
  	    (nil))

However, when the code looped again at:

    for (reg_used = &reg_use_table[0]; reg_use_count > 0;
         reg_used++, reg_use_count--)
      {
        unsigned int regno = REGNO (reg_used->reg_rtx);

It crossed exhibit A again, but this time caused a core dump because
insn 1108 was now a note, not an insn, so there was no PATTERN().

  		   && GET_CODE (PATTERN (insn)) == SET
  				^^^^^^^death.

The following code makes sure that we do not do propagate constants
into jump_insns for machines with CC0 (more than once anyhow).

Ok to install?
Aldy

2000-10-24  Aldy Hernandez  <aldyh@redhat.com>

	* gcse.c (cprop_insn): do not propagate constants into jump_insn
	for machines with CC0 more than once.

Index: gcse.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/gcse.c,v
retrieving revision 1.107
diff -c -r1.107 gcse.c
*** gcse.c      2000/10/20 19:17:41     1.107
--- gcse.c      2000/10/24 21:48:14
***************
*** 3948,3954 ****
                   && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN
                   && condjump_p (NEXT_INSN (insn))
                   && ! simplejump_p (NEXT_INSN (insn)))
!           changed |= cprop_cc0_jump (insn, reg_used, src);
  #endif
        }
        else if (GET_CODE (src) == REG
--- 3948,3960 ----
                   && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN
                   && condjump_p (NEXT_INSN (insn))
                   && ! simplejump_p (NEXT_INSN (insn)))
!             {
!             if (cprop_cc0_jump (insn, reg_used, src))
!               {
!                 changed = 1;
!                 break;
!               }
!           }
  #endif
        }
        else if (GET_CODE (src) == REG

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