This is the mail archive of the gcc-bugs@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]

[Bug middle-end/65391] unnecessary load of conditionally updated pointer in loop


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

--- Comment #2 from Aaron Sawdey <acsawdey at linux dot vnet.ibm.com> ---
Asm for the test case as in the description (load/store of *o_ptr for every
update):

compute_object_gain:
        ld 9,0(3)
        li 10,0
        std 10,0(4)
        cmpdi 7,9,0
        beqlr 7
        .p2align 5,,31
.L6:
        cmpd 7,5,9
        blt 7,.L3
        ld 10,0(4)
        add 9,10,9
        std 9,0(4)
.L3:
        ldu 9,8(3)
        cmpdi 7,9,0
        bne 7,.L6
        blr

Same test case, but with __restrict__ removed (essentially no difference):
compute_object_gain:
        li 9,0
        std 9,0(4)
        ld 9,0(3)
        cmpdi 7,9,0
        beqlr 7
        .p2align 5,,31
.L6:
        cmpd 7,5,9
        blt 7,.L3
        ld 10,0(4)
        add 9,10,9
        std 9,0(4)
.L3:
        ldu 9,8(3)
        cmpdi 7,9,0
        bne 7,.L6
        blr

Remove the if() and add __restrict__ back (no load or store of *o_ptr in the
loop):
compute_object_gain:
        ld 9,0(3)
        li 8,0
        li 10,0
        std 8,0(4)
        cmpdi 7,9,0
        beqlr 7
        .p2align 4,,15
.L5:
        add 10,10,9
        ldu 9,8(3)
        cmpdi 7,9,0
        bne 7,.L5
        std 10,0(4)
        blr

Remove both the if() and __restrict__ (now store to *o_ptr is in the loop but
no load):
compute_object_gain:
        li 9,0
        li 10,0
        std 9,0(4)
        ld 9,0(3)
        cmpdi 7,9,0
        beqlr 7
        .p2align 5,,31
.L5:
        add 10,10,9
        std 10,0(4)
        ldu 9,8(3)
        cmpdi 7,9,0
        bne 7,.L5
        blr


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