From: Richard Biener Date: Thu, 11 Dec 2014 15:52:47 +0000 (+0000) Subject: re PR tree-optimization/42108 (50% performance regression) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d17271de7f98ec782324307a8840f531831c4509;p=gcc.git re PR tree-optimization/42108 (50% performance regression) 2014-12-11 Richard Biener PR tree-optimization/42108 * trans-stmt.c (gfc_trans_do): Execute the division computing countm1 before the loop entry check. * gfortran.dg/pr42108.f90: Amend. From-SVN: r218630 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 554474c3fc4..3092e3cb4a2 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2014-12-11 Richard Biener + + PR tree-optimization/42108 + * trans-stmt.c (gfc_trans_do): Execute the division computing + countm1 before the loop entry check. + 2014-12-11 Manuel López-Ibáñez PR fortran/44054 diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index d28d67bc82c..1ba382ab193 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -1645,15 +1645,15 @@ gfc_trans_do (gfc_code * code, tree exit_cond) This code is executed before we enter the loop body. We generate: if (step > 0) { + countm1 = (to - from) / step; if (to < from) goto exit_label; - countm1 = (to - from) / step; } else { + countm1 = (from - to) / -step; if (to > from) goto exit_label; - countm1 = (from - to) / -step; } */ @@ -1675,11 +1675,12 @@ gfc_trans_do (gfc_code * code, tree exit_cond) fold_build2_loc (loc, MINUS_EXPR, utype, tou, fromu), stepu); - pos = fold_build3_loc (loc, COND_EXPR, void_type_node, tmp, - fold_build1_loc (loc, GOTO_EXPR, void_type_node, - exit_label), - fold_build2 (MODIFY_EXPR, void_type_node, - countm1, tmp2)); + pos = build2 (COMPOUND_EXPR, void_type_node, + fold_build2 (MODIFY_EXPR, void_type_node, + countm1, tmp2), + build3_loc (loc, COND_EXPR, void_type_node, tmp, + build1_loc (loc, GOTO_EXPR, void_type_node, + exit_label), NULL_TREE)); /* For a negative step, when to > from, exit, otherwise compute countm1 = ((unsigned)from - (unsigned)to) / -(unsigned)step */ @@ -1688,11 +1689,12 @@ gfc_trans_do (gfc_code * code, tree exit_cond) fold_build2_loc (loc, MINUS_EXPR, utype, fromu, tou), fold_build1_loc (loc, NEGATE_EXPR, utype, stepu)); - neg = fold_build3_loc (loc, COND_EXPR, void_type_node, tmp, - fold_build1_loc (loc, GOTO_EXPR, void_type_node, - exit_label), - fold_build2 (MODIFY_EXPR, void_type_node, - countm1, tmp2)); + neg = build2 (COMPOUND_EXPR, void_type_node, + fold_build2 (MODIFY_EXPR, void_type_node, + countm1, tmp2), + build3_loc (loc, COND_EXPR, void_type_node, tmp, + build1_loc (loc, GOTO_EXPR, void_type_node, + exit_label), NULL_TREE)); tmp = fold_build2_loc (loc, LT_EXPR, boolean_type_node, step, build_int_cst (TREE_TYPE (step), 0)); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c6a1932746d..4507037087e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-12-11 Richard Biener + + PR tree-optimization/42108 + * gfortran.dg/pr42108.f90: Amend. + 2014-12-11 Manuel López-Ibáñez * gfortran.dg/do_iterator.f90: Remove bogus dg-warning. diff --git a/gcc/testsuite/gfortran.dg/pr42108.f90 b/gcc/testsuite/gfortran.dg/pr42108.f90 index 9a0a2532a78..020a0a13ac4 100644 --- a/gcc/testsuite/gfortran.dg/pr42108.f90 +++ b/gcc/testsuite/gfortran.dg/pr42108.f90 @@ -1,5 +1,5 @@ ! { dg-do compile } -! { dg-options "-O2 -fdump-tree-fre1" } +! { dg-options "-O2 -fdump-tree-fre1 -fdump-tree-pre-details" } subroutine eval(foo1,foo2,foo3,foo4,x,n,nnd) implicit real*8 (a-h,o-z) @@ -21,7 +21,9 @@ subroutine eval(foo1,foo2,foo3,foo4,x,n,nnd) end do end subroutine eval +! We should have hoisted the division +! { dg-final { scan-tree-dump "in all uses of countm1\[^\n\]* / " "pre" } } ! There should be only one load from n left - ! { dg-final { scan-tree-dump-times "\\*n_" 1 "fre1" } } ! { dg-final { cleanup-tree-dump "fre1" } } +! { dg-final { cleanup-tree-dump "pre" } }