1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=indvars < %s | FileCheck %s
4 ; This tests the case where a terminator can be modeled by SCEV,
5 ; because it has a returned attribute.
7 target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
11 define void @test(ptr %p) personality ptr undef {
14 ; CHECK-NEXT: br label [[LOOP:%.*]]
16 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ], [ 0, [[ENTRY:%.*]] ]
17 ; CHECK-NEXT: [[TMP0:%.*]] = trunc i64 [[INDVARS_IV]] to i32
18 ; CHECK-NEXT: [[RES:%.*]] = invoke i32 @foo(i32 returned [[TMP0]])
19 ; CHECK-NEXT: to label [[LOOP_LATCH]] unwind label [[EXIT:%.*]]
21 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add i64 [[INDVARS_IV]], 1
22 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[INDVARS_IV]] to i32
23 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @foo(i32 [[TMP1]])
24 ; CHECK-NEXT: br label [[LOOP]]
26 ; CHECK-NEXT: [[LP:%.*]] = landingpad { ptr, i32 }
28 ; CHECK-NEXT: ret void
34 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]
35 %res = invoke i32 @foo(i32 returned %iv)
36 to label %loop.latch unwind label %exit
39 %ext = zext i32 %iv to i64
40 %tmp5 = getelementptr inbounds i8, ptr %p, i64 %ext
41 %iv.next = add nuw i32 %iv, 1
42 call i32 @foo(i32 %res)
46 %lp = landingpad { ptr, i32 }
51 define void @test_critedge(i1 %c, ptr %p) personality ptr undef {
52 ; CHECK-LABEL: @test_critedge(
54 ; CHECK-NEXT: br label [[LOOP:%.*]]
56 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ], [ 0, [[ENTRY:%.*]] ]
57 ; CHECK-NEXT: br i1 [[C:%.*]], label [[LOOP_INVOKE:%.*]], label [[LOOP_OTHER:%.*]]
59 ; CHECK-NEXT: [[TMP0:%.*]] = trunc i64 [[INDVARS_IV]] to i32
60 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[INDVARS_IV]] to i32
61 ; CHECK-NEXT: [[RES:%.*]] = invoke i32 @foo(i32 returned [[TMP0]])
62 ; CHECK-NEXT: to label [[LOOP_LATCH]] unwind label [[EXIT:%.*]]
64 ; CHECK-NEXT: br label [[LOOP_LATCH]]
66 ; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ [[TMP1]], [[LOOP_INVOKE]] ], [ 0, [[LOOP_OTHER]] ]
67 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add i64 [[INDVARS_IV]], 1
68 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @foo(i32 [[PHI]])
69 ; CHECK-NEXT: br label [[LOOP]]
71 ; CHECK-NEXT: [[LP:%.*]] = landingpad { ptr, i32 }
73 ; CHECK-NEXT: ret void
79 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]
80 br i1 %c, label %loop.invoke, label %loop.other
83 %res = invoke i32 @foo(i32 returned %iv)
84 to label %loop.latch unwind label %exit
90 %phi = phi i32 [ %res, %loop.invoke ], [ 0, %loop.other ]
91 %ext = zext i32 %iv to i64
92 %tmp5 = getelementptr inbounds i8, ptr %p, i64 %ext
93 %iv.next = add nuw i32 %iv, 1
94 call i32 @foo(i32 %phi)
98 %lp = landingpad { ptr, i32 }