This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: useless cast blocking some optimization in gcc 4.7.3


On Mon, Apr 8, 2013 at 9:13 PM, Laurent Alfonsi <laurent.alfonsi@st.com> wrote:
>     Hello,
>
> 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
> chars.
>   - It is now type-promoted to "int" when it is written "result += foo()".
> (since 4.7)
>   - 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 */
> into :
>     a1 + a2
>
> I believe this is legal for any licit a1/a2 input values (no overflow on
> signed char).
> No new failure on the two tested targets : sh-superh-elf and
> x86_64-unknown-linux-gnu.
> 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
help you.

Richard.

> 2013-04-08  Laurent Alfonsi  <laurent.alfonsi@st.com>
>
>        * fold-const.c (fold_unary_loc): Suppress useless type promotion.
>
>
> Thanks,
> Laurent
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]