comparison test/Analysis/BasicAA/phi-loop.ll @ 95:afa8332a0e37 LLVM3.8

LLVM 3.8
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Tue, 13 Oct 2015 17:48:58 +0900
parents
children
comparison
equal deleted inserted replaced
84:f3e34b893a5f 95:afa8332a0e37
1 ; RUN: opt < %s -basicaa -basicaa-recphi=1 -gvn -S | FileCheck %s
2 ;
3 ; Check that section->word_ofs doesn't get reloaded in every iteration of the
4 ; for loop.
5 ;
6 ; Code:
7 ;
8 ; typedef struct {
9 ; unsigned num_words;
10 ; unsigned word_ofs;
11 ; const unsigned *data;
12 ; } section_t;
13 ;
14 ;
15 ; void test2(const section_t * restrict section, unsigned * restrict dst) {;
16 ; while (section->data != NULL) {
17 ; const unsigned *src = section->data;
18 ; for (unsigned i=0; i < section->num_words; ++i) {
19 ; dst[section->word_ofs + i] = src[i];
20 ; }
21 ;
22 ; ++section;
23 ; }
24 ; }
25 ;
26
27 ; CHECK-LABEL: for.body:
28 ; CHECK-NOT: load i32, i32* %word_ofs
29
30 %struct.section_t = type { i32, i32, i32* }
31
32 define void @test2(%struct.section_t* noalias nocapture readonly %section, i32* noalias nocapture %dst) {
33 entry:
34 %data13 = getelementptr inbounds %struct.section_t, %struct.section_t* %section, i32 0, i32 2
35 %0 = load i32*, i32** %data13, align 4
36 %cmp14 = icmp eq i32* %0, null
37 br i1 %cmp14, label %while.end, label %for.cond.preheader
38
39 for.cond.preheader: ; preds = %entry, %for.end
40 %1 = phi i32* [ %6, %for.end ], [ %0, %entry ]
41 %section.addr.015 = phi %struct.section_t* [ %incdec.ptr, %for.end ], [ %section, %entry ]
42 %num_words = getelementptr inbounds %struct.section_t, %struct.section_t* %section.addr.015, i32 0, i32 0
43 %2 = load i32, i32* %num_words, align 4
44 %cmp211 = icmp eq i32 %2, 0
45 br i1 %cmp211, label %for.end, label %for.body.lr.ph
46
47 for.body.lr.ph: ; preds = %for.cond.preheader
48 %word_ofs = getelementptr inbounds %struct.section_t, %struct.section_t* %section.addr.015, i32 0, i32 1
49 br label %for.body
50
51 for.body: ; preds = %for.body.lr.ph, %for.body
52 %arrayidx.phi = phi i32* [ %1, %for.body.lr.ph ], [ %arrayidx.inc, %for.body ]
53 %i.012 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
54 %3 = load i32, i32* %arrayidx.phi, align 4
55 %4 = load i32, i32* %word_ofs, align 4
56 %add = add i32 %4, %i.012
57 %arrayidx3 = getelementptr inbounds i32, i32* %dst, i32 %add
58 store i32 %3, i32* %arrayidx3, align 4
59 %inc = add i32 %i.012, 1
60 %5 = load i32, i32* %num_words, align 4
61 %cmp2 = icmp ult i32 %inc, %5
62 %arrayidx.inc = getelementptr i32, i32* %arrayidx.phi, i32 1
63 br i1 %cmp2, label %for.body, label %for.end
64
65 for.end: ; preds = %for.body, %for.cond.preheader
66 %incdec.ptr = getelementptr inbounds %struct.section_t, %struct.section_t* %section.addr.015, i32 1
67 %data = getelementptr inbounds %struct.section_t, %struct.section_t* %section.addr.015, i32 1, i32 2
68 %6 = load i32*, i32** %data, align 4
69 %cmp = icmp eq i32* %6, null
70 br i1 %cmp, label %while.end, label %for.cond.preheader
71
72 while.end: ; preds = %for.end, %entry
73 ret void
74 }
75