summaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/reassoc-31.c17
-rw-r--r--gcc/testsuite/gfortran.dg/reassoc_12.f9074
-rw-r--r--gcc/tree-ssa-reassoc.c25
5 files changed, 118 insertions, 12 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index abf8182b09d..286aed55344 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2013-09-04 Easwaran Raman <eraman@google.com>
+
+ PR middle-end/57370
+ * tree-ssa-reassoc.c (get_stmt_uid_with_default): New function,
+ (build_and_add_sum): Use it.
+ (appears_later_in_bb): Simplify code.
+
2013-09-04 Teresa Johnson <tejohnson@google.com>
* dumpfile.c (dump_finish): Don't close stderr/stdout.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index ffa42f090eb..5f1939086aa 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2013-09-04 Easwaran Raman <eraman@google.com>
+
+ PR middle-end/57370
+ PR tree-optimization/58011
+ * gfortran.dg/reassoc_12.f90: New testcase.
+ * gcc.dg/tree-ssa/reassoc-31.c: New testcase.
+
2013-09-04 David Edelsohn <dje.gcc@gmail.com>
* gcc.dg/attr-weakref-1.c: Skip on AIX.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-31.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-31.c
new file mode 100644
index 00000000000..1c1527f1350
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-31.c
@@ -0,0 +1,17 @@
+/* PR tree-optimization/58011 */
+/* { dg-do compile } */
+/* { dg-options "-O1" } */
+int a, b;
+
+void f(unsigned p)
+{
+ unsigned *pp = &p;
+
+ if(!a)
+ p = 0;
+
+ for(b = 0; b < 1; b++)
+ if(3 * p + 5 * *pp)
+ a = 0;
+}
+
diff --git a/gcc/testsuite/gfortran.dg/reassoc_12.f90 b/gcc/testsuite/gfortran.dg/reassoc_12.f90
new file mode 100644
index 00000000000..7f4d70e31ca
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/reassoc_12.f90
@@ -0,0 +1,74 @@
+! { dg-do compile }
+! { dg-options "-O2 -ffast-math" }
+! PR middle-end/57370
+
+ SUBROUTINE xb88_lr_adiabatic_lda_calc(e_ndrho_ndrho_ndrho, &
+ grad_deriv,npoints, sx)
+ IMPLICIT REAL*8 (t)
+ INTEGER, PARAMETER :: dp=8
+ REAL(kind=dp), DIMENSION(1:npoints) :: e_ndrho_ndrho_ndrho, &
+ e_ndrho_ndrho_rho
+ DO ii=1,npoints
+ IF( grad_deriv >= 2 .OR. grad_deriv == -2 ) THEN
+ t1425 = t233 * t557
+ t1429 = beta * t225
+ t1622 = t327 * t1621
+ t1626 = t327 * t1625
+ t1632 = t327 * t1631
+ t1685 = t105 * t1684
+ t2057 = t1636 + t8 * (t2635 + t3288)
+ END IF
+ IF( grad_deriv >= 3 .OR. grad_deriv == -3 ) THEN
+ t5469 = t5440 - t5443 - t5446 - t5449 - &
+ t5451 - t5454 - t5456 + t5459 - &
+ t5462 + t5466 - t5468
+ t5478 = 0.240e2_dp * t1616 * t973 * t645 * t1425
+ t5489 = 0.1600000000e2_dp * t1429 * t1658
+ t5531 = 0.160e2_dp * t112 * t1626
+ t5533 = 0.160e2_dp * t112 * t1632
+ t5537 = 0.160e2_dp * t112 * t1622
+ t5541 = t5472 - t5478 - t5523 + t5525 + &
+ t5531 + t5533 + t5535 + t5537 + &
+ t5540
+ t5565 = t112 * t1685
+ t5575 = t5545 - t5548 + t5551 + t5553 - &
+ t5558 + t5560 - t5562 + t5564 - &
+ 0.80e1_dp * t5565 + t5568 + t5572 + &
+ t5574
+ t5611 = t5579 - t5585 + t5590 - t5595 + &
+ t5597 - t5602 + t5604 + t5607 + &
+ t5610
+ t5613 = t5469 + t5541 + t5575 + t5611
+ t6223 = t6189 - &
+ 0.3333333336e0_dp * t83 * t84 * t5613 + &
+ t6222
+ t6227 = - t8 * (t5305 + t6223)
+ e_ndrho_ndrho_rho(ii) = e_ndrho_ndrho_rho(ii) + &
+ t6227 * sx
+ t6352 = t5440 - t5443 - t5446 - t5449 - &
+ t5451 - t5454 + &
+ 0.40e1_dp * t102 * t327 * t2057 * t557 - &
+ t5456 + t5459 - t5462 + t5466 - &
+ t5468
+ t6363 = t5480 - t5489 + &
+ 0.9600000000e2_dp * t1054 * t640 * t3679
+ t6367 = t5472 - t5474 - t5478 - t5523 + &
+ t5525 + t5531 + t5533 + t5535 + &
+ t5537 - 0.20e1_dp * t102 * t105 * t6363 + &
+ t5540
+ t6370 = t5545 - t5548 + t5551 + t5553 - &
+ t5558 + t5560 - t5562 + t5564 - &
+ 0.40e1_dp * t5565 + &
+ t5568 + t5572 + t5574
+ t6373 = t5579 - t5585 + t5590 - t5595 + &
+ t5597 - t5602 + t5604 + t5607 + &
+ t5610
+ t6375 = t6352 + t6367 + t6370 + t6373
+ t6380 = - 0.3333333336e0_dp * t83 * t84 * t6375 + t5701
+ t6669 = -t4704 - t8 * (t6344 + t6380 + t6665)
+ e_ndrho_ndrho_ndrho(ii) = e_ndrho_ndrho_ndrho(ii) + &
+ t6669 * sx
+ END IF
+ END DO
+ END SUBROUTINE xb88_lr_adiabatic_lda_calc
+
diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c
index 7e1d8c77a3f..03c6c5dbfa4 100644
--- a/gcc/tree-ssa-reassoc.c
+++ b/gcc/tree-ssa-reassoc.c
@@ -1141,6 +1141,14 @@ zero_one_operation (tree *def, enum tree_code opcode, tree op)
while (1);
}
+/* Returns the UID of STMT if it is non-NULL. Otherwise return 1. */
+
+static inline unsigned
+get_stmt_uid_with_default (gimple stmt)
+{
+ return stmt ? gimple_uid (stmt) : 1;
+}
+
/* Builds one statement performing OP1 OPCODE OP2 using TMPVAR for
the result. Places the statement after the definition of either
OP1 or OP2. Returns the new statement. */
@@ -1165,12 +1173,8 @@ build_and_add_sum (tree type, tree op1, tree op2, enum tree_code opcode)
if ((!op1def || gimple_nop_p (op1def))
&& (!op2def || gimple_nop_p (op2def)))
{
- gimple first_stmt;
- unsigned uid;
gsi = gsi_after_labels (single_succ (ENTRY_BLOCK_PTR));
- first_stmt = gsi_stmt (gsi);
- uid = first_stmt ? gimple_uid (first_stmt) : 1;
- gimple_set_uid (sum, uid);
+ gimple_set_uid (sum, get_stmt_uid_with_default (gsi_stmt (gsi)));
gsi_insert_before (&gsi, sum, GSI_NEW_STMT);
}
else if ((!op1def || gimple_nop_p (op1def))
@@ -1180,7 +1184,7 @@ build_and_add_sum (tree type, tree op1, tree op2, enum tree_code opcode)
if (gimple_code (op2def) == GIMPLE_PHI)
{
gsi = gsi_after_labels (gimple_bb (op2def));
- gimple_set_uid (sum, gimple_uid (gsi_stmt (gsi)));
+ gimple_set_uid (sum, get_stmt_uid_with_default (gsi_stmt (gsi)));
gsi_insert_before (&gsi, sum, GSI_NEW_STMT);
}
else
@@ -1207,7 +1211,7 @@ build_and_add_sum (tree type, tree op1, tree op2, enum tree_code opcode)
if (gimple_code (op1def) == GIMPLE_PHI)
{
gsi = gsi_after_labels (gimple_bb (op1def));
- gimple_set_uid (sum, gimple_uid (op1def));
+ gimple_set_uid (sum, get_stmt_uid_with_default (gsi_stmt (gsi)));
gsi_insert_before (&gsi, sum, GSI_NEW_STMT);
}
else
@@ -2860,7 +2864,7 @@ not_dominated_by (gimple a, gimple b)
basic_block bb_a, bb_b;
bb_a = gimple_bb (a);
bb_b = gimple_bb (b);
- return ((bb_a == bb_b && gimple_uid (a) < gimple_uid (b))
+ return ((bb_a == bb_b && gimple_uid (a) < gimple_uid (b))
|| (bb_a != bb_b
&& !dominated_by_p (CDI_DOMINATORS, bb_a, bb_b)));
@@ -2874,10 +2878,7 @@ appears_later_in_bb (gimple stmt1, gimple stmt2)
{
unsigned uid = gimple_uid (stmt1);
gimple_stmt_iterator gsi = gsi_for_stmt (stmt1);
- gsi_next (&gsi);
- if (gsi_end_p (gsi))
- return stmt1;
- for (; !gsi_end_p (gsi); gsi_next (&gsi))
+ for (gsi_next (&gsi); !gsi_end_p (gsi); gsi_next (&gsi))
{
gimple stmt = gsi_stmt (gsi);