[LLVMbugs] [Bug 16600] New: IndVars should preserve nsw when widening IV
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Thu Jul 11 10:50:47 PDT 2013
http://llvm.org/bugs/show_bug.cgi?id=16600
Bug ID: 16600
Summary: IndVars should preserve nsw when widening IV
Product: new-bugs
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: atrick at apple.com
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
Created attachment 10869
--> http://llvm.org/bugs/attachment.cgi?id=10869&action=edit
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130711/e41399a3/attachment.html>
More information about the llvm-bugs
mailing list