1 ; RUN: opt < %s -S -mtriple=amdgcn-- -passes=loop-unroll | FileCheck %s
3 ; Check the handling of amdgpu.loop.unroll.threshold metadata which can be used to
4 ; set the default threshold for a loop. This metadata overrides both the AMDGPU
5 ; default, and any value specified by the amdgpu-unroll-threshold function attribute
6 ; (which sets a threshold for all loops in the function).
8 ; Check that the loop in unroll_default is not fully unrolled using the default
10 ; CHECK-LABEL: @unroll_default
15 @in = internal unnamed_addr global ptr null, align 8
16 @out = internal unnamed_addr global ptr null, align 8
18 define void @unroll_default() {
22 do.body: ; preds = %entry
23 %i.0 = phi i32 [ 0, %entry ], [ %inc, %do.body ]
24 %v1 = load i64, ptr @in, align 8
25 store i64 %v1, ptr @out, align 8
26 %inc = add nsw i32 %i.0, 1
27 %cmp = icmp slt i32 %inc, 100
28 br i1 %cmp, label %do.body, label %do.end
30 do.end: ; preds = %do.body
34 ; Check that the same loop in unroll_full is fully unrolled when the default
35 ; unroll threshold is increased by use of the amdgpu.loop.unroll.threshold metadata
36 ; CHECK-LABEL: @unroll_full
38 ; CHECK-NOT: br i1 %cmp
41 define void @unroll_full() {
45 do.body: ; preds = %entry
46 %i.0 = phi i32 [ 0, %entry ], [ %inc, %do.body ]
47 %v1 = load i64, ptr @in, align 8
48 store i64 %v1, ptr @out, align 8
49 %inc = add nsw i32 %i.0, 1
50 %cmp = icmp slt i32 %inc, 100
51 br i1 %cmp, label %do.body, label %do.end, !llvm.loop !1
53 do.end: ; preds = %do.body
57 ; Check that the same loop in override_no_unroll is not unrolled when a high default
58 ; unroll threshold specified using the amdgpu-unroll-threshold function attribute
59 ; is overridden by a low threshold using the amdgpu.loop.unroll.threshold metadata
61 ; CHECK-LABEL: @override_no_unroll
66 define void @override_no_unroll() #0 {
70 do.body: ; preds = %entry
71 %i.0 = phi i32 [ 0, %entry ], [ %inc, %do.body ]
72 %v1 = load i64, ptr @in, align 8
73 store i64 %v1, ptr @out, align 8
74 %inc = add nsw i32 %i.0, 1
75 %cmp = icmp slt i32 %inc, 100
76 br i1 %cmp, label %do.body, label %do.end, !llvm.loop !3
78 do.end: ; preds = %do.body
82 ; Check that the same loop in override_unroll is fully unrolled when a low default
83 ; unroll threshold specified using the amdgpu-unroll-threshold function attribute
84 ; is overridden by a high threshold using the amdgpu.loop.unroll.threshold metadata
86 ; CHECK-LABEL: @override_unroll
88 ; CHECK-NOT: br i1 %cmp
91 define void @override_unroll() #1 {
95 do.body: ; preds = %entry
96 %i.0 = phi i32 [ 0, %entry ], [ %inc, %do.body ]
97 %v1 = load i64, ptr @in, align 8
98 store i64 %v1, ptr @out, align 8
99 %inc = add nsw i32 %i.0, 1
100 %cmp = icmp slt i32 %inc, 100
101 br i1 %cmp, label %do.body, label %do.end, !llvm.loop !1
103 do.end: ; preds = %do.body
107 attributes #0 = { "amdgpu-unroll-threshold"="1000" }
108 attributes #1 = { "amdgpu-unroll-threshold"="100" }
111 !2 = !{!"amdgpu.loop.unroll.threshold", i32 1000}
113 !4 = !{!"amdgpu.loop.unroll.threshold", i32 100}