2012-03-23 01:09:04 +08:00
|
|
|
; RUN: opt < %s -indvars -S | FileCheck %s
|
2011-09-13 01:20:57 +08:00
|
|
|
; Test WidenIV::GetExtendedOperandRecurrence.
|
2014-08-21 16:25:45 +08:00
|
|
|
; %add, %sub and %mul should be extended to i64 because it is nsw, even though its
|
2011-09-13 01:20:57 +08:00
|
|
|
; sext cannot be hoisted outside the loop.
|
|
|
|
|
|
|
|
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
|
|
|
|
|
|
|
|
define void @test() nounwind {
|
|
|
|
entry:
|
|
|
|
br i1 undef, label %for.body11, label %for.end285
|
|
|
|
|
|
|
|
for.body11: ; preds = %entry
|
|
|
|
%shl = shl i32 1, 1
|
|
|
|
%shl132 = shl i32 %shl, 1
|
|
|
|
br label %for.body153
|
|
|
|
|
|
|
|
for.body153: ; preds = %for.body153, %for.body11
|
|
|
|
br i1 undef, label %for.body170, label %for.body153
|
|
|
|
|
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
}
Differential Revision: http://reviews.llvm.org/D6748
llvm-svn: 225282
2015-01-07 03:02:56 +08:00
|
|
|
; CHECK: add nuw nsw i64 %indvars.iv, 1
|
2014-08-21 16:25:45 +08:00
|
|
|
; CHECK: sub nsw i64 %indvars.iv, 2
|
2014-10-02 21:01:15 +08:00
|
|
|
; CHECK: sub nsw i64 4, %indvars.iv
|
|
|
|
; CHECK: mul nsw i64 %indvars.iv, 8
|
2011-09-13 01:20:57 +08:00
|
|
|
for.body170: ; preds = %for.body170, %for.body153
|
2011-11-29 08:52:04 +08:00
|
|
|
%i2.19 = phi i32 [ %add249, %for.body170 ], [ 0, %for.body153 ]
|
2014-08-21 16:25:45 +08:00
|
|
|
|
|
|
|
%add = add nsw i32 %i2.19, 1
|
|
|
|
%add.idxprom = sext i32 %add to i64
|
|
|
|
|
|
|
|
%sub = sub nsw i32 %i2.19, 2
|
|
|
|
%sub.idxprom = sext i32 %sub to i64
|
|
|
|
|
2014-10-02 21:01:15 +08:00
|
|
|
%sub.neg = sub nsw i32 4, %i2.19
|
|
|
|
%sub.neg.idxprom = sext i32 %sub.neg to i64
|
|
|
|
|
|
|
|
%mul = mul nsw i32 %i2.19, 8
|
2014-08-21 16:25:45 +08:00
|
|
|
%mul.idxprom = sext i32 %mul to i64
|
|
|
|
|
2011-09-13 01:20:57 +08:00
|
|
|
%add249 = add nsw i32 %i2.19, %shl132
|
|
|
|
br label %for.body170
|
|
|
|
for.end285: ; preds = %entry
|
|
|
|
ret void
|
|
|
|
}
|