1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -loop-reduce -S %s | FileCheck %s
3
4target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
5target triple = "x86_64-apple-macosx10.15.0"
6
7declare void @use(double) readnone
8
9; Make sure re-used instructions do not impact the insertion points for SCEV
10; expansion.
11define void @test(double* %ioptr, i32 %X, double* %start, double* %end) {
12; CHECK-LABEL: @test(
13; CHECK-NEXT:  entry:
14; CHECK-NEXT:    [[IDX_EXT32:%.*]] = sext i32 [[X:%.*]] to i64
15; CHECK-NEXT:    [[TMP0:%.*]] = shl nsw i64 [[IDX_EXT32]], 3
16; CHECK-NEXT:    [[TMP1:%.*]] = add nsw i64 [[TMP0]], 8
17; CHECK-NEXT:    br label [[FOR_BODY15:%.*]]
18; CHECK:       for.body15:
19; CHECK-NEXT:    br label [[FOR_BODY37:%.*]]
20; CHECK:       for.body37:
21; CHECK-NEXT:    [[P0R_0335:%.*]] = phi double* [ [[ADD_PTR94:%.*]], [[FOR_BODY37]] ], [ [[START:%.*]], [[FOR_BODY15]] ]
22; CHECK-NEXT:    [[ADD_PTR94]] = getelementptr inbounds double, double* [[P0R_0335]], i64 1
23; CHECK-NEXT:    [[P0R_03351:%.*]] = bitcast double* [[P0R_0335]] to i8*
24; CHECK-NEXT:    [[UGLYGEP:%.*]] = getelementptr i8, i8* [[P0R_03351]], i64 [[TMP1]]
25; CHECK-NEXT:    [[UGLYGEP2:%.*]] = bitcast i8* [[UGLYGEP]] to double*
26; CHECK-NEXT:    [[F1I_0:%.*]] = load double, double* [[UGLYGEP2]], align 8
27; CHECK-NEXT:    call void @use(double [[F1I_0]])
28; CHECK-NEXT:    [[EC0:%.*]] = icmp eq double* [[END:%.*]], [[ADD_PTR94]]
29; CHECK-NEXT:    br i1 [[EC0]], label [[FOR_BODY37]], label [[FOR_END_LOOPEXIT:%.*]]
30; CHECK:       for.end.loopexit:
31; CHECK-NEXT:    br label [[FOR_END:%.*]]
32; CHECK:       for.end:
33; CHECK-NEXT:    [[P0R_0_LCSSA:%.*]] = phi double* [ [[ADD_PTR94]], [[FOR_END_LOOPEXIT]] ]
34; CHECK-NEXT:    [[EC1:%.*]] = icmp eq double* [[P0R_0_LCSSA]], [[END]]
35; CHECK-NEXT:    br i1 [[EC1]], label [[FOR_BODY15]], label [[FOR_INC133:%.*]]
36; CHECK:       for.inc133:
37; CHECK-NEXT:    ret void
38;
39entry:
40  %idx.ext32 = sext i32 %X to i64
41  br label %for.body15
42
43for.body15:                                       ; preds = %for.end, %for.body15.lr.ph
44  br label %for.body37
45
46for.body37:                                       ; preds = %for.body37, %for.body37.preheader
47  %p0r.0335 = phi double* [ %add.ptr94, %for.body37 ], [ %start, %for.body15 ]
48  %add.ptr94 = getelementptr inbounds double, double* %p0r.0335, i64 1
49  %f1i.0.in = getelementptr inbounds double, double* %add.ptr94, i64 %idx.ext32
50  %f1i.0 = load double, double* %f1i.0.in, align 8
51  call void @use(double %f1i.0)
52  %ec0 = icmp eq double* %add.ptr94, %end
53  br i1 %ec0, label %for.body37, label %for.end.loopexit
54
55for.end.loopexit:                                 ; preds = %for.body37
56  br label %for.end
57
58for.end:                                          ; preds = %for.end.loopexit, %for.body15
59  %p0r.0.lcssa = phi double* [ %add.ptr94, %for.end.loopexit ]
60  %ec1 = icmp eq double* %p0r.0.lcssa, %end
61  br i1 %ec1, label %for.body15, label %for.inc133
62
63for.inc133:                                       ; preds = %for.end
64  ret void
65}
66