From: Sebastian Pop Date: Thu, 11 Feb 2010 15:45:27 +0000 (+0000) Subject: re PR regression/40886 (No loop counter reversal for simple loops anymore) X-Git-Tag: releases/gcc-4.5.0~814 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=04eadb13265b69db0282da8803f13e357a129079;p=thirdparty%2Fgcc.git re PR regression/40886 (No loop counter reversal for simple loops anymore) Fix PR40886. 2010-02-11 Sebastian Pop Changpeng Fang PR middle-end/40886 * tree-ssa-loop-ivopts.c (determine_use_iv_cost_condition): Decrement the cost of an IV candidate when the IV is used in a test against zero. * gcc.dg/tree-ssa/ivopts-3.c: New. Co-Authored-By: Changpeng Fang From-SVN: r156701 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 70deed75ece3..52d1a1abc4a9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2010-02-11 Sebastian Pop + Changpeng Fang + + PR middle-end/40886 + * tree-ssa-loop-ivopts.c (determine_use_iv_cost_condition): Decrement + the cost of an IV candidate when the IV is used in a test against zero. + + * gcc.dg/tree-ssa/ivopts-3.c: New. + 2010-02-11 Richard Guenther PR lto/41664 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ivopts-3.c b/gcc/testsuite/gcc.dg/tree-ssa/ivopts-3.c new file mode 100644 index 000000000000..7c4236b1cc73 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ivopts-3.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-ivopts-details" } */ + +void main (void) +{ + int i; + for (i = 0; i < 10; i++) + f2 (); +} + +/* { dg-final { scan-tree-dump-times "!= 0" 4 "ivopts" } } */ +/* { dg-final { cleanup-tree-dump "ivopts" } } */ diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c index 436e6ce8fc47..74dadf778979 100644 --- a/gcc/tree-ssa-loop-ivopts.c +++ b/gcc/tree-ssa-loop-ivopts.c @@ -4089,6 +4089,7 @@ determine_use_iv_cost_condition (struct ivopts_data *data, bitmap depends_on_elim = NULL, depends_on_express = NULL, depends_on; comp_cost elim_cost, express_cost, cost; bool ok; + tree *control_var, *bound_cst; /* Only consider real candidates. */ if (!cand->iv) @@ -4110,9 +4111,21 @@ determine_use_iv_cost_condition (struct ivopts_data *data, /* Try expressing the original giv. If it is compared with an invariant, note that we cannot get rid of it. */ - ok = extract_cond_operands (data, use->stmt, NULL, NULL, NULL, &cmp_iv); + ok = extract_cond_operands (data, use->stmt, &control_var, &bound_cst, + NULL, &cmp_iv); gcc_assert (ok); + /* When the condition is a comparison of the candidate IV against + zero, prefer this IV. + + TODO: The constant that we're substracting from the cost should + be target-dependent. This information should be added to the + target costs for each backend. */ + if (integer_zerop (*bound_cst) + && (operand_equal_p (*control_var, cand->var_after, 0) + || operand_equal_p (*control_var, cand->var_before, 0))) + elim_cost.cost -= 1; + express_cost = get_computation_cost (data, use, cand, false, &depends_on_express, NULL); fd_ivopts_data = data;