[PATCH] Teach IndVarSimplify to add nuw and nsw to operations that provably don't overflow.
Sanjoy Das
sanjoy at playingwithpointers.com
Sun Dec 21 01:37:49 PST 2014
Hi atrick, majnemer, hfinkel,
This patch teaches IndVarSimplify to add `nuw` and `nsw` to certain kinds of operations that provably don't overflow. For example, we can prove `%civ.inc` below does not sign-overflow. With this change, `IndVarSimplify` changes `%civ.inc` to an `add nsw`.
```
define i32 @foo(i32* %array, i32* %length_ptr, i32 %init) {
entry:
%length = load i32* %length_ptr, !range !0
%len.sub.1 = sub i32 %length, 1
%upper = icmp slt i32 %init, %len.sub.1
br i1 %upper, label %loop, label %exit
loop:
%civ = phi i32 [ %init, %entry ], [ %civ.inc, %latch ]
%civ.inc = add i32 %civ, 1
%cmp = icmp slt i32 %civ.inc, %length
br i1 %cmp, label %latch, label %break
latch:
store i32 0, i32* %array
%check = icmp slt i32 %civ.inc, %len.sub.1
br i1 %check, label %loop, label %break
break:
ret i32 %civ.inc
exit:
ret i32 42
}
```
http://reviews.llvm.org/D6748
Files:
lib/Transforms/Utils/SimplifyIndVar.cpp
test/Transforms/BBVectorize/loop1.ll
test/Transforms/IndVarSimplify/2011-09-10-widen-nsw.ll
test/Transforms/IndVarSimplify/strengthen-overflow.ll
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D6748.17535.patch
Type: text/x-patch
Size: 12529 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141221/d1e200f7/attachment.bin>
More information about the llvm-commits
mailing list