[llvm-bugs] [Bug 37534] New: Dead movs are not eliminated

via llvm-bugs llvm-bugs at lists.llvm.org
Mon May 21 00:50:23 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=37534

            Bug ID: 37534
           Summary: Dead movs are not eliminated
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Keywords: performance
          Severity: enhancement
          Priority: P
         Component: Backend: ARM
          Assignee: unassignedbugs at nondot.org
          Reporter: lidija.besker at rt-rk.com
                CC: llvm-bugs at lists.llvm.org, mips32r2 at gmail.com

While I was going through some code compiled for ARM32 I noticed a number of
what seam to be unneeded movs in code. I will give an example:

typedef struct k
{
    int m;
    int n;
} str_k;

extern int bar2(str_k *, int);

int foo(str_k *a, int b){
        if(a == NULL && b < 0) return 0;
    bar2(a, b);
    return b-a->n; 
}

For this clang generated:

00000000 <foo>:
   0:   e92d4830        push    {r4, r5, fp, lr}
   4:   e28db008        add     fp, sp, #8
   8:   e1a04001        mov     r4, r1
   c:   e1a05000        mov     r5, r0
  10:   e3500000        cmp     r0, #0
  14:   1a000004        bne     2c <foo+0x2c>
  18:   e3a00000        mov     r0, #0
  1c:   e3540000        cmp     r4, #0
  20:   aa000001        bge     2c <foo+0x2c>
  24:   e8bd4830        pop     {r4, r5, fp, lr}
  28:   e12fff1e        bx      lr
  2c:   e1a00005        mov     r0, r5
  30:   e1a01004        mov     r1, r4
  34:   ebfffffe        bl      0 <bar2>
  38:   e5950004        ldr     r0, [r5, #4]
  3c:   e0440000        sub     r0, r4, r0
  40:   e8bd4830        pop     {r4, r5, fp, lr}
  44:   e12fff1e        bx      lr

Line: 
 30:    e1a01004        mov     r1, r4
is unneeded but is generated for both -O3 and -Os optimizations, when removed
tests give expected results.

I had a look further into this problem and think it has something to do with
Machine Copy Propagation Pass (MachineCopyPropagation.cpp to be more exact
function CopyPropagateBlock) where cases like this should be handled but are
not. Reason behind that appears to be that those copy instructions that become
movs are in different blocks and checking is done only on block bases.
Same function is making unneeded movs on the end of function when saving values
by moving it to other registers which are never used and poped at the end.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180521/e91a7abc/attachment.html>


More information about the llvm-bugs mailing list