[llvm-bugs] [Bug 27209] New: failure to optimize a simple loop to a memset call (incorrect fear of aliasing?)

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Apr 4 16:53:25 PDT 2016


            Bug ID: 27209
           Summary: failure to optimize a simple loop to a memset call
                    (incorrect fear of aliasing?)
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: richard-llvm at metafoo.co.uk
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

LLVM fails to optimize this simple loop to a memset:

void f(char *p, char *q) {
  for (char *r = q; r != q + 256; ++r) *r = *p;

Presumably the relevant optimization is not firing here because of fear that p
might alias some element of the array pointed at by q. However, that doesn't
matter, because *p is the only thing written to that array, and the store size
is the same as the alignment, so *p can never actually change as a result.

See also https://llvm.org/bugs/show_bug.cgi?id=27206 -- LLVM should at least be
able to optimize that if the type of the field within struct S is char, and
should be able to hoist the load of s.i out of the loop for any type where size
== alignment. (And using C++ object lifetime rules, the hoisting is always
permitted regardless of alignment.)

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/20160404/1d8cb17b/attachment.html>

More information about the llvm-bugs mailing list