diff options
author | Richard Biener <rguenther@suse.de> | 2014-12-11 15:52:47 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2014-12-11 15:52:47 +0000 |
commit | d17271de7f98ec782324307a8840f531831c4509 (patch) | |
tree | 83a5e16407fda4f8d1b8d7ae328e0054a656a7f6 /gcc/fortran/trans-stmt.c | |
parent | b214b73391d67f9a0dbb8807912330289973982a (diff) | |
download | gcc-d17271de7f98ec782324307a8840f531831c4509.tar.gz |
re PR tree-optimization/42108 (50% performance regression)
2014-12-11 Richard Biener <rguenther@suse.de>
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
Diffstat (limited to 'gcc/fortran/trans-stmt.c')
-rw-r--r-- | gcc/fortran/trans-stmt.c | 26 |
1 files changed, 14 insertions, 12 deletions
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)); |