[llvm-bugs] [Bug 37535] New: Dead condition left after removal of branch that used it

via llvm-bugs llvm-bugs at lists.llvm.org
Mon May 21 00:52:40 PDT 2018


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

            Bug ID: 37535
           Summary: Dead condition left after removal of branch that used
                    it
           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

I have been looking into some code compiled for ARM32 using LLVM and I noticed
that in some cases -O3 and -Os optimizations leave excess instructions. I have
made a mini example where that can be seen:

typedef union df_union {
        int    *set;
        int     state;
} df;

int n;
df *d;

int foo1(int index){
        if ((n && !d[index].set) || (!n && !d[index].state)) {
                return --index;                 
        }                       
        return 0;       
}


For this clang generated: 

00000000 <foo1>:
   0:   e59f1024        ldr     r1, [pc, #36]   ; 2c <foo1+0x2c>
   4:   e59f2024        ldr     r2, [pc, #36]   ; 30 <foo1+0x30>
   8:   e5922000        ldr     r2, [r2]
   c:   e5911000        ldr     r1, [r1]
  10:   e3520000        cmp     r2, #0
  14:   e7912100        ldr     r2, [r1, r0, lsl #2]
  18:   e3a01000        mov     r1, #0
  1c:   e3520000        cmp     r2, #0
  20:   02401001        subeq   r1, r0, #1
  24:   e1a00001        mov     r0, r1
  28:   e12fff1e        bx      lr


cmp and loads that it uses are excess and when removed function continues to
give expected result. 

I had a look into it and it appears to be caused by merging of basic blocks and
removal of conditional branch whose condition is computed using excess
instructions which are left behind. This happens in Control Flow Optimizes pass
in BranchFolding.cpp in function OptimizeBlock where ARM's removeBranch is
called, none of them removes condition calculation.

-- 
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/e730f9af/attachment.html>


More information about the llvm-bugs mailing list