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 declare void @use(double) readnone
9 ; Make sure re-used instructions do not impact the insertion points for SCEV
11 define void @test(ptr %ioptr, i32 %X, ptr %start, ptr %end) {
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:%.*]]
19 ; CHECK-NEXT: br label [[FOR_BODY37:%.*]]
21 ; CHECK-NEXT: [[P0R_0335:%.*]] = phi ptr [ [[ADD_PTR94:%.*]], [[FOR_BODY37]] ], [ [[START:%.*]], [[FOR_BODY15]] ]
22 ; CHECK-NEXT: [[ADD_PTR94]] = getelementptr inbounds double, ptr [[P0R_0335]], i64 1
23 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, ptr [[P0R_0335]], i64 [[TMP1]]
24 ; CHECK-NEXT: [[F1I_0:%.*]] = load double, ptr [[SCEVGEP]], align 8
25 ; CHECK-NEXT: call void @use(double [[F1I_0]])
26 ; CHECK-NEXT: [[EC0:%.*]] = icmp eq ptr [[ADD_PTR94]], [[END:%.*]]
27 ; CHECK-NEXT: br i1 [[EC0]], label [[FOR_BODY37]], label [[FOR_END_LOOPEXIT:%.*]]
28 ; CHECK: for.end.loopexit:
29 ; CHECK-NEXT: [[ADD_PTR94_LCSSA:%.*]] = phi ptr [ [[ADD_PTR94]], [[FOR_BODY37]] ]
30 ; CHECK-NEXT: br label [[FOR_END:%.*]]
32 ; CHECK-NEXT: [[P0R_0_LCSSA:%.*]] = phi ptr [ [[ADD_PTR94_LCSSA]], [[FOR_END_LOOPEXIT]] ]
33 ; CHECK-NEXT: [[EC1:%.*]] = icmp eq ptr [[P0R_0_LCSSA]], [[END]]
34 ; CHECK-NEXT: br i1 [[EC1]], label [[FOR_BODY15]], label [[FOR_INC133:%.*]]
36 ; CHECK-NEXT: ret void
39 %idx.ext32 = sext i32 %X to i64
42 for.body15: ; preds = %for.end, %for.body15.lr.ph
45 for.body37: ; preds = %for.body37, %for.body37.preheader
46 %p0r.0335 = phi ptr [ %add.ptr94, %for.body37 ], [ %start, %for.body15 ]
47 %add.ptr94 = getelementptr inbounds double, ptr %p0r.0335, i64 1
48 %f1i.0.in = getelementptr inbounds double, ptr %add.ptr94, i64 %idx.ext32
49 %f1i.0 = load double, ptr %f1i.0.in, align 8
50 call void @use(double %f1i.0)
51 %ec0 = icmp eq ptr %add.ptr94, %end
52 br i1 %ec0, label %for.body37, label %for.end.loopexit
54 for.end.loopexit: ; preds = %for.body37
57 for.end: ; preds = %for.end.loopexit, %for.body15
58 %p0r.0.lcssa = phi ptr [ %add.ptr94, %for.end.loopexit ]
59 %ec1 = icmp eq ptr %p0r.0.lcssa, %end
60 br i1 %ec1, label %for.body15, label %for.inc133
62 for.inc133: ; preds = %for.end