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: unassignedb...@nondot.org
          Reporter: david.bolvan...@gmail.com
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to