1 ; RUN: opt < %s -aa-pipeline=basic-aa -passes=gvn -S | FileCheck %s
3 ; Check that section->word_ofs doesn't get reloaded in every iteration of the
11 ; const unsigned *data;
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];
27 ; CHECK-LABEL: for.body:
28 ; CHECK-NOT: load i32, i32* %word_ofs
30 %struct.section_t = type { i32, i32, ptr }
32 define void @test2(ptr noalias nocapture readonly %section, ptr noalias nocapture %dst) {
34 %data13 = getelementptr inbounds %struct.section_t, ptr %section, i32 0, i32 2
35 %0 = load ptr, ptr %data13, align 4
36 %cmp14 = icmp eq ptr %0, null
37 br i1 %cmp14, label %while.end, label %for.cond.preheader
39 for.cond.preheader: ; preds = %entry, %for.end
40 %1 = phi ptr [ %6, %for.end ], [ %0, %entry ]
41 %section.addr.015 = phi ptr [ %incdec.ptr, %for.end ], [ %section, %entry ]
42 %2 = load i32, ptr %section.addr.015, align 4
43 %cmp211 = icmp eq i32 %2, 0
44 br i1 %cmp211, label %for.end, label %for.body.lr.ph
46 for.body.lr.ph: ; preds = %for.cond.preheader
47 %word_ofs = getelementptr inbounds %struct.section_t, ptr %section.addr.015, i32 0, i32 1
50 for.body: ; preds = %for.body.lr.ph, %for.body
51 %arrayidx.phi = phi ptr [ %1, %for.body.lr.ph ], [ %arrayidx.inc, %for.body ]
52 %i.012 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
53 %3 = load i32, ptr %arrayidx.phi, align 4
54 %4 = load i32, ptr %word_ofs, align 4
55 %add = add i32 %4, %i.012
56 %arrayidx3 = getelementptr inbounds i32, ptr %dst, i32 %add
57 store i32 %3, ptr %arrayidx3, align 4
58 %inc = add i32 %i.012, 1
59 %5 = load i32, ptr %section.addr.015, align 4
60 %cmp2 = icmp ult i32 %inc, %5
61 %arrayidx.inc = getelementptr i32, ptr %arrayidx.phi, i32 1
62 br i1 %cmp2, label %for.body, label %for.end
64 for.end: ; preds = %for.body, %for.cond.preheader
65 %incdec.ptr = getelementptr inbounds %struct.section_t, ptr %section.addr.015, i32 1
66 %data = getelementptr inbounds %struct.section_t, ptr %section.addr.015, i32 1, i32 2
67 %6 = load ptr, ptr %data, align 4
68 %cmp = icmp eq ptr %6, null
69 br i1 %cmp, label %while.end, label %for.cond.preheader
71 while.end: ; preds = %for.end, %entry