re PR tree-optimization/71230 (ICE : in zero_one_operation, at tree-ssa-reassoc.c...
authorRichard Biener <rguenther@suse.de>
Tue, 24 May 2016 14:35:36 +0000 (14:35 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 24 May 2016 14:35:36 +0000 (14:35 +0000)
2016-05-24  Richard Biener  <rguenther@suse.de>

PR tree-optimization/71230
* tree-ssa-reassoc.c (zero_one_operation): Handle negate special ops.

* gcc.dg/torture/pr71230.c: New testcase.
* g++.dg/torture/pr71230.C: Likewise.

From-SVN: r236643

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/torture/pr71230.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr71230.c [new file with mode: 0644]
gcc/tree-ssa-reassoc.c

index 6eac48e6e8e9fb764b2505ac9988df4318986deb..13134d91114962ecc24af25363fa5900321e5a76 100644 (file)
@@ -1,3 +1,8 @@
+2016-05-24  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/71230
+       * tree-ssa-reassoc.c (zero_one_operation): Handle negate special ops.
+
 2016-05-24  Richard Sandiford  <richard.sandiford@arm.com>
 
        * tree-vectorizer.h (vectorizable_comparison): Delete.
index 361fbbdedbae71bd486e7a97811599c04a7fb85e..a6f65b87a1988c63cb0f2a0fd77b5383ce8b1f62 100644 (file)
@@ -1,3 +1,9 @@
+2016-05-24  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/71230
+       * gcc.dg/torture/pr71230.c: New testcase.
+       * g++.dg/torture/pr71230.C: Likewise.
+
 2016-05-24  Thomas Schwinge  <thomas@codesourcery.com>
 
        * c-c++-common/goacc/routine-5.c: Add tests.
diff --git a/gcc/testsuite/g++.dg/torture/pr71230.C b/gcc/testsuite/g++.dg/torture/pr71230.C
new file mode 100644 (file)
index 0000000..40ce55a
--- /dev/null
@@ -0,0 +1,31 @@
+// { dg-do compile }
+// { dg-additional-options "-ffast-math" }
+
+template <int rank, int dim> class Tensor;
+template <int dim> class Point {
+public:
+    Point (const double x, const double y, const double z);
+    double operator () (const unsigned int index) const;
+};
+template <int celldim, int dim> class TriaObjectAccessor  {
+    Point<dim> & vertex (const unsigned int i) const;
+    Point<dim> barycenter (double, double, double, double, double) const;
+};
+template <> Point<3> TriaObjectAccessor<3, 3>::barycenter (double s6, double s7, double s1, double s2, double s3) const
+{
+    const double x[8] = {
+       vertex(0)(0),    vertex(1)(0),    vertex(2)(0),    vertex(3)(0),    vertex(4)(0),    vertex(5)(0),    vertex(6)(0),    vertex(7)(0) };
+    const double y[8] = {
+       vertex(0)(1),    vertex(1)(1),    vertex(2)(1),    vertex(3)(1),    vertex(4)(1),    vertex(5)(1),    vertex(6)(1),    vertex(7)(1) };
+    const double z[8] = {
+       vertex(0)(2),    vertex(1)(2),    vertex(2)(2),    vertex(3)(2),    vertex(4)(2),    vertex(5)(2),    vertex(6)(2),    vertex(7)(2) };
+    double s4, s5, s8;
+    const double unknown0 = s1*s2;
+    const double unknown1 = s1*s2;
+    s8 = -z[2]*x[1]*y[2]*z[5]+z[2]*y[1]*x[2]*z[5]-z[2]*z[1]*x[2]*y[5]+z[2]*z        [1]*x[5]*y[2]+2.0*y[5]*x[7]*z[4]*z[4]-y[1]*x[2]*z[0]*z[0]+x[0]*y[3]*z[7]*z[7]        -2.0*z[5]*z[5]*x[4]*y[1]+2.0*z[5]*z[5]*x[1]*y[4]+z[5]*z[5]*x[0]*y[4]-2.0*z[2]*z        [2]*x[1]*y[3]+2.0*z[2]*z[2]*x[3]*y[1]-x[0]*y[4]*z[7]*z[7]-y[0]*x[3]*z[7]*z[7]+x        [1]*y[0]*z[5]*z[5];
+    s5 = s8+z[2]*x[6]*y[2]*z[5]-z[2]*x[5]*y[2]*z[6]-z[2]*x[2]*y[3]*z[7]-x[2]*        y[3]*z[7]*z[7]+2.0*z[2]*x[2]*y[3]*z[1]-z[2]*y[2]*x[3]*z[0]+z[2]*y[2]*x[0]*z[3]-        z[2]*x[2]*y[0]*z[3]-z[7]*y[2]*x[7]*z[3]+z[7]*z[2]*x[7]*y[3]+z[7]*x[2]*y[7]*z[3]        +z[6]*y[1]*x[2]*z[5]-z[6]*x[1]*y[2]*z[5]+z[5]*x[1]*y[5]*z[2]+s6+s7;
+    s4 = 1/s5;
+    s2 = s3*s4;
+    const double unknown2 = s1*s2;
+    return Point<3> (unknown0, unknown1, unknown2);
+}
diff --git a/gcc/testsuite/gcc.dg/torture/pr71230.c b/gcc/testsuite/gcc.dg/torture/pr71230.c
new file mode 100644 (file)
index 0000000..d0df8da
--- /dev/null
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-ffast-math" } */
+
+void metric_carttosphere(int *cctk_lsh, double txz, double tyz, double txx,
+                        double tzz, double sint, double cosp, double cost,
+                        double tyy, double sinp, double txy, double *grp,
+                        double *grq, double *r)
+{
+  int i;
+  for(i=0; i<cctk_lsh[0]*cctk_lsh[1]*cctk_lsh[2]; i++)
+    {
+      grq[i] = (cost*tyy*((sinp)*(sinp))*sint+
+               2*cosp*cost*txy*sinp*sint-
+               cost*tzz*sint+ 
+               ((cosp)*(cosp))*cost*txx*sint+
+               2*((cost)*(cost))*tyz*sinp-
+               tyz*sinp+
+               2*cosp*((cost)*(cost))*txz-
+               cosp*txz)*r[i];
+      grp[i] = ((-txy*((sinp)*(sinp))+
+                (cosp*tyy-cosp*txx)*sinp+
+                ((cosp)*(cosp))*txy)*sint-
+               cost*txz*sinp+cosp*cost*tyz);
+    }
+}
index 28823a2c7e644f855601d363a2b94b23dd0b8c27..3b0266767a3c3ce6c90b5e1e06acb11da1b2527d 100644 (file)
@@ -1189,12 +1189,20 @@ zero_one_operation (tree *def, enum tree_code opcode, tree op)
     {
       tree name;
 
-      if (opcode == MULT_EXPR
-         && stmt_is_power_of_op (stmt, op))
+      if (opcode == MULT_EXPR)
        {
-         if (decrement_power (stmt) == 1)
-           propagate_op_to_single_use (op, stmt, def);
-         return;
+         if (stmt_is_power_of_op (stmt, op))
+           {
+             if (decrement_power (stmt) == 1)
+               propagate_op_to_single_use (op, stmt, def);
+             return;
+           }
+         else if (gimple_assign_rhs_code (stmt) == NEGATE_EXPR
+                  && gimple_assign_rhs1 (stmt) == op)
+           {
+             propagate_op_to_single_use (op, stmt, def);
+             return;
+           }
        }
 
       name = gimple_assign_rhs1 (stmt);
@@ -1213,7 +1221,8 @@ zero_one_operation (tree *def, enum tree_code opcode, tree op)
        }
 
       /* We might have a multiply of two __builtin_pow* calls, and
-        the operand might be hiding in the rightmost one.  */
+        the operand might be hiding in the rightmost one.  Likewise
+        this can happen for a negate.  */
       if (opcode == MULT_EXPR
          && gimple_assign_rhs_code (stmt) == opcode
          && TREE_CODE (gimple_assign_rhs2 (stmt)) == SSA_NAME
@@ -1226,6 +1235,13 @@ zero_one_operation (tree *def, enum tree_code opcode, tree op)
                propagate_op_to_single_use (op, stmt2, def);
              return;
            }
+         else if (is_gimple_assign (stmt2)
+                  && gimple_assign_rhs_code (stmt2) == NEGATE_EXPR
+                  && gimple_assign_rhs1 (stmt2) == op)
+           {
+             propagate_op_to_single_use (op, stmt2, def);
+             return;
+           }
        }
 
       /* Continue walking the chain.  */