This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PR 54168: Unnecessary narrowing in tree-ssa-forwprop pass?
- From: Richard Earnshaw <rearnsha at arm dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: Kyrylo Tkachov <Kyrylo dot Tkachov at arm dot com>, Richard Biener <richard dot guenther at gmail dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 14 Jan 2014 15:14:23 +0000
- Subject: Re: PR 54168: Unnecessary narrowing in tree-ssa-forwprop pass?
- Authentication-results: sourceware.org; auth=none
- References: <52D543C9 dot 4060105 at arm dot com> <CAFiYyc2s-9txxRH820mfV1B6W+WiSyCJZtHbuo1VL=UYaUMAtw at mail dot gmail dot com> <52D54800 dot 4080101 at arm dot com> <20140114143203 dot GO892 at tucnak dot redhat dot com> <52D54E7A dot 9000809 at arm dot com>
On 14/01/14 14:49, Richard Earnshaw wrote:
> On 14/01/14 14:32, Jakub Jelinek wrote:
>> Anyway, the above is really a simple case, and I'd call it a
>> backend bug if it isn't able to generate good code out of that.
>
> Exactly which back-end pass are you expecting to simplify
>
> (set (subreg:SI (reg:HI 1) 0) (and:SI (subreg:SI (reg:HI 0) 0)
> (const_int 2)))
>
> (set (reg:SI 2) (zero_extend:SI (reg:HI 1)))
>
> (set (reg:SI 3) (ne:SI (reg:SI 2) (const_int 0)))
>
> into
>
> (set (reg:SI 2) (and:SI (subreg:SI (reg:HI 0) 0) (const_int 2)))
>
> (set (reg:SI 3) (ne:SI (reg:SI 2) (const_int 0)))
>
> Combine is about the only pass that does this sort of thing, and that's
> far too often confused by extraneous information that it thinks might be
> helpful, but isn't, or by the fact that the intermediate result is used
> more than once.
>
> R.
>
Consider this case:
struct b2Body {
unsigned short flags;
int type;
};
_Bool IsAwake(short *a, struct b2Body *b)
{
int c;
c = b->flags & 2;
*a = c;
return c == 2;
}
There's a redundant extend operation left in here on ARM, MIPS & PPC.
ARM:
ldrh r3, [r1]
and r3, r3, #2
uxth r3, r3 // Redundant
strh r3, [r0]
adds r0, r3, #0
movne r0, #1
bx lr
MIPS
lhu $2,0($5)
nop
andi $2,$2,0x2
andi $2,$2,0xffff // Redundant
sh $2,0($4)
j $31
sltu $2,$0,$2
PPC:
lhz 9,0(4)
rlwinm 9,9,0,30,30
rlwinm 9,9,0,0xffff // Redundant
sth 9,0(3)
addic 10,9,-1
subfe 3,10,9
blr
So if this is a backend issue, it's wide-spread on word-based machines.
R.