[PATCH] Fix PR 24600 (regression in old loop optimizer)

Ulrich Weigand uweigand@de.ibm.com
Wed Nov 2 14:27:00 GMT 2005


Hello,

this fixes PR 24600, a 4.1 ICE-on-valid regression on s390-ibm-linux.

The ICE is caused by a bug in the old loop optimizer introduced by:
http://gcc.gnu.org/ml/gcc-patches/2005-03/msg00690.html

The problem with this patch is that it assumes gen_move_insn always
returns a valid instruction, even when the source is a PLUS representing
an address.  This is not the case at least on s390.

The patch below fixes the problem by using force_operand to expand
such GIV moves instead.

Bootstrapped/regtested on s390-ibm-linux and s390x-ibm-linux.
OK for mainline?

Bye,
Ulrich


ChangeLog:

	PR target/24600
	* loop.c (loop_givs_rescan): Use force_operand to expand
	complex GIVs.

testsuite/ChangeLog:

	PR target/24600
	* gcc.dg/pr24600.c: New test.


Index: gcc/loop.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/loop.c,v
retrieving revision 1.540
diff -c -p -r1.540 loop.c
*** gcc/loop.c	26 Aug 2005 21:57:25 -0000	1.540
--- gcc/loop.c	1 Nov 2005 21:44:00 -0000
*************** loop_givs_rescan (struct loop *loop, str
*** 5493,5501 ****
  	  /* Not replaceable; emit an insn to set the original
  	     giv reg from the reduced giv.  */
  	  else if (REG_P (*v->location))
! 	    loop_insn_emit_before (loop, 0, v->insn,
! 				   gen_move_insn (*v->location,
! 						  v->new_reg));
  	  else if (GET_CODE (*v->location) == PLUS
  		   && REG_P (XEXP (*v->location, 0))
  		   && CONSTANT_P (XEXP (*v->location, 1)))
--- 5493,5508 ----
  	  /* Not replaceable; emit an insn to set the original
  	     giv reg from the reduced giv.  */
  	  else if (REG_P (*v->location))
! 	    {
! 	      rtx tem;
! 	      start_sequence ();
! 	      tem = force_operand (v->new_reg, *v->location);
! 	      if (tem != *v->location)
! 		emit_move_insn (*v->location, tem);
! 	      tem = get_insns ();
! 	      end_sequence ();
! 	      loop_insn_emit_before (loop, 0, v->insn, tem);
! 	    }
  	  else if (GET_CODE (*v->location) == PLUS
  		   && REG_P (XEXP (*v->location, 0))
  		   && CONSTANT_P (XEXP (*v->location, 1)))
*** /dev/null	Tue Oct 26 21:02:43 2004
--- gcc/testsuite/gcc.dg/pr24600.c	Wed Nov  2 14:47:37 2005
***************
*** 0 ****
--- 1,16 ----
+ /* This used to ICE on s390 due to a old-loop bug.  */
+ 
+ /* { dg-do compile } */
+ /* { dg-options "-O2" } */
+ 
+ char *strcpy (char *dest, const char *src);
+ 
+ void test (char *Line, int len)
+ {
+   int z;
+ 
+   for (z = 1; z <= len; z++)
+     if (Line[z - 1])
+       strcpy (Line + z + 1, Line);
+ }
+ 
-- 
  Dr. Ulrich Weigand
  Linux on zSeries Development
  Ulrich.Weigand@de.ibm.com



More information about the Gcc-patches mailing list