This is the mail archive of the
mailing list for the GCC project.
Re: useless cast blocking some optimization in gcc 4.7.3
- From: Laurent Alfonsi <laurent dot alfonsi at st dot com>
- To: Richard Biener <richard dot guenther at gmail dot com>
- Cc: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 9 Apr 2013 17:31:12 +0200
- Subject: Re: useless cast blocking some optimization in gcc 4.7.3
- References: <516316EF dot 6080806 at st dot com> <CAFiYyc0axHBJQP0e-=UL=vDMxz3Pt4f5o7dqvXJL9vOvc1pTEw at mail dot gmail dot com>
I understand, Thanks for your answer.
Looking at the standard, I was thinking the example you pointed was
I have created a bugzilla
(http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56894) to track this big
My investigations pointed on the scev_const_prop optimization.
The scalar evolution of "result" variable in the loop cannot be computed
because of the cast :
type <integer_type 0xf7de32a0 char sizes-gimplified public string-flag
arg 0 <polynomial_chrec 0xf7ecd180
type <integer_type 0xf7de33c0 int sizes-gimplified public type_6
arg 0 <integer_cst 0xf7dcbe70 constant 2>
arg 1 <integer_cst 0xf7dcba80 constant 0>
arg 2 <integer_cst 0xf7dcba9c constant 1>>>
I don't know how to fix the case. But I believe it should be looked at,
as it is a quite big perf regression in some testcases.
Also, I didn't find the bugzilla that led to this change of the +=
operation. I would be interested to have a look at it, if you can find it.
On 09.04.2013 10:50, Richard Biener wrote:
On Mon, Apr 8, 2013 at 9:13 PM, Laurent Alfonsi <email@example.com> wrote:
I have identified a big performance regression between 4.6 and 4.7. (I have
enclosed a pathological test).
After investigation, it is because of the += statement applied on 2 signed
- It is now type-promoted to "int" when it is written "result += foo()".
- it is type promoted to "unsigned char" when it is written "result =
result + foo()".
The "char->int->char" cast is blocking some optimizations in later phases.
Anyway, this doesn't look wrong, so I extended fold optimization in order to
catch this case. (patch enclosed)
The patch basically transforms :
(TypeA) ( (TypeB) a1 + (TypeB) a2 ) /* with a1 and a2 of
the signed type TypeA */
a1 + a2
I believe this is legal for any licit a1/a2 input values (no overflow on
No new failure on the two tested targets : sh-superh-elf and
Should I enter a bugzilla to track this ? Is it ok for trunk ?
Please open a bugzilla. No, the patch is not ok, as said by Marc.
It's possible to shorten the operation by performing it using
unsigned arithmetic, that is (signed)((unsigned)a1 + (unsigned)a2).
But if really "casts" cause the issue you are seeing that will not
2013-04-08 Laurent Alfonsi <firstname.lastname@example.org>
* fold-const.c (fold_unary_loc): Suppress useless type promotion.