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