<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 - LLVM is missing loop splitting"
   href="https://bugs.llvm.org/show_bug.cgi?id=36990">36990</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LLVM is missing loop splitting
          </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>Windows NT
          </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>Scalar Optimizations
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Even for a very simple case:

int foo(int *a, int n, int m) { 
  int s = 0; 
  int i; 
  for (i = 0; i < 1024; i++) 
    if (i != 512) 
      s += a[i]; 
  return s; 


llvm is unable to split loop into 2:

int foo(int *a, int n, int m) { 
  int s = 0; 
  int i; 
  for (i = 0; i < 512; i++) 
    s += a[i]; 
  for (i = 513; i < 1024; i++) 
    s += a[i]; 
  return s; 
}

Generated IR:

; <label>:4:                                      ; preds = %12, %3 
  %5 = phi i64 [ 0, %3 ], [ %14, %12 ] 
  %6 = phi i32 [ 0, %3 ], [ %13, %12 ] 
  %7 = icmp eq i64 %5, 512 
  br i1 %7, label %12, label %8 

; <label>:8:                                      ; preds = %4 
  %9 = getelementptr inbounds i32, i32* %0, i64 %5 
  %10 = load i32, i32* %9, align 4, !tbaa !2 
  %11 = add nsw i32 %10, %6 
  br label %12 

; <label>:12:                                     ; preds = %4, %8 
  %13 = phi i32 [ %11, %8 ], [ %6, %4 ] 
  %14 = add nuw nsw i64 %5, 1 
  %15 = icmp eq i64 %14, 1024 
  br i1 %15, label %16, label %4, !llvm.loop !6 

; <label>:16:                                     ; preds = %12 
  ret i32 %13</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>