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: [Ping]Two pending IVOPT patches


On Tue, Nov 26, 2013 at 6:06 AM, Jeff Law <law@redhat.com> wrote:
> On 11/25/13 02:11, Bin.Cheng wrote:
>>
>>
>> Slightly tune to make iv cand choosing algorithm more accurate:
>> http://gcc.gnu.org/ml/gcc-patches/2013-11/msg01574.html
>
> It would help if you had some sample codes where this patch was useful.  I
> can kind-of see what's going on, but I'm way too unfamiliar with the tree-IV
> code to review this change.
>
Jeff, Thanks to your review.
As for example, consider below code on ARM/cortex-m4, (the code itself
may be non-sense):

long arr[8][8];
int foo (void)
{
    int i_1, j_1;

    for( i_1 = 0 ; i_1 < 8 ; i_1++ )
      {
        for( j_1 = 0 ; j_1 < 8 ; j_1++ )
          {
            arr[i_1][j_1] = arr[i_1][j_1-1] ;
          }
      }

    return 0;
}

The generated assembly is:
foo:
    @ args = 0, pretend = 0, frame = 0
    @ frame_needed = 0, uses_anonymous_args = 0
    @ link register save eliminated.
    movw    r0, #:lower16:arr
    movt    r0, #:upper16:arr
    push    {r4}
    add    r4, r0, #256
.L2:
    mov    r2, r0
    movs    r3, #0
.L3:
    adds    r3, r3, #1
    ldr    r1, [r2, #-4]
    str    r1, [r2], #4
    cmp    r3, #8
    bne    .L3
    adds    r0, r0, #32
    cmp    r0, r4
    bne    .L2
    movs    r0, #0
    ldr    r4, [sp], #4
    bx    lr
    .size    foo, .-foo


Which can be improved with this patch:

foo:
    @ args = 0, pretend = 0, frame = 0
    @ frame_needed = 0, uses_anonymous_args = 0
    @ link register save eliminated.
    movw    r3, #:lower16:arr
    movt    r3, #:upper16:arr
    add    r0, r3, #256
.L2:
    add    r1, r3, #32
.L3:
    ldr    r2, [r3, #-4]
    str    r2, [r3], #4
    cmp    r1, r3
    bne    .L3
    cmp    r1, r0
    bne    .L2
    movs    r0, #0
    bx    lr

I attached the dump of ivopt pass and it's clear that the candidate 17
can't be selected for use 2 without this patch.

Since the case is highly depends on cost and is very fragile , I
haven't create any test case for it.  Furthermore, the patch may
generate worse code in some case, but I think it's caused by
inaccurate cost and the change itself is reasonable.

Thanks,
bin

-- 
Best Regards.

Attachment: good.ivopts
Description: Binary data

Attachment: bad.ivopts
Description: Binary data


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