1; RUN: opt < %s -aa-pipeline=basic-aa -passes=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, ptr } 31 32define void @test2(ptr noalias nocapture readonly %section, ptr noalias nocapture %dst) { 33entry: 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 38 39for.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 45 46for.body.lr.ph: ; preds = %for.cond.preheader 47 %word_ofs = getelementptr inbounds %struct.section_t, ptr %section.addr.015, i32 0, i32 1 48 br label %for.body 49 50for.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 63 64for.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 70 71while.end: ; preds = %for.end, %entry 72 ret void 73} 74 75