<html>
    <head>
      <base href="http://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 --- - IndVars should preserve nsw when widening IV"
   href="http://llvm.org/bugs/show_bug.cgi?id=16600">16600</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>IndVars should preserve nsw when widening IV
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </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>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>atrick@apple.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=10869" name="attach_10869" title="Jonas' test case">attachment 10869</a> <a href="attachment.cgi?id=10869&action=edit" title="Jonas' test case">[details]</a></span>
Jonas' test case

Passes downstream from IndVars like to see the NSW flags in tact. IV widening
currently removes them because it uses SCEVExpander. I think this is fixable.

Here's an example from Jonas Wagner

I'm using LLVM to reason about memory safety of programs. One goal is to prove
that certain array accesses are always safe.

Currently, one of these proofs fails because of a missing no-signed-wrap (nsw)
flag. I found that it has been "lost" during the SimplifyIndVar pass. Here's
the example:

int foo(int a[]) {
    int sum = 0;
    for (int i = 0; i < 1000; ++i)
        sum += a[i];
    return sum;
}

// *** IR Dump Before Induction Variable Simplification ***
// for.body:                                         ; preds = %entry,
%for.body
//   %i.05 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
//   %sum.04 = phi i32 [ 0, %entry ], [ %add, %for.body ]
//   %idxprom = sext i32 %i.05 to i64
//   %arrayidx = getelementptr inbounds i32* %a, i64 %idxprom
//   %0 = load i32* %arrayidx, align 4, !tbaa !0
//   %add = add nsw i32 %0, %sum.04
//   %inc = add nsw i32 %i.05, 1
//   %cmp = icmp slt i32 %inc, 1000
//   br i1 %cmp, label %for.body, label %for.end
// *** IR Dump After Induction Variable Simplification ***
// for.body:                                         ; preds = %entry,
%for.body
//   %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
//   %sum.04 = phi i32 [ 0, %entry ], [ %add, %for.body ]
//   %arrayidx = getelementptr inbounds i32* %a, i64 %indvars.iv
//   %0 = load i32* %arrayidx, align 4, !tbaa !0
//   %add = add nsw i32 %0, %sum.04
//   %indvars.iv.next = add i64 %indvars.iv, 1
//   %lftr.wideiv = trunc i64 %indvars.iv.next to i32
//   %exitcond = icmp ne i32 %lftr.wideiv, 1000
//   br i1 %exitcond, label %for.body, label %for.end

You can see that %inc is transformed into %indvars.iv.next, and the nsw flag is
lost in the process.</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>