<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - if (auto x = y(z)) generates bad/slow code (found via analysis of dyn_cast)"
   href="https://bugs.llvm.org/show_bug.cgi?id=35790">35790</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>if (auto x = y(z)) generates bad/slow code (found via analysis of dyn_cast)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Interprocedural Optimizations
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>dave@znu.io
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>