This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: cosmetic change - simplify cse.c:preferable()
- From: Dodji Seketeli <dodji at seketeli dot org>
- To: Dimitrios Apostolou <jimis at gmx dot net>
- Cc: gcc-patches at gcc dot gnu dot org, Andrey Belevantsev <abel at ispras dot ru>, Richard Henderson <rth at redhat dot com>, Richard Guenther <rguenther at suse dot de>
- Date: Wed, 18 Jul 2012 21:36:41 +0200
- Subject: Re: cosmetic change - simplify cse.c:preferable()
- References: <alpine.LNX.2.02.1207081038340.4288@localhost.localdomain>
Hey Dimitrios,
I can't say much about your patch, so I am CC-ing the maintainers.
Thanks.
Dimitrios Apostolou <jimis@gmx.net> a Ãcrit:
> Hello,
>
> I've had this patch some time now, it's simple and cosmetic only, I
> had done it while trying to understand expression costs in CSE. I
> think it's more readable than the previous one. FWIW it passed all
> tests on x86.
>
>
> Thanks,
> Dimitris
>
> === modified file 'gcc/cse.c'
> --- gcc/cse.c 2012-06-15 09:22:00 +0000
> +++ gcc/cse.c 2012-07-08 07:28:52 +0000
> @@ -713,32 +713,25 @@ approx_reg_cost (rtx x)
> static int
> preferable (int cost_a, int regcost_a, int cost_b, int regcost_b)
> {
> - /* First, get rid of cases involving expressions that are entirely
> - unwanted. */
> - if (cost_a != cost_b)
> - {
> - if (cost_a == MAX_COST)
> - return 1;
> - if (cost_b == MAX_COST)
> - return -1;
> - }
> + int cost_diff = cost_a - cost_b;
> + int regcost_diff = regcost_a - regcost_b;
>
> - /* Avoid extending lifetimes of hardregs. */
> - if (regcost_a != regcost_b)
> + if (cost_diff != 0)
> {
> - if (regcost_a == MAX_COST)
> - return 1;
> - if (regcost_b == MAX_COST)
> - return -1;
> + /* If none of the expressions are entirely unwanted */
> + if ((cost_a != MAX_COST) && (cost_b != MAX_COST)
> + /* AND only one of the regs is HARD_REG */
> + && (regcost_diff != 0)
> + && ((regcost_a == MAX_COST) || (regcost_b == MAX_COST))
> + )
> + /* Then avoid extending lifetime of HARD_REG */
> + return regcost_diff;
> +
> + return cost_diff;
> }
>
> - /* Normal operation costs take precedence. */
> - if (cost_a != cost_b)
> - return cost_a - cost_b;
> - /* Only if these are identical consider effects on register pressure. */
> - if (regcost_a != regcost_b)
> - return regcost_a - regcost_b;
> - return 0;
> + /* cost_a == costb, consider effects on register pressure */
> + return regcost_diff;
> }
>
> /* Internal function, to compute cost when X is not a register; called
>
--
Dodji