From c2034a856d8389a12149a95273a1ba53d8bd28c3 Mon Sep 17 00:00:00 2001
From: mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Thu, 27 Mar 2003 18:53:36 +0000
Subject: [PATCH] 	PR opt/10087 	* gcc.dg/20030324-1.c: New test.

	PR opt/10087
	* loop.c (loop_givs_reduce): Skip bivs with duplicate locations
	while incrementing giv.
	(record_biv): Check for duplicate biv locations and
	set (struct induction *) v->same if found.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@64928 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog                     |  8 ++++++++
 gcc/loop.c                        | 15 ++++++++++++++
 gcc/testsuite/ChangeLog           |  5 +++++
 gcc/testsuite/gcc.dg/20030324-1.c | 33 +++++++++++++++++++++++++++++++
 4 files changed, 61 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/20030324-1.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 76947581cefd..03113df8678a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2003-03-27  Glen Nakamura  <glen@imodulo.com>
+
+	PR opt/10087
+	* loop.c (loop_givs_reduce): Skip bivs with duplicate locations
+	while incrementing giv.
+	(record_biv): Check for duplicate biv locations and
+	set (struct induction *) v->same if found.
+
 2003-03-27  David Mosberger  <davidm@hpl.hp.com>
 
         * unwind-libunwind.c (uw_frame_state_for): Adjust for libunwind
diff --git a/gcc/loop.c b/gcc/loop.c
index 781ed3725144..7624b6d6a038 100644
--- a/gcc/loop.c
+++ b/gcc/loop.c
@@ -4817,6 +4817,9 @@ loop_givs_reduce (loop, bl)
 	    {
 	      rtx insert_before;
 
+	      /* Skip if location is the same as a previous one.  */
+	      if (tv->same)
+		continue;
 	      if (! auto_inc_opt)
 		insert_before = NEXT_INSN (tv->insn);
 	      else if (auto_inc_opt == 1)
@@ -5724,6 +5727,7 @@ record_biv (loop, v, insn, dest_reg, inc_val, mult_val, location,
   v->always_computable = ! not_every_iteration;
   v->always_executed = ! not_every_iteration;
   v->maybe_multiple = maybe_multiple;
+  v->same = 0;
 
   /* Add this to the reg's iv_class, creating a class
      if this is the first incrementation of the reg.  */
@@ -5761,6 +5765,17 @@ record_biv (loop, v, insn, dest_reg, inc_val, mult_val, location,
       /* Put it in the array of biv register classes.  */
       REG_IV_CLASS (ivs, REGNO (dest_reg)) = bl;
     }
+  else
+    {
+      /* Check if location is the same as a previous one.  */
+      struct induction *induction;
+      for (induction = bl->biv; induction; induction = induction->next_iv)
+	if (location == induction->location)
+	  {
+	    v->same = induction;
+	    break;
+	  }
+    }
 
   /* Update IV_CLASS entry for this biv.  */
   v->next_iv = bl->biv;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 405556d9d818..3fa38837c3d6 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2003-03-27  Glen Nakamura  <glen@imodulo.com>
+
+	PR opt/10087
+	* gcc.dg/20030324-1.c: New test.
+
 2003-03-27  Nathan Sidwell  <nathan@codesourcery.com>
 
 	PR c++/10224
diff --git a/gcc/testsuite/gcc.dg/20030324-1.c b/gcc/testsuite/gcc.dg/20030324-1.c
new file mode 100644
index 000000000000..343c721dc643
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/20030324-1.c
@@ -0,0 +1,33 @@
+/* { dg-do run } */
+/* { dg-options "-O -fstrength-reduce -fstrict-aliasing -fforce-mem -fgcse" } */
+
+void b(int*,int*);
+    
+typedef struct {
+    double T1;
+    char c;
+} S;
+
+int main(void)
+{
+  int i,j;
+  double s;
+
+  S x1[2][2];
+  S *x[2] = { x1[0], x1[1] };
+  S **E = x;
+
+  for( i=0; i < 2; i++ )
+    for( j=0; j < 2; j++ )
+      E[j][i].T1 = 1;
+
+  for( i=0; i < 2; i++ )
+    for( j=0; j < 2; j++ )
+      s = E[j][i].T1;
+
+  b(&j,&i);
+  printf( "result %.6e\n", s);
+  return 0;
+}
+
+void b(int *i, int *j) {}
-- 
GitLab