6329a9d
2007-07-10  Jakub Jelinek  <jakub@redhat.com>
6329a9d
6329a9d
	* simplify-rtx.c (simplify_plus_minus_op_data_cmp): If both operands
6329a9d
	are REGs and TARGET_INDEX_OPERAND_FIRST, sort lower REGNOs first.
6329a9d
6329a9d
	* gcc.dg/20070710-1.c: New test.
6329a9d
6329a9d
--- gcc/simplify-rtx.c.jj	2006-08-11 17:32:05.000000000 +0200
6329a9d
+++ gcc/simplify-rtx.c	2007-07-09 22:53:26.000000000 +0200
6329a9d
@@ -2608,6 +2608,12 @@ simplify_plus_minus_op_data_cmp (const v
6329a9d
 	    - commutative_operand_precedence (d1->op));
6329a9d
   if (result)
6329a9d
     return result;
6329a9d
+
6329a9d
+  /* Group together equal REGs to do more simplification.  */
6329a9d
+  if (TARGET_INDEX_OPERAND_FIRST && REG_P (d1->op) && REG_P (d2->op)
6329a9d
+      && REGNO (d1->op) != REGNO (d2->op))
6329a9d
+    return REGNO (d1->op) - REGNO (d2->op);
6329a9d
+
6329a9d
   return d1->ix - d2->ix;
6329a9d
 }
6329a9d
 
6329a9d
--- gcc/testsuite/gcc.dg/20070710-1.c.jj	2007-07-10 09:32:43.000000000 +0200
6329a9d
+++ gcc/testsuite/gcc.dg/20070710-1.c	2007-07-10 09:31:39.000000000 +0200
6329a9d
@@ -0,0 +1,17 @@
6329a9d
+/* { dg-do compile } */
6329a9d
+/* { dg-options "-O2 -ffast-math" } */
6329a9d
+
6329a9d
+extern float sqrtf (float);
6329a9d
+
6329a9d
+float
6329a9d
+foo (const float *m)
6329a9d
+{
6329a9d
+  float x = m[0] + m[1] + m[2] + 1.0f;
6329a9d
+  float s;
6329a9d
+
6329a9d
+  if (x > 0.001)
6329a9d
+    s = 0.5f / sqrtf (x);
6329a9d
+  else
6329a9d
+    s = 2.0f * sqrtf (1.0f + m[0] - m[1] - m[2]);
6329a9d
+  return s;
6329a9d
+}