https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88784

--- Comment #6 from Fredrik Hederstierna 
<fredrik.hederstie...@securitas-direct.com> ---
Created attachment 46397
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46397&action=edit
Some more patterns

Looking into this I found some more places where it seems to be non-optimal
code, maybe separate issue, but these are also example of equal evaluation for
unsigned types ?

Test 1
  (x > y) || (x > (y / N))   equal to
  (x > (y / N))

Test 2
  (x > y) || (x > (y >> N))  equal to
  (x > (y >> N))

Test 3
  (x > y) && (x > (y / N))   equal to
  (x > y)

Test 4
  (x > y) && (x > (y >> N))  equal to
  (x > y)

One thing to consider here maybe that depending on optimizing for size or
speed, then the order of evaluation can be changed, so like if some operation
is costy, then it could be avoided to obtain higher speed possibly assuming it
will accept arguments prior in list I guess. But when optimizing for size, then
I think always the more simplified expression would apply?

Example for arm using above expressions,
(code attached)

00000000 <test_xy_1_org>:
   0:   b510            push    {r4, lr}
   2:   000b            movs    r3, r1
   4:   0004            movs    r4, r0
   6:   2001            movs    r0, #1
   8:   428c            cmp     r4, r1
   a:   d807            bhi.n   1c <test_xy_1_org+0x1c>
   c:   2103            movs    r1, #3
   e:   0018            movs    r0, r3
  10:   f7ff fffe       bl      0 <__aeabi_uidiv>
  14:   b2c0            uxtb    r0, r0
  16:   42a0            cmp     r0, r4
  18:   4180            sbcs    r0, r0
  1a:   4240            negs    r0, r0
  1c:   bd10            pop     {r4, pc}

0000001e <test_xy_1_equ>:
  1e:   b510            push    {r4, lr}
  20:   0004            movs    r4, r0
  22:   0008            movs    r0, r1
  24:   2103            movs    r1, #3
  26:   f7ff fffe       bl      0 <__aeabi_uidiv>
  2a:   b2c0            uxtb    r0, r0
  2c:   42a0            cmp     r0, r4
  2e:   4180            sbcs    r0, r0
  30:   4240            negs    r0, r0
  32:   bd10            pop     {r4, pc}

00000034 <test_xy_2_org>:
  34:   0003            movs    r3, r0
  36:   2001            movs    r0, #1
  38:   428b            cmp     r3, r1
  3a:   d803            bhi.n   44 <test_xy_2_org+0x10>
  3c:   08c9            lsrs    r1, r1, #3
  3e:   4299            cmp     r1, r3
  40:   4189            sbcs    r1, r1
  42:   4248            negs    r0, r1
  44:   4770            bx      lr

00000046 <test_xy_2_equ>:
  46:   08c9            lsrs    r1, r1, #3
  48:   4281            cmp     r1, r0
  4a:   4180            sbcs    r0, r0
  4c:   4240            negs    r0, r0
  4e:   4770            bx      lr

00000050 <test_xy_3_org>:
  50:   b510            push    {r4, lr}
  52:   000b            movs    r3, r1
  54:   0004            movs    r4, r0
  56:   2000            movs    r0, #0
  58:   428c            cmp     r4, r1
  5a:   d907            bls.n   6c <test_xy_3_org+0x1c>
  5c:   2103            movs    r1, #3
  5e:   0018            movs    r0, r3
  60:   f7ff fffe       bl      0 <__aeabi_uidiv>
  64:   b2c0            uxtb    r0, r0
  66:   42a0            cmp     r0, r4
  68:   4180            sbcs    r0, r0
  6a:   4240            negs    r0, r0
  6c:   bd10            pop     {r4, pc}

0000006e <test_xy_3_equ>:
  6e:   4281            cmp     r1, r0
  70:   4180            sbcs    r0, r0
  72:   4240            negs    r0, r0
  74:   4770            bx      lr

00000076 <test_xy_4_org>:
  76:   0003            movs    r3, r0
  78:   2000            movs    r0, #0
  7a:   428b            cmp     r3, r1
  7c:   d903            bls.n   86 <test_xy_4_org+0x10>
  7e:   08c9            lsrs    r1, r1, #3
  80:   4299            cmp     r1, r3
  82:   4189            sbcs    r1, r1
  84:   4248            negs    r0, r1
  86:   4770            bx      lr

00000088 <test_xy_4_equ>:
  88:   4281            cmp     r1, r0
  8a:   4180            sbcs    r0, r0
  8c:   4240            negs    r0, r0
  8e:   4770            bx      lr

Reply via email to