-; RUN: opt < %s -indvars -disable-iv-rewrite -S | FileCheck %s
+; RUN: opt < %s -indvars -S | FileCheck %s
;
; Make sure that indvars isn't inserting canonical IVs.
; This is kinda hard to do until linear function test replacement is removed.
; back to the loop iv.
;
; CHECK: loop:
-; CHECK: phi i32
; CHECK-NOT: phi
; CHECK: exit:
loop:
; CHECK-NOT: phi
; CHECK: add i32
; CHECK: add i32
+; CHECK: add i32
; CHECK-NOT: add
; CHECK: return:
;
; CHECK: loop:
; CHECK: phi %structIF*
-; CHECK: phi i32*
-; CHECK: getelementptr inbounds
+; CHECK-NOT: phi
; CHECK: getelementptr inbounds
+; CHECK-NOT: getelementptr
; CHECK: exit:
loop:
%ptr.iv = phi %structIF* [ %ptr.inc, %latch ], [ %base, %entry ]
exit:
ret void
}
+
+; Test a widened IV that is used by a phi on different paths within the loop.
+;
+; CHECK: for.body:
+; CHECK: phi i64
+; CHECK: trunc i64
+; CHECK: if.then:
+; CHECK: for.inc:
+; CHECK: phi i32
+; CHECK: for.end:
+define void @phiUsesTrunc() nounwind {
+entry:
+ br i1 undef, label %for.body, label %for.end
+
+for.body:
+ %iv = phi i32 [ %inc, %for.inc ], [ 1, %entry ]
+ br i1 undef, label %if.then, label %if.else
+
+if.then:
+ br i1 undef, label %if.then33, label %for.inc
+
+if.then33:
+ br label %for.inc
+
+if.else:
+ br i1 undef, label %if.then97, label %for.inc
+
+if.then97:
+ %idxprom100 = sext i32 %iv to i64
+ br label %for.inc
+
+for.inc:
+ %kmin.1 = phi i32 [ %iv, %if.then33 ], [ 0, %if.then ], [ %iv, %if.then97 ], [ 0, %if.else ]
+ %inc = add nsw i32 %iv, 1
+ br i1 undef, label %for.body, label %for.end
+
+for.end:
+ ret void
+}