https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63548
Bug ID: 63548 Summary: redundent reload in loop after removing regmove Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: wmi at google dot com Created attachment 33730 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33730&action=edit testcase 1.c For program with many insns like "a = b + c", where operands "b" and "c" are both dead immediately after the add insn, the hardreg preference heuristic seems not perfect. Here is a testcase 1.c, For gcc after r204212, they generates two redundent reload insns caused by imperfect hardreg preference heuristic in IRA. ~/workarea/gcc-r214579/build/install/bin/gcc -O2 -S 1.c .L5: movl %ebx, %edi call goo leal 2(%rbx), %edi movl %eax, %r13d call goo leal 4(%rbx), %edi movl %eax, %r12d call goo leal 6(%rbx), %edi movl %eax, %ebp addl $1, %ebx call goo movl %eax, %edx // redundent mov movl %r13d, %eax // redundent mov imull %r12d, %eax imull %ebp, %eax imull %edx, %eax addl %eax, total(%rip) cmpl %ebx, M(%rip) jg .L5 For old gcc with regmove, it happens to be better than hardreg preference heuristic and generates one redundent reload. ~/workarea/gcc-r199418/build/install/bin/gcc -O2 -S 1.c .L3: movl %ebx, %edi call goo leal 2(%rbx), %edi movl %eax, %r13d call goo leal 4(%rbx), %edi movl %eax, %r12d call goo leal 6(%rbx), %edi movl %eax, %ebp addl $1, %ebx call goo movl %r13d, %edx // redundent mov imull %r12d, %edx imull %ebp, %edx imull %eax, %edx addl %edx, total(%rip) cmpl %ebx, M(%rip) jg .L3 llvm generates no redundent move insn. clang-r217862 -O2 -S 1.c .LBB0_2: movl %ebx, %edi callq goo movl %eax, %r14d leal 2(%rbx), %edi callq goo movl %eax, %ebp leal 4(%rbx), %edi callq goo movl %eax, %r15d leal 6(%rbx), %edi callq goo imull %r14d, %ebp imull %r15d, %ebp imull %eax, %ebp addl %ebp, total(%rip) incl %ebx cmpl M(%rip), %ebx jl .LBB0_2