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