<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 - Interprocedural Sparse Conditional Constant Propagation generates incorrect code"
   href="https://bugs.llvm.org/show_bug.cgi?id=39772">39772</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Interprocedural Sparse Conditional Constant Propagation generates incorrect code
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </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>Interprocedural Optimizations
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=21148" name="attach_21148" title="Program that reproduces issue">attachment 21148</a> <a href="attachment.cgi?id=21148&action=edit" title="Program that reproduces issue">[details]</a></span>
Program that reproduces issue

The attached program generates incorrect code. Specifically, this clause:

    if (left_height > right_height) {
        return left_height + 1;
    } else {
        return right_height + 1;
    }

Always returns 1 if it hits the else condition (left_height is not greater than
right_height). You can see the generated LLVM IR below. Note that, the phi node
will return 1 if it branches from %if.else:

if.end5:                                          ; preds = %if.end
  %cmp6 = icmp sgt i32 %call, %call1
  br i1 %cmp6, label %if.then7, label %if.else

if.then7:                                         ; preds = %if.end5
  %add = add nsw i32 %call, 1
  br label %cleanup

if.else:                                          ; preds = %if.end5
  br label %cleanup

cleanup:                                          ; preds = %if.else,
%if.then7, %if.then
  %retval.0 = phi i32 [ 0, %if.then ], [ %add, %if.then7 ], [ 1, %if.else ]
  ret i32 %retval.0
}

If I add the parameter -mllvm -opt-bisect-limit=6, it still generates incorrect
code as above, bug if I change the parameter to 5, it no longer does, which
corresponds to this pass:

BISECT: running pass (6) Interprocedural Sparse Conditional Constant
Propagation on module (bug-min.c)

This behavior started some time between SVN revision 329504 and 346103. It
still happens as of 347515.

I don't think this is clang specific, but I couldn't figure out how to
reproduce with opt (I generated LLVM IR code from clang with -O0, but running
with opt -O3 did not seem to optimize anything).</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>