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: [3.3 PATCH] fix PHI insertion for RTL SSA-CCP


On Wednesday 25 August 2004 15:21, Wolfgang Bangerth wrote:
> > > I could be persuaded if this were a regression with a due PR...
> >
> > This is most likely PR10463.  I doubt it is a regression, it's
> > a bit hard to verify.  Apparently, ssa-ccp appeared for the first
> > time in GCC 3.1 (?), and I don't have such old compilers around.
>
> I made the check: as it so happens, PR 10463 is indeed a regression, and I
> attached a small testcase. Steven, you may want to check whether your patch
> fixes it.

Yes, my patch fixes the ICE.  As attached.

Gr.
Steven

	* ssa.c (insert_phi_node): Insert PHI nodes after the block note
	so that they end up in the correct basic block.
	* ssa-ccp.c (ssa_ccp_substitute_constants): Only replace operands
	with constants if the change can be validated by recog.
	(ssa_fast_dce): Never remove insns with libcall notes.

Index: ssa-ccp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/ssa-ccp.c,v
retrieving revision 1.26
diff -c -3 -p -r1.26 ssa-ccp.c
*** ssa-ccp.c	22 Jul 2002 17:31:42 -0000	1.26
--- ssa-ccp.c	25 Aug 2004 23:00:09 -0000
*************** ssa_ccp_substitute_constants ()
*** 875,882 ****
  	    {
  	      if (rtl_dump_file)
  		fprintf (rtl_dump_file,
! 			 "Register %d is now set to a constant\n",
! 			 SSA_NAME (PATTERN (def)));
  	      SET_SRC (set) = values[i].const_value;
  	      INSN_CODE (def) = -1;
  	      df_insn_modify (df_analyzer, BLOCK_FOR_INSN (def), def);
--- 875,896 ----
  	    {
  	      if (rtl_dump_file)
  		fprintf (rtl_dump_file,
! 			 "Register %d is now proved to be a constant\n",
! 			 SSA_NAME (set));
! 	      if (validate_change (def, &SET_SRC (set),
! 				   values[i].const_value, 0))
! 		{
! 		  if (rtl_dump_file)
! 		    fprintf (rtl_dump_file,
! 			     "   replacement made and validated\n");
! 		}
! 	      else
! 		{
! 		  if (rtl_dump_file)
! 		    fprintf (rtl_dump_file,
! 			     "   but unable to validate replacement...\n");
! 		}
! 
  	      SET_SRC (set) = values[i].const_value;
  	      INSN_CODE (def) = -1;
  	      df_insn_modify (df_analyzer, BLOCK_FOR_INSN (def), def);
*************** ssa_fast_dce (df)
*** 1155,1176 ****
    while (sbitmap_first_set_bit (worklist) >= 0)
      {
        struct df_link *curruse;
!       int reg, found_use;
  
!       /* Remove an item from the worklist.  */
!       reg = sbitmap_first_set_bit (worklist);
        RESET_BIT (worklist, reg);
  
        /* We never consider deleting assignments to hard regs or things
  	 which do not have SSA definitions, or things we have already
  	 deleted, or things with unusual side effects.  */
        if (reg < FIRST_PSEUDO_REGISTER
! 	  || ! VARRAY_RTX (ssa_definition, reg)
! 	  || INSN_DELETED_P (VARRAY_RTX (ssa_definition, reg))
! 	  || (GET_CODE (VARRAY_RTX (ssa_definition, reg)) == NOTE
! 	      && (NOTE_LINE_NUMBER (VARRAY_RTX (ssa_definition, reg))
! 		  == NOTE_INSN_DELETED))
! 	  || side_effects_p (PATTERN (VARRAY_RTX (ssa_definition, reg))))
  	continue;
  
        /* Iterate over the uses of this register.  If we can not find
--- 1169,1192 ----
    while (sbitmap_first_set_bit (worklist) >= 0)
      {
        struct df_link *curruse;
!       int found_use;
!       int reg = sbitmap_first_set_bit (worklist);
!       rtx def = VARRAY_RTX (ssa_definition, reg);
  
!       /* Remove this item from the worklist.  */
        RESET_BIT (worklist, reg);
  
        /* We never consider deleting assignments to hard regs or things
  	 which do not have SSA definitions, or things we have already
  	 deleted, or things with unusual side effects.  */
        if (reg < FIRST_PSEUDO_REGISTER
! 	  || !def
! 	  || INSN_DELETED_P (def)
! 	  || (GET_CODE (def) == NOTE
! 	      && (NOTE_LINE_NUMBER (def) == NOTE_INSN_DELETED))
! 	  || find_reg_note (def, REG_LIBCALL, NULL_RTX)
! 	  || find_reg_note (def, REG_RETVAL, NULL_RTX)
! 	  || side_effects_p (PATTERN (def)))
  	continue;
  
        /* Iterate over the uses of this register.  If we can not find
*************** ssa_fast_dce (df)
*** 1185,1191 ****
  	      && ! (GET_CODE (DF_REF_INSN (curruse->ref)) == NOTE
  		    && (NOTE_LINE_NUMBER (DF_REF_INSN (curruse->ref))
  			== NOTE_INSN_DELETED))
! 	      && DF_REF_INSN (curruse->ref) != VARRAY_RTX (ssa_definition, reg))
  	    {
  	      found_use = 1;
  	      break;
--- 1201,1207 ----
  	      && ! (GET_CODE (DF_REF_INSN (curruse->ref)) == NOTE
  		    && (NOTE_LINE_NUMBER (DF_REF_INSN (curruse->ref))
  			== NOTE_INSN_DELETED))
! 	      && DF_REF_INSN (curruse->ref) != def)
  	    {
  	      found_use = 1;
  	      break;
*************** ssa_fast_dce (df)
*** 1197,1204 ****
  
        if (! found_use)
  	{
- 	  rtx def = VARRAY_RTX (ssa_definition, reg);
- 
  	  /* Add all registers referenced by INSN to the work
  	     list.  */
  	  for_each_rtx (&PATTERN (def), mark_references, worklist);
--- 1213,1218 ----
Index: ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/ssa.c,v
retrieving revision 1.56
diff -c -3 -p -r1.56 ssa.c
*** ssa.c	27 Sep 2002 12:48:03 -0000	1.56
--- ssa.c	25 Aug 2004 23:00:10 -0000
*************** insert_phi_node (regno, bb)
*** 676,682 ****
  
    insn = first_insn_after_basic_block_note (b);
    end_p = PREV_INSN (insn) == b->end;
!   emit_insn_before (phi, insn);
    if (end_p)
      b->end = PREV_INSN (insn);
  }
--- 676,682 ----
  
    insn = first_insn_after_basic_block_note (b);
    end_p = PREV_INSN (insn) == b->end;
!   emit_insn_after (phi, PREV_INSN (insn));
    if (end_p)
      b->end = PREV_INSN (insn);
  }


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