1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -loop-reduce %s -S | FileCheck %s
4 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
5 target triple = "x86_64-apple-macosx10.15.0"
7 ; Tests for crashes during SCEV expansion.
9 %struct.hoge = type { i32, i32, i32, i32 }
11 define i64 @blam(%struct.hoge* %start, %struct.hoge* %end, %struct.hoge* %ptr.2) {
14 ; CHECK-NEXT: [[START1:%.*]] = ptrtoint %struct.hoge* [[START:%.*]] to i64
15 ; CHECK-NEXT: br label [[LOOP_1_HEADER:%.*]]
16 ; CHECK: loop.1.header:
17 ; CHECK-NEXT: [[LSR_IV5:%.*]] = phi i64 [ [[LSR_IV_NEXT6:%.*]], [[LOOP_1_HEADER]] ], [ [[START1]], [[ENTRY:%.*]] ]
18 ; CHECK-NEXT: [[IV:%.*]] = phi %struct.hoge* [ [[IV_NEXT:%.*]], [[LOOP_1_HEADER]] ], [ [[START]], [[ENTRY]] ]
19 ; CHECK-NEXT: [[IV_NEXT]] = getelementptr inbounds [[STRUCT_HOGE:%.*]], %struct.hoge* [[IV]], i64 1
20 ; CHECK-NEXT: [[LSR_IV_NEXT6]] = add nuw i64 [[LSR_IV5]], 16
21 ; CHECK-NEXT: [[EC:%.*]] = icmp eq %struct.hoge* [[IV_NEXT]], [[END:%.*]]
22 ; CHECK-NEXT: br i1 [[EC]], label [[LOOP_2_PH:%.*]], label [[LOOP_1_HEADER]]
24 ; CHECK-NEXT: br label [[LOOP_2_HEADER:%.*]]
25 ; CHECK: loop.2.header:
26 ; CHECK-NEXT: [[LSR_IV2:%.*]] = phi i64 [ [[LSR_IV_NEXT3:%.*]], [[LOOP_2_LATCH:%.*]] ], [ [[LSR_IV_NEXT6]], [[LOOP_2_PH]] ]
27 ; CHECK-NEXT: [[IV2:%.*]] = phi %struct.hoge* [ [[IV2_NEXT:%.*]], [[LOOP_2_LATCH]] ], [ [[IV_NEXT]], [[LOOP_2_PH]] ]
28 ; CHECK-NEXT: [[IV24:%.*]] = bitcast %struct.hoge* [[IV2]] to i32*
29 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[LSR_IV2]], 12
30 ; CHECK-NEXT: call void @use.i64(i64 [[TMP0]])
31 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i32, i32* [[IV24]], i64 2
32 ; CHECK-NEXT: store i32 10, i32* [[SCEVGEP]], align 8
33 ; CHECK-NEXT: [[EC_2:%.*]] = icmp ugt %struct.hoge* [[IV2]], [[PTR_2:%.*]]
34 ; CHECK-NEXT: br i1 [[EC_2]], label [[LOOP_2_EXIT:%.*]], label [[LOOP_2_LATCH]]
35 ; CHECK: loop.2.latch:
36 ; CHECK-NEXT: [[IV2_NEXT]] = getelementptr inbounds [[STRUCT_HOGE]], %struct.hoge* [[IV2]], i64 1
37 ; CHECK-NEXT: [[LSR_IV_NEXT3]] = add i64 [[LSR_IV2]], 16
38 ; CHECK-NEXT: br label [[LOOP_2_HEADER]]
40 ; CHECK-NEXT: ret i64 [[LSR_IV2]]
43 br label %loop.1.header
46 %iv = phi %struct.hoge* [ %iv.next, %loop.1.header ], [ %start, %entry ]
47 %iv.next = getelementptr inbounds %struct.hoge, %struct.hoge* %iv, i64 1
48 %ec = icmp eq %struct.hoge* %iv.next, %end
49 br i1 %ec, label %loop.2.ph, label %loop.1.header
52 br label %loop.2.header
55 %iv2 = phi %struct.hoge* [ %iv2.next, %loop.2.latch ], [ %iv.next, %loop.2.ph ]
56 %tmp7 = getelementptr inbounds %struct.hoge, %struct.hoge* %iv2, i64 0, i32 3
57 %tmp8 = ptrtoint i32* %tmp7 to i64
58 call void @use.i64(i64 %tmp8)
59 %tmp9 = getelementptr inbounds %struct.hoge, %struct.hoge* %iv2, i64 0, i32 2
60 store i32 10, i32* %tmp9, align 8
61 %ec.2 = icmp ugt %struct.hoge* %iv2, %ptr.2
62 br i1 %ec.2, label %loop.2.exit, label %loop.2.latch
65 %iv2.next = getelementptr inbounds %struct.hoge, %struct.hoge* %iv2, i64 1
66 br label %loop.2.header
68 loop.2.exit: ; preds = %bb6
69 %iv2.cast = ptrtoint %struct.hoge* %iv2 to i64
74 declare void @use.i64(i64)