• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: llc -march=hexagon -mcpu=hexagonv4 -no-phi-elim-live-out-early-exit \
2; RUN:    < %s | FileCheck %s
3; Check that we remove the compare and induction variable instructions
4; after generating hardware loops.
5; Bug 6685.
6
7; CHECK: loop0
8; CHECK-NOT: r{{[0-9]+}}{{.}}={{.}}add(r{{[0-9]+}},{{.}}#-1)
9; CHECK-NOT: cmp.eq
10; CHECK: endloop0
11
12define i32 @test1(i32* nocapture %b, i32 %n) nounwind readonly {
13entry:
14  %cmp1 = icmp sgt i32 %n, 0
15  br i1 %cmp1, label %for.body.preheader, label %for.end
16
17for.body.preheader:
18  br label %for.body
19
20for.body:                                         ; preds = %for.body.preheader, %for.body
21  %sum.03 = phi i32 [ %add, %for.body ], [ 0, %for.body.preheader ]
22  %arrayidx.phi = phi i32* [ %arrayidx.inc, %for.body ], [ %b, %for.body.preheader ]
23  %i.02 = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ]
24  %0 = load i32, i32* %arrayidx.phi, align 4
25  %add = add nsw i32 %0, %sum.03
26  %inc = add nsw i32 %i.02, 1
27  %exitcond = icmp eq i32 %inc, %n
28  %arrayidx.inc = getelementptr i32, i32* %arrayidx.phi, i32 1
29  br i1 %exitcond, label %for.end.loopexit, label %for.body
30
31for.end.loopexit:
32  br label %for.end
33
34for.end:
35  %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.end.loopexit ]
36  ret i32 %sum.0.lcssa
37}
38
39; This test checks that that initial loop count value is removed.
40; CHECK-NOT: ={{.}}#40
41; CHECK: loop0
42; CHECK-NOT: r{{[0-9]+}}{{.}}={{.}}add(r{{[0-9]+}},{{.}}#-1)
43; CHECK-NOT: cmp.eq
44; CHECK: endloop0
45
46define i32 @test2(i32* nocapture %b) nounwind readonly {
47entry:
48  br label %for.body
49
50for.body:
51  %sum.02 = phi i32 [ 0, %entry ], [ %add, %for.body ]
52  %arrayidx.phi = phi i32* [ %b, %entry ], [ %arrayidx.inc, %for.body ]
53  %i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
54  %0 = load i32, i32* %arrayidx.phi, align 4
55  %add = add nsw i32 %0, %sum.02
56  %inc = add nsw i32 %i.01, 1
57  %exitcond = icmp eq i32 %inc, 40
58  %arrayidx.inc = getelementptr i32, i32* %arrayidx.phi, i32 1
59  br i1 %exitcond, label %for.end, label %for.body
60
61for.end:
62  ret i32 %add
63}
64
65; This test checks that we don't remove the induction variable since it's used.
66; CHECK: loop0
67; CHECK: r{{[0-9]+}}{{.}}={{.}}add(r{{[0-9]+}},{{.}}#1)
68; CHECK-NOT: cmp.eq
69; CHECK: endloop0
70define i32 @test3(i32* nocapture %b) nounwind {
71entry:
72  br label %for.body
73
74for.body:
75  %arrayidx.phi = phi i32* [ %b, %entry ], [ %arrayidx.inc, %for.body ]
76  %i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
77  store i32 %i.01, i32* %arrayidx.phi, align 4
78  %inc = add nsw i32 %i.01, 1
79  %exitcond = icmp eq i32 %inc, 40
80  %arrayidx.inc = getelementptr i32, i32* %arrayidx.phi, i32 1
81  br i1 %exitcond, label %for.end, label %for.body
82
83for.end:
84  ret i32 0
85}
86
87
88