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
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.
7 @a = common local_unnamed_addr global i32 0, align 4
8 @arr = common local_unnamed_addr global [5 x i32] zeroinitializer, align 4
10 ; Function Attrs: norecurse nounwind readonly
11 define signext i32 @testTripCount2(i32 signext %a) {
13 ; CHECK-LABEL: testTripCount2:
20 for.cond.cleanup: ; preds = %for.body
23 for.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
34 ; Function Attrs: norecurse nounwind readonly
35 define signext i32 @testTripCount3(i32 signext %a) {
37 ; CHECK-LABEL: testTripCount3:
44 for.cond.cleanup: ; preds = %for.body
47 for.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
58 ; Function Attrs: norecurse nounwind readonly
60 define signext i32 @testTripCount4(i32 signext %a) {
62 ; CHECK-LABEL: testTripCount4:
69 for.cond.cleanup: ; preds = %for.body
72 for.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
83 ; Function Attrs: norecurse nounwind
84 define signext i32 @testTripCount2NonSmallLoop() {
85 ; CHECK-LABEL: testTripCount2NonSmallLoop:
90 %.pre = load i32, i32* @a, align 4
93 for.body: ; preds = %entry, %if.end
94 %0 = phi i32 [ %.pre, %entry ], [ %1, %if.end ]
95 %dec4 = phi i32 [ 1, %entry ], [ %dec, %if.end ]
96 %b.03 = phi i8 [ 0, %entry ], [ %b.1, %if.end ]
97 %tobool1 = icmp eq i32 %0, 0
98 br i1 %tobool1, label %if.end, label %if.then
100 if.then: ; preds = %for.body
101 store i32 2, i32* @a, align 4
104 if.end: ; preds = %for.body, %if.then
105 %1 = phi i32 [ 2, %if.then ], [ 0, %for.body ]
106 %b.1 = phi i8 [ 2, %if.then ], [ %b.03, %for.body ]
107 %dec = add nsw i32 %dec4, -1
108 %tobool = icmp eq i32 %dec4, 0
109 br i1 %tobool, label %for.end, label %for.body
111 for.end: ; preds = %if.end
112 %conv = zext i8 %b.1 to i32