[llvm-bugs] [Bug 35790] New: if (auto x = y(z)) generates bad/slow code (found via analysis of dyn_cast)

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jan 1 15:35:30 PST 2018


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

            Bug ID: 35790
           Summary: if (auto x = y(z)) generates bad/slow code (found via
                    analysis of dyn_cast)
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Interprocedural Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: dave at znu.io
                CC: llvm-bugs at lists.llvm.org

While analyzing Swift compiler performance, I found that that LLVM's dyn_cast
generates suboptimal and surprising code gen. I've reduced it down to a test
case that still reproduces on top-of-tree on my Linux box when compiling with
-O3:

//__attribute__((used,noinline))
int *x(void *arg) {
        return ((long long)arg & 1) ? (int *)arg : nullptr;
}

int test(void *arg) {
        if (auto y = x(arg)) return *y;
        return 42;
}

If 'x' is inlined, then the compiler effectively generates the following
surprising pseudo code:

int test(void *arg) {
  if (arg != nullptr)
    if (arg & 1)
      return *arg;
  return 42;
}

If 'x' is not inlined. then 'arg' passed to 'test' is not (as expected) NULL
tested by either 'test' or 'x'.

This seems like a a weird inlining versus "if (auto x = y(z))" bug.

-- 
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/20180101/2e2f68c6/attachment.html>


More information about the llvm-bugs mailing list