1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -loop-reduce -S | FileCheck %s
3target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
4target triple = "x86_64-pc-windows-msvc18.0.0"
5
6%struct.L = type { i8, i8* }
7
8declare i32 @__CxxFrameHandler3(...)
9
10@GV1 = external global %struct.L*
11@GV2 = external global %struct.L
12
13define void @b_copy_ctor() personality i32 (...)* @__CxxFrameHandler3 {
14; CHECK-LABEL: @b_copy_ctor(
15; CHECK-NEXT:  entry:
16; CHECK-NEXT:    [[TMP0:%.*]] = load %struct.L*, %struct.L** @GV1, align 8
17; CHECK-NEXT:    [[TMP1:%.*]] = bitcast %struct.L* [[TMP0]] to i8*
18; CHECK-NEXT:    br label [[FOR_COND:%.*]]
19; CHECK:       for.cond:
20; CHECK-NEXT:    [[LSR_IV:%.*]] = phi i64 [ [[LSR_IV_NEXT:%.*]], [[CALL_I_NOEXC:%.*]] ], [ 0, [[ENTRY:%.*]] ]
21; CHECK-NEXT:    [[LSR_IV2:%.*]] = inttoptr i64 [[LSR_IV]] to %struct.L*
22; CHECK-NEXT:    invoke void @a_copy_ctor()
23; CHECK-NEXT:    to label [[CALL_I_NOEXC]] unwind label [[CATCH_DISPATCH:%.*]]
24; CHECK:       call.i.noexc:
25; CHECK-NEXT:    [[LSR_IV_NEXT]] = add i64 [[LSR_IV]], -16
26; CHECK-NEXT:    br label [[FOR_COND]]
27; CHECK:       catch.dispatch:
28; CHECK-NEXT:    [[TMP2:%.*]] = catchswitch within none [label %catch] unwind to caller
29; CHECK:       catch:
30; CHECK-NEXT:    [[TMP3:%.*]] = catchpad within [[TMP2]] [i8* null, i32 64, i8* null]
31; CHECK-NEXT:    [[CMP16:%.*]] = icmp eq %struct.L* [[LSR_IV2]], null
32; CHECK-NEXT:    [[TMP4:%.*]] = mul i64 [[LSR_IV]], -1
33; CHECK-NEXT:    [[UGLYGEP:%.*]] = getelementptr i8, i8* [[TMP1]], i64 [[TMP4]]
34; CHECK-NEXT:    [[UGLYGEP1:%.*]] = bitcast i8* [[UGLYGEP]] to %struct.L*
35; CHECK-NEXT:    br i1 [[CMP16]], label [[FOR_END:%.*]], label [[FOR_BODY_PREHEADER:%.*]]
36; CHECK:       for.body.preheader:
37; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
38; CHECK:       for.body:
39; CHECK-NEXT:    [[CMP:%.*]] = icmp eq %struct.L* [[UGLYGEP1]], @GV2
40; CHECK-NEXT:    br i1 [[CMP]], label [[FOR_END_LOOPEXIT:%.*]], label [[FOR_BODY]]
41; CHECK:       for.end.loopexit:
42; CHECK-NEXT:    br label [[FOR_END]]
43; CHECK:       for.end:
44; CHECK-NEXT:    catchret from [[TMP3]] to label [[TRY_CONT:%.*]]
45; CHECK:       try.cont:
46; CHECK-NEXT:    ret void
47;
48entry:
49  %0 = load %struct.L*, %struct.L** @GV1, align 8
50  br label %for.cond
51
52for.cond:                                         ; preds = %call.i.noexc, %entry
53  %d.0 = phi %struct.L* [ %0, %entry ], [ %incdec.ptr, %call.i.noexc ]
54  invoke void @a_copy_ctor()
55  to label %call.i.noexc unwind label %catch.dispatch
56
57call.i.noexc:                                     ; preds = %for.cond
58  %incdec.ptr = getelementptr inbounds %struct.L, %struct.L* %d.0, i64 1
59  br label %for.cond
60
61catch.dispatch:                                   ; preds = %for.cond
62  %1 = catchswitch within none [label %catch] unwind to caller
63
64catch:                                            ; preds = %catch.dispatch
65  %2 = catchpad within %1 [i8* null, i32 64, i8* null]
66  %cmp16 = icmp eq %struct.L* %0, %d.0
67  br i1 %cmp16, label %for.end, label %for.body
68
69for.body:                                         ; preds = %for.body, %catch
70  %cmp = icmp eq %struct.L* @GV2, %d.0
71  br i1 %cmp, label %for.end, label %for.body
72
73for.end:                                          ; preds = %for.body, %catch
74  catchret from %2 to label %try.cont
75
76try.cont:                                         ; preds = %for.end
77  ret void
78}
79
80declare void @a_copy_ctor()
81