<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 --- - Instcombine can't remove a PHI cycle when that cycle should be replaced with a PHI"
   href="https://llvm.org/bugs/show_bug.cgi?id=25585">25585</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Instcombine can't remove a PHI cycle when that cycle should be replaced with a PHI
          </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>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>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>silviu.baranga@arm.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=15319" name="attach_15319" title="The reproducer">attachment 15319</a> <a href="attachment.cgi?id=15319&action=edit" title="The reproducer">[details]</a></span>
The reproducer

For the following IR, instcombine should be able to replace %p1 and %p2 with
%p0.

target triple = "aarch64-linux-gnueabi"

define i32 @f(i1 %c) {
entry:
  br i1 %c, label %if.else, label %pre

if.else:
  br label %pre

pre:
  %p0 = phi i32 [ 0, %entry ], [ 1, %if.else ]
  br label %loop

loop:
  %p1 = phi i32 [ %p2, %loop ], [ %p0, %pre ]
  %p2 = phi i32 [ %p0, %loop ] , [ %p1, %pre ]
  br i1 %c, label %loop, label %exit

exit:
  ret i32 %p2
}

We're already trying to do this, but the current phi cycle elimination
algorithm can't handle the case where the value that we should be replacing
other the PHIs with is another PHI (in this case %p).

When the value that we would replace the PHI cycle with is not a PHI, this
algorithm works as expected:

define i32 @g(i1 %c, i32 %val) {
entry:
  br label %pre

pre:
  br label %loop

loop:
  %p1 = phi i32 [ %p2, %loop ], [ %val, %pre ]
  %p2 = phi i32 [ %val, %loop ] , [ %p1, %pre ]
  br i1 %c, label %loop, label %exit

exit:
  ret i32 %p2
}

Reproduce with: opt -instcombine ind.ll -S -o -</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>