• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -loop-vectorize -S < %s 2>&1 | FileCheck %s
2
3; Produced from test-case:
4;
5; void testGuardedInnerLoop(uint32_t *ptr, uint32_t denom, uint32_t numer, uint32_t outer_lim)
6; {
7;   for(uint32_t outer_i = 0; outer_i < outer_lim; ++outer_i) {
8;     if (denom > 0) {
9;       const uint32_t lim = numer / denom;
10;
11;       for (uint32_t i = 0; i < lim; ++i)
12;         ptr[i] = 1;
13;     }
14;   }
15; }
16
17
18target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128-ni:1"
19target triple = "x86_64-unknown-linux-gnu"
20
21define void @testGuardedInnerLoop(i32* %ptr, i32 %denom, i32 %numer, i32 %outer_lim) {
22entry:
23  %cmp1 = icmp eq i32 %outer_lim, 0
24  br i1 %cmp1, label %exit, label %loop1.preheader
25
26; Verify that a 'udiv' does not appear between the 'loop1.preheader' label, and
27; whatever label comes next.
28loop1.preheader:
29; CHECK-LABEL: loop1.preheader:
30; CHECK-NOT: udiv
31; CHECK-LABEL: :
32  br label %loop1
33
34loop1:
35  %outer_i = phi i32 [ %inc1, %loop2.exit ], [ 0, %loop1.preheader ]
36  %0 = add i32 %denom, -1
37  %1 = icmp ult i32 %0, %numer
38  br i1 %1, label %loop2.preheader, label %loop2.exit
39
40; Verify that a 'udiv' does appear between the 'loop2.preheader' label, and
41; whatever label comes next.
42loop2.preheader:
43; CHECK-LABEL: loop2.preheader:
44; CHECK: udiv
45; CHECK-LABEL: :
46  %lim = udiv i32 %numer, %denom
47  %2 = zext i32 %lim to i64
48  br label %loop2
49
50loop2:
51  %indvar.loop2 = phi i64 [ 0, %loop2.preheader ], [ %indvar.loop2.next, %loop2 ]
52  %arrayidx = getelementptr inbounds i32, i32* %ptr, i64 %indvar.loop2
53  store i32 1, i32* %arrayidx, align 4
54  %indvar.loop2.next = add nuw nsw i64 %indvar.loop2, 1
55  %cmp2 = icmp ult i64 %indvar.loop2.next, %2
56  br i1 %cmp2, label %loop2, label %loop2.exit
57
58loop2.exit:
59  %inc1 = add nuw i32 %outer_i, 1
60  %exitcond = icmp eq i32 %inc1, %outer_lim
61  br i1 %exitcond, label %exit, label %loop1
62
63exit:
64  ret void
65}
66