xref: /llvm-project/llvm/test/Transforms/LoopUnroll/full-unroll-avoid-partial.ll (revision aea2a147363197f3cef140ebcd27b534fd41877b)
1*aea2a147SYashwant Singh; RUN: opt -S -passes=loop-unroll --debug-only=loop-unroll < %s 2>&1 | FileCheck %s -check-prefix=LOOP-UNROLL
2*aea2a147SYashwant Singh; RUN: opt -S -passes='require<opt-remark-emit>,loop(loop-unroll-full)' --debug-only=loop-unroll < %s 2>&1 | FileCheck %s -check-prefix=LOOP-UNROLL-FULL
3*aea2a147SYashwant Singh
4*aea2a147SYashwant Singh; REQUIRES: asserts
5*aea2a147SYashwant Singh
6*aea2a147SYashwant Singh%struct.HIP_vector_type = type {  %union.anon }
7*aea2a147SYashwant Singh%union.anon = type { <2 x float> }
8*aea2a147SYashwant Singh
9*aea2a147SYashwant Singh
10*aea2a147SYashwant Singh; LOOP-UNROLL-LABEL: Loop Unroll: F[pragma_unroll] Loop %for.body
11*aea2a147SYashwant Singh; LOOP-UNROLL-NEXT: Loop Size = 9
12*aea2a147SYashwant Singh; LOOP-UNROLL-NEXT: runtime unrolling with count: 8
13*aea2a147SYashwant Singh; LOOP-UNROLL-NEXT: Exiting block %for.body: TripCount=0, TripMultiple=1, BreakoutTrip=1
14*aea2a147SYashwant Singh; LOOP-UNROLL-NEXT: Trying runtime unrolling on Loop:
15*aea2a147SYashwant Singh; LOOP-UNROLL-NEXT: Loop at depth 1 containing: %for.body<header><latch><exiting>
16*aea2a147SYashwant Singh; LOOP-UNROLL-NEXT: Using epilog remainder.
17*aea2a147SYashwant Singh; LOOP-UNROLL-NEXT: UNROLLING loop %for.body by 8 with run-time trip count!
18*aea2a147SYashwant Singh
19*aea2a147SYashwant Singh; LOOP-UNROLL-FULL-LABEL: Loop Unroll: F[pragma_unroll] Loop %for.body
20*aea2a147SYashwant Singh; LOOP-UNROLL-FULL-NEXT: Loop Size = 9
21*aea2a147SYashwant Singh; LOOP-UNROLL-FULL-NEXT:  runtime unrolling with count: 8
22*aea2a147SYashwant Singh; LOOP-UNROLL-FULL-NEXT: Not attempting partial/runtime unroll in FullLoopUnroll
23*aea2a147SYashwant Singhdefine void @pragma_unroll(ptr %queue, i32 %num_elements) {
24*aea2a147SYashwant Singhentry:
25*aea2a147SYashwant Singh  %cmp5 = icmp sgt i32 %num_elements, 0
26*aea2a147SYashwant Singh  br i1 %cmp5, label %for.body.preheader, label %for.cond.cleanup
27*aea2a147SYashwant Singh
28*aea2a147SYashwant Singhfor.body.preheader:                               ; preds = %entry
29*aea2a147SYashwant Singh  br label %for.body
30*aea2a147SYashwant Singh
31*aea2a147SYashwant Singhfor.cond.cleanup.loopexit:                        ; preds = %for.body
32*aea2a147SYashwant Singh  br label %for.cond.cleanup
33*aea2a147SYashwant Singh
34*aea2a147SYashwant Singhfor.cond.cleanup:                                 ; preds = %for.cond.cleanup.loopexit, %entry
35*aea2a147SYashwant Singh  ret void
36*aea2a147SYashwant Singh
37*aea2a147SYashwant Singhfor.body:                                         ; preds = %for.body.preheader, %for.body
38*aea2a147SYashwant Singh  %i.06 = phi i32 [ %add, %for.body ], [ 0, %for.body.preheader ]
39*aea2a147SYashwant Singh  %add = add nuw nsw i32 %i.06, 1
40*aea2a147SYashwant Singh  %idxprom = zext i32 %add to i64
41*aea2a147SYashwant Singh  %arrayidx = getelementptr inbounds %struct.HIP_vector_type, ptr %queue, i64 %idxprom
42*aea2a147SYashwant Singh  %idxprom1 = zext i32 %i.06 to i64
43*aea2a147SYashwant Singh  %arrayidx2 = getelementptr inbounds %struct.HIP_vector_type, ptr %queue, i64 %idxprom1
44*aea2a147SYashwant Singh  %0 = load i64, ptr %arrayidx, align 8
45*aea2a147SYashwant Singh  store i64 %0, ptr %arrayidx2, align 8
46*aea2a147SYashwant Singh  %exitcond = icmp ne i32 %add, %num_elements
47*aea2a147SYashwant Singh  br i1 %exitcond, label %for.body, label %for.cond.cleanup.loopexit, !llvm.loop !1
48*aea2a147SYashwant Singh}
49*aea2a147SYashwant Singh
50*aea2a147SYashwant Singh; LOOP-UNROLL-LABEL: Loop Unroll: F[pragma_unroll_count1] Loop %for.body
51*aea2a147SYashwant Singh; LOOP-UNROLL-NEXT: Loop Size = 9
52*aea2a147SYashwant Singh; LOOP-UNROLL-NEXT: Exiting block %for.body: TripCount=0, TripMultiple=1, BreakoutTrip=1
53*aea2a147SYashwant Singh; LOOP-UNROLL-NEXT: Trying runtime unrolling on Loop:
54*aea2a147SYashwant Singh; LOOP-UNROLL-NEXT: Loop at depth 1 containing: %for.body<header><latch><exiting>
55*aea2a147SYashwant Singh; LOOP-UNROLL-NEXT: Using epilog remainder.
56*aea2a147SYashwant Singh; LOOP-UNROLL-NEXT: UNROLLING loop %for.body by 5 with run-time trip count!
57*aea2a147SYashwant Singh
58*aea2a147SYashwant Singh; LOOP-UNROLL-FULL-LABEL: Loop Unroll: F[pragma_unroll_count1] Loop %for.body
59*aea2a147SYashwant Singh; LOOP-UNROLL-FULL-NEXT: Loop Size = 9
60*aea2a147SYashwant Singh; LOOP-UNROLL-FULL-NEXT: Not attempting partial/runtime unroll in FullLoopUnroll
61*aea2a147SYashwant Singhdefine void @pragma_unroll_count1(ptr %queue, i32 %num_elements) {
62*aea2a147SYashwant Singhentry:
63*aea2a147SYashwant Singh  %cmp5 = icmp sgt i32 %num_elements, 0
64*aea2a147SYashwant Singh  br i1 %cmp5, label %for.body.preheader, label %for.cond.cleanup
65*aea2a147SYashwant Singh
66*aea2a147SYashwant Singhfor.body.preheader:                               ; preds = %entry
67*aea2a147SYashwant Singh  br label %for.body
68*aea2a147SYashwant Singh
69*aea2a147SYashwant Singhfor.cond.cleanup.loopexit:                        ; preds = %for.body
70*aea2a147SYashwant Singh  br label %for.cond.cleanup
71*aea2a147SYashwant Singh
72*aea2a147SYashwant Singhfor.cond.cleanup:                                 ; preds = %for.cond.cleanup.loopexit, %entry
73*aea2a147SYashwant Singh  ret void
74*aea2a147SYashwant Singh
75*aea2a147SYashwant Singhfor.body:                                         ; preds = %for.body.preheader, %for.body
76*aea2a147SYashwant Singh  %i.06 = phi i32 [ %add, %for.body ], [ 0, %for.body.preheader ]
77*aea2a147SYashwant Singh  %add = add nuw nsw i32 %i.06, 1
78*aea2a147SYashwant Singh  %idxprom = zext i32 %add to i64
79*aea2a147SYashwant Singh  %arrayidx = getelementptr inbounds %struct.HIP_vector_type, ptr %queue, i64 %idxprom
80*aea2a147SYashwant Singh  %idxprom1 = zext i32 %i.06 to i64
81*aea2a147SYashwant Singh  %arrayidx2 = getelementptr inbounds %struct.HIP_vector_type, ptr %queue, i64 %idxprom1
82*aea2a147SYashwant Singh  %0 = load i64, ptr %arrayidx, align 8
83*aea2a147SYashwant Singh  store i64 %0, ptr %arrayidx2, align 8
84*aea2a147SYashwant Singh  %exitcond = icmp ne i32 %add, %num_elements
85*aea2a147SYashwant Singh  br i1 %exitcond, label %for.body, label %for.cond.cleanup.loopexit, !llvm.loop !3
86*aea2a147SYashwant Singh}
87*aea2a147SYashwant Singh
88*aea2a147SYashwant Singh; LOOP-UNROLL: llvm.loop.unroll.disable
89*aea2a147SYashwant Singh; LOOP-UNROLL-FULL: llvm.loop.unroll.enable
90*aea2a147SYashwant Singh!0 = !{!"llvm.loop.unroll.enable"}
91*aea2a147SYashwant Singh!1 = distinct !{!1, !0}
92*aea2a147SYashwant Singh
93*aea2a147SYashwant Singh!2 = !{!"llvm.loop.unroll.count", i32 5}
94*aea2a147SYashwant Singh!3 = distinct !{!3, !2}
95