<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 --- - IndVarSimplify breaks LCSSA form, while saying it's preserved"
   href="https://llvm.org/bugs/show_bug.cgi?id=25578">25578</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>IndVarSimplify breaks LCSSA form, while saying it's preserved
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Loop Optimizer
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>michael.v.zolotukhin@gmail.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>Applied on the following test case, IndVarSimplify introduces a definition
without corresponding LCSSA phi nodes, thus breaking LCSSA:

--------------------------------------------
; RUN: opt < %s -indvars -S | FileCheck %s
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"

; CHECK-LABEL: @foo
define void @foo() {
entry:
  br label %L1_header

L1_header:
  br label %L2_header

; CHECK: L2_header:
; CHECK: %[[INDVAR:.*]] = phi i64
L2_header:
  %i = phi i32 [ 0, %L1_header ], [ %i_next, %L2_latch ]
  %i_prom = sext i32 %i to i64
  br label %L3_header

; CHECK: L3_header:
; CHECK: %[[TRUNC:.*]] = trunc i64 %[[INDVAR]] to i32
L3_header:
  br i1 undef, label %L3_latch, label %L2_exiting_1

L3_latch:
  br i1 undef, label %L3_header, label %L2_exiting_2

; CHECK: L2_exiting_1:
; CHECK: %{{.*}} = phi i32 [ %[[TRUNC]], %L3_header ]
L2_exiting_1:
  br i1 undef, label %L2_latch, label %L1_latch

; CHECK: L2_exiting_2:
; CHECK: %{{.*}} = phi i32 [ %[[TRUNC]], %L3_latch ]
L2_exiting_2:
  br i1 undef, label %L2_latch, label %L1_latch

L2_latch:
  %i_next = add nsw i32 %i, 1
  br label %L2_header

L1_latch:
  %i_lcssa = phi i32 [ %i, %L2_exiting_1 ], [ %i, %L2_exiting_2 ]
  br i1 undef, label %exit, label %L1_header

exit:
  ret void
}
--------------------------------------------

When it promotes an i32 induction variable to i64, it has to insert trunc
instruction before uses of the original i32 variable. In this case such use is
a phi-node(%i_lcssa in L1_latch), so it finds the nearest block that dominates
all corresponding incoming blocks (L2_exiting_1 and L2_exiting_2), and inserts
"%0 = trunc ..." there (into L3_header). However, this insertion point happens
to be in a loop (L3), so this definition is inside a loop, while its uses are
outside the loop. IndVarSimplify doesn't insert corresponding phi-nodes, and
thus breaks LCSSA.</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>