<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - SimplifyCFG blocks SROA optimization"
   href="https://llvm.org/bugs/show_bug.cgi?id=30188">30188</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>SimplifyCFG blocks SROA optimization
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

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

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

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>danielcdh@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>davidxl@google.com, james.molloy@arm.com, llvm-bugs@lists.llvm.org, wmi@google.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>struct b {
  int x_;
};

struct a {
  int l_;
  struct b *data_;
};

int BinarySearch(struct a *input, struct b t) {
  if (input->l_ > 0) {
    int low = 0;
    int high = input->l_;
    while (high != low + 1) {
      int mid = (high + low) / 2;
      if (input->data_[mid].x_ > t.x_)
        high = mid;
      else
        low = mid;
    }
    return low;
  }
  return -1;
}

The bug issue was introduced by
<a href="http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160822/384231.html">http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160822/384231.html</a>

Without the patch, the inner loop x86 code (compiled at -O2):

        leal    (%rcx,%rax), %edx
        movl    %edx, %edi
        shrl    $31, %edi
        addl    %edx, %edi
        sarl    %edi
        movslq  %edi, %rdx
        cmpl    %esi, (%r8,%rdx,4)
        cmovlel %edx, %eax
        cmovgl  %edx, %ecx
        leal    1(%rax), %edx
        cmpl    %edx, %ecx
        jne     .LBB0_3

With the patch:

        addl    %ecx, %eax
        movl    %eax, %ecx
        shrl    $31, %ecx
        addl    %eax, %ecx
        sarl    %ecx
        movslq  %ecx, %rax
        cmpl    %esi, (%rdx,%rax,4)
        movq    %r9, %rcx
        cmovgq  %r8, %rcx
        movl    %eax, (%rcx)
        movl    -8(%rsp), %ecx
        movl    -4(%rsp), %eax
        leal    1(%rax), %edi
        cmpl    %edi, %ecx
        jne     .LBB0_3

2 more memory store instructions are generated.

This is because when simplifycfg combines 2 store address into a select, SROA
can no longer find the pairing for instruction addresses between load and
store, thus the store cannot be removed.</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>