[llvm-bugs] [Bug 43897] New: LLVM should not remove branches if not profitable

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Nov 4 06:19:41 PST 2019


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

            Bug ID: 43897
           Summary: LLVM should not remove branches if not profitable
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: llvm-bugs at lists.llvm.org

void foo(char **d, char **s, int n, int m) {
    for (int i = 0; i < n; ++i) {
        if (m == 128) // m is usually 128, hot path
            __builtin_memcpy(d[i], s[i], m);
        else
            __builtin_memcpy(d[i], s[i], m);

    }
}

LLVM (Simplify CFG?) removes branch and leaves '__builtin_memcpy(d[i], s[i],
m);'. But here, LLVM was too smart and ignored what I wanted to do - "inlined"
version of memcpy.

If I use:
 if (m == 128) 
            __builtin_memcpy(d[i], s[i], 128);
  else
            __builtin_memcpy(d[i], s[i], m);

Everything is OK. Simplify CFG should not merge branches if it can propagate
constant from condition to one branch.

https://godbolt.org/z/GFfPrb

-- 
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/20191104/8a988d75/attachment.html>


More information about the llvm-bugs mailing list