• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: llc < %s -mtriple=powerpc64le-unknown-linux-gnu -verify-machineinstrs -mcpu=pwr8 | FileCheck %s
2; RUN: llc < %s -mtriple=powerpc64le-unknown-linux-gnu -verify-machineinstrs -mcpu=a2q | FileCheck %s
3
4; Verify that we do NOT generate the mtctr instruction for loop trip counts < 4
5; The latency of the mtctr is only justified if there are more than 4 comparisons that are removed as a result.
6
7@a = common local_unnamed_addr global i32 0, align 4
8@arr = common local_unnamed_addr global [5 x i32] zeroinitializer, align 4
9
10; Function Attrs: norecurse nounwind readonly
11define signext i32 @testTripCount2(i32 signext %a) {
12
13; CHECK-LABEL: testTripCount2:
14; CHECK-NOT: mtctr
15; CHECK: blr
16
17entry:
18  br label %for.body
19
20for.cond.cleanup:                                 ; preds = %for.body
21  ret i32 %add
22
23for.body:                                         ; preds = %entry, %for.body
24  %indvars.iv = phi i64 [ 1, %entry ], [ %indvars.iv.next, %for.body ]
25  %Sum.05 = phi i32 [ 0, %entry ], [ %add, %for.body ]
26  %arrayidx = getelementptr inbounds [5 x i32], [5 x i32]* @arr, i64 0, i64 %indvars.iv
27  %0 = load i32, i32* %arrayidx, align 4
28  %add = add nsw i32 %0, %Sum.05
29  %indvars.iv.next = add nsw i64 %indvars.iv, -1
30  %tobool = icmp eq i64 %indvars.iv, 0
31  br i1 %tobool, label %for.cond.cleanup, label %for.body
32}
33
34; Function Attrs: norecurse nounwind readonly
35define signext i32 @testTripCount3(i32 signext %a) {
36
37; CHECK-LABEL: testTripCount3:
38; CHECK-NOT: mtctr
39; CHECK: blr
40
41entry:
42  br label %for.body
43
44for.cond.cleanup:                                 ; preds = %for.body
45  ret i32 %add
46
47for.body:                                         ; preds = %entry, %for.body
48  %indvars.iv = phi i64 [ 2, %entry ], [ %indvars.iv.next, %for.body ]
49  %Sum.05 = phi i32 [ 0, %entry ], [ %add, %for.body ]
50  %arrayidx = getelementptr inbounds [5 x i32], [5 x i32]* @arr, i64 0, i64 %indvars.iv
51  %0 = load i32, i32* %arrayidx, align 4
52  %add = add nsw i32 %0, %Sum.05
53  %indvars.iv.next = add nsw i64 %indvars.iv, -1
54  %tobool = icmp eq i64 %indvars.iv, 0
55  br i1 %tobool, label %for.cond.cleanup, label %for.body
56}
57
58; Function Attrs: norecurse nounwind readonly
59
60define signext i32 @testTripCount4(i32 signext %a) {
61
62; CHECK-LABEL: testTripCount4:
63; CHECK: mtctr
64; CHECK: bdnz
65
66entry:
67  br label %for.body
68
69for.cond.cleanup:                                 ; preds = %for.body
70  ret i32 %add
71
72for.body:                                         ; preds = %entry, %for.body
73  %indvars.iv = phi i64 [ 3, %entry ], [ %indvars.iv.next, %for.body ]
74  %Sum.05 = phi i32 [ 0, %entry ], [ %add, %for.body ]
75  %arrayidx = getelementptr inbounds [5 x i32], [5 x i32]* @arr, i64 0, i64 %indvars.iv
76  %0 = load i32, i32* %arrayidx, align 4
77  %add = add nsw i32 %0, %Sum.05
78  %indvars.iv.next = add nsw i64 %indvars.iv, -1
79  %tobool = icmp eq i64 %indvars.iv, 0
80  br i1 %tobool, label %for.cond.cleanup, label %for.body
81}
82
83; Function Attrs: norecurse nounwind
84define signext i32 @testTripCount2NonSmallLoop() {
85
86; CHECK-LABEL: testTripCount2NonSmallLoop:
87; CHECK: mtctr
88; CHECK: blr
89
90entry:
91  %.pre = load i32, i32* @a, align 4
92  br label %for.body
93
94for.body:                                         ; preds = %entry, %if.end
95  %0 = phi i32 [ %.pre, %entry ], [ %1, %if.end ]
96  %dec4 = phi i32 [ 1, %entry ], [ %dec, %if.end ]
97  %b.03 = phi i8 [ 0, %entry ], [ %b.1, %if.end ]
98  %tobool1 = icmp eq i32 %0, 0
99  br i1 %tobool1, label %if.end, label %if.then
100
101if.then:                                          ; preds = %for.body
102  store i32 2, i32* @a, align 4
103  br label %if.end
104
105if.end:                                           ; preds = %for.body, %if.then
106  %1 = phi i32 [ 2, %if.then ], [ 0, %for.body ]
107  %b.1 = phi i8 [ 2, %if.then ], [ %b.03, %for.body ]
108  %dec = add nsw i32 %dec4, -1
109  %tobool = icmp eq i32 %dec4, 0
110  br i1 %tobool, label %for.end, label %for.body
111
112for.end:                                          ; preds = %if.end
113  %conv = zext i8 %b.1 to i32
114  ret i32 %conv
115}
116
117