[Bug middle-end/92455] Unnecessary memory read in a loop

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Nov 11 13:55:00 GMT 2019


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

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
You need partial-PRE to perform the desired transform.  With -O3 or -O2
-ftree-partial-pre we do what you suggest (plus also cache *max->ptr in
exchange
for another IV):

f1:
.LFB0:
        .cfi_startproc
        movq    (%rdi), %rax
        leaq    40(%rdi), %rcx
        movq    %rdi, %rsi
        movl    (%rax), %edx
.L3:
        movq    8(%rdi), %rax
        addq    $8, %rdi
        movl    (%rax), %eax
        cmpl    %edx, %eax
        jle     .L2
        movl    %eax, %edx
        movq    %rdi, %rsi
.L2:
        cmpq    %rdi, %rcx
        jne     .L3
        movq    (%rsi), %rax
        ret

because of the two conditional values (*max and *max->ptr_) the cmov
transform doesn't trigger.


More information about the Gcc-bugs mailing list