1*f4a2713aSLionel Sambuc; RUN: llc < %s -mcpu=atom -mtriple=i686-linux | FileCheck %s 2*f4a2713aSLionel Sambuc; CHECK:BB#5 3*f4a2713aSLionel Sambuc; CHECK-NEXT:leal 4*f4a2713aSLionel Sambuc; CHECK-NEXT:leal 5*f4a2713aSLionel Sambuc; CHECK-NEXT:leal 6*f4a2713aSLionel Sambuc; CHECK-NEXT:movl 7*f4a2713aSLionel Sambuc 8*f4a2713aSLionel Sambuc 9*f4a2713aSLionel Sambuc; Test for fixup lea pre-emit pass. LEA instructions should be substituted for 10*f4a2713aSLionel Sambuc; ADD instructions which compute the address and index of the load because they 11*f4a2713aSLionel Sambuc; precede the load within 5 instructions. An LEA should also be substituted for 12*f4a2713aSLionel Sambuc; an ADD which computes part of the index because it precedes the index LEA 13*f4a2713aSLionel Sambuc; within 5 instructions, this substitution is referred to as backwards chaining. 14*f4a2713aSLionel Sambuc 15*f4a2713aSLionel Sambuc; Original C Code 16*f4a2713aSLionel Sambuc;struct node_t 17*f4a2713aSLionel Sambuc;{ 18*f4a2713aSLionel Sambuc; int k, m, n, p; 19*f4a2713aSLionel Sambuc; int * array; 20*f4a2713aSLionel Sambuc;}; 21*f4a2713aSLionel Sambuc 22*f4a2713aSLionel Sambuc;extern struct node_t getnode(); 23*f4a2713aSLionel Sambuc 24*f4a2713aSLionel Sambuc;int test() 25*f4a2713aSLionel Sambuc;{ 26*f4a2713aSLionel Sambuc; int sum = 0; 27*f4a2713aSLionel Sambuc; struct node_t n = getnode(); 28*f4a2713aSLionel Sambuc; if(n.array != 0 && n.p > 0 && n.k > 0 && n.n > 0 && n.m > 0) { 29*f4a2713aSLionel Sambuc; sum = ((int*)((int)n.array + n.p) )[ n.k + n.m + n.n ]; 30*f4a2713aSLionel Sambuc; } 31*f4a2713aSLionel Sambuc; return sum; 32*f4a2713aSLionel Sambuc;} 33*f4a2713aSLionel Sambuc 34*f4a2713aSLionel Sambuc%struct.node_t = type { i32, i32, i32, i32, i32* } 35*f4a2713aSLionel Sambuc 36*f4a2713aSLionel Sambucdefine i32 @test() { 37*f4a2713aSLionel Sambucentry: 38*f4a2713aSLionel Sambuc %n = alloca %struct.node_t, align 4 39*f4a2713aSLionel Sambuc call void bitcast (void (%struct.node_t*, ...)* @getnode to void (%struct.node_t*)*)(%struct.node_t* sret %n) 40*f4a2713aSLionel Sambuc %array = getelementptr inbounds %struct.node_t* %n, i32 0, i32 4 41*f4a2713aSLionel Sambuc %0 = load i32** %array, align 4 42*f4a2713aSLionel Sambuc %cmp = icmp eq i32* %0, null 43*f4a2713aSLionel Sambuc br i1 %cmp, label %if.end, label %land.lhs.true 44*f4a2713aSLionel Sambuc 45*f4a2713aSLionel Sambucland.lhs.true: 46*f4a2713aSLionel Sambuc %p = getelementptr inbounds %struct.node_t* %n, i32 0, i32 3 47*f4a2713aSLionel Sambuc %1 = load i32* %p, align 4 48*f4a2713aSLionel Sambuc %cmp1 = icmp sgt i32 %1, 0 49*f4a2713aSLionel Sambuc br i1 %cmp1, label %land.lhs.true2, label %if.end 50*f4a2713aSLionel Sambuc 51*f4a2713aSLionel Sambucland.lhs.true2: 52*f4a2713aSLionel Sambuc %k = getelementptr inbounds %struct.node_t* %n, i32 0, i32 0 53*f4a2713aSLionel Sambuc %2 = load i32* %k, align 4 54*f4a2713aSLionel Sambuc %cmp3 = icmp sgt i32 %2, 0 55*f4a2713aSLionel Sambuc br i1 %cmp3, label %land.lhs.true4, label %if.end 56*f4a2713aSLionel Sambuc 57*f4a2713aSLionel Sambucland.lhs.true4: 58*f4a2713aSLionel Sambuc %n5 = getelementptr inbounds %struct.node_t* %n, i32 0, i32 2 59*f4a2713aSLionel Sambuc %3 = load i32* %n5, align 4 60*f4a2713aSLionel Sambuc %cmp6 = icmp sgt i32 %3, 0 61*f4a2713aSLionel Sambuc br i1 %cmp6, label %land.lhs.true7, label %if.end 62*f4a2713aSLionel Sambuc 63*f4a2713aSLionel Sambucland.lhs.true7: 64*f4a2713aSLionel Sambuc %m = getelementptr inbounds %struct.node_t* %n, i32 0, i32 1 65*f4a2713aSLionel Sambuc %4 = load i32* %m, align 4 66*f4a2713aSLionel Sambuc %cmp8 = icmp sgt i32 %4, 0 67*f4a2713aSLionel Sambuc br i1 %cmp8, label %if.then, label %if.end 68*f4a2713aSLionel Sambuc 69*f4a2713aSLionel Sambucif.then: 70*f4a2713aSLionel Sambuc %add = add i32 %3, %2 71*f4a2713aSLionel Sambuc %add12 = add i32 %add, %4 72*f4a2713aSLionel Sambuc %5 = ptrtoint i32* %0 to i32 73*f4a2713aSLionel Sambuc %add15 = add nsw i32 %1, %5 74*f4a2713aSLionel Sambuc %6 = inttoptr i32 %add15 to i32* 75*f4a2713aSLionel Sambuc %arrayidx = getelementptr inbounds i32* %6, i32 %add12 76*f4a2713aSLionel Sambuc %7 = load i32* %arrayidx, align 4 77*f4a2713aSLionel Sambuc br label %if.end 78*f4a2713aSLionel Sambuc 79*f4a2713aSLionel Sambucif.end: 80*f4a2713aSLionel Sambuc %sum.0 = phi i32 [ %7, %if.then ], [ 0, %land.lhs.true7 ], [ 0, %land.lhs.true4 ], [ 0, %land.lhs.true2 ], [ 0, %land.lhs.true ], [ 0, %entry ] 81*f4a2713aSLionel Sambuc ret i32 %sum.0 82*f4a2713aSLionel Sambuc} 83*f4a2713aSLionel Sambuc 84*f4a2713aSLionel Sambucdeclare void @getnode(%struct.node_t* sret, ...) 85