https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65214
Bug ID: 65214 Summary: [SH] Optimize sign/zero extensions across basic blocks Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: olegendo at gcc dot gnu.org Target: sh*-*-* This is an example from gcc.c-torture/execute/pr20187-1.c: int a = 0x101; int b = 0x100; int test (void) { return (((unsigned char) (unsigned long long) ((a ? a : 1) & (a * b))) ? 0 : 1); } compiled with -m4 -ml -O2 -fdisable-rtl-dbr: mov.l .L6,r1 mov.l @r1,r2 mov #1,r1 // r1 is zero extended after constant load tst r2,r2 bt .L2 exts.b r2,r1 .L2: mov.l .L7,r3 extu.b r1,r1 // r1 = extu.b (exts.b (r2)) mov.l @r3,r3 mulu.w r2,r3 sts macl,r3 tst r3,r1 movt r0 rts nop The extu.b basically overrides result of exts.b. Thus we can replace the exts.b with extu.b and eliminate one insn: mov.l .L6,r1 mov.l @r1,r2 mov #1,r1 tst r2,r2 bt .L2 extu.b r2,r1 .L2: mov.l .L7,r3 mov.l @r3,r3 mulu.w r2,r3 sts macl,r3 tst r3,r1 movt r0 rts nop