http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51697
Bug #: 51697 Summary: SH Target: Inefficient DImode comparisons for -Os Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: target AssignedTo: unassig...@gcc.gnu.org ReportedBy: oleg.e...@t-online.de CC: kkoj...@gcc.gnu.org Target: sh*-*-* For -Os and everything but -m1 DImode comparisons are not optimized properly which results in redundant SImode comparisons, producing code worse than for -O1. A reduced example: int test_0 (long long* x) { return *x & 0xFFFFFFFF ? -20 : -40; } -Os -m2/-m3/-m4: mov #0,r2 ! 55 movsi_ie/3 [length = 2] tst r2,r2 ! 57 cmpeqsi_t/1 [length = 2] bf/s .L12 ! 58 branch_false [length = 2] mov.l @(4,r4),r3 ! 12 movsi_ie/7 [length = 2] tst r3,r3 ! 59 cmpeqsi_t/1 [length = 2] .L12: bt/s .L11 ! 14 branch_true [length = 2] mov #-40,r0 ! 5 movsi_ie/3 [length = 2] mov #-20,r0 ! 4 movsi_ie/3 [length = 2] .L11: rts nop ! 65 *return_i [length = 4] -Os -m1: -O2 -m4: mov.l @(4,r4),r1 ! 10 movsi_i/5 [length = 2] mov #-40,r0 ! 5 movsi_i/3 [length = 2] tst r1,r1 ! 15 cmpeqsi_t/1 [length = 2] bt .L7 ! 16 branch_true [length = 2] mov #-20,r0 ! 4 movsi_i/3 [length = 2] .L7: rts nop ! 61 *return_i [length = 4] -O1 -m4: mov.l @(4,r4),r1 ! 10 movsi_ie/7 [length = 2] tst r1,r1 ! 17 cmpeqsi_t/1 [length = 2] bt/s .L6 ! 18 branch_true [length = 2] mov #-40,r0 ! 5 movsi_ie/3 [length = 2] mov #-20,r0 ! 4 movsi_ie/3 [length = 2] .L6: rts nop ! 62 *return_i [length = 4] Another example would be: int test_2 (unsigned long long x) { return x >= 0x100000000LL ? -20 : -40; } -Os -m2/-m3/-m4: mov #0,r2 ! 48 movsi_ie/3 [length = 2] mov #-1,r3 ! 49 movsi_ie/3 [length = 2] cmp/eq r2,r4 ! 9 cmpgtudi_t [length = 8] bf/s .Ldi67 cmp/hi r2,r4 cmp/hi r3,r5 .Ldi67: bf/s .L16 ! 10 branch_false [length = 2] mov #-40,r0 ! 5 movsi_ie/3 [length = 2] mov #-20,r0 ! 4 movsi_ie/3 [length = 2] .L16: rts nop ! 52 *return_i [length = 4] -Os -m1: tst r4,r4 ! 9 cmpeqsi_t/1 [length = 2] mov #-20,r0 ! 4 movsi_i/3 [length = 2] bf .L12 ! 10 branch_false [length = 2] mov #-40,r0 ! 5 movsi_i/3 [length = 2] .L12: rts nop ! 56 *return_i [length = 4] The problem does not appear for -m1, only for -Os and -m2*, -m3*, -m4*.