1; RUN: llc < %s -mcpu=atom -mtriple=i686-linux | FileCheck %s 2; CHECK: addl ({{%[a-z]+}},[[reg:%[a-z]+]],4) 3; CHECK-NEXT: movl 4; CHECK-NEXT: addl 4({{%[a-z]+}},[[reg:%[a-z]+]],4) 5; CHECK-NEXT: incl 6 7; Test for the FixupLEAs pre-emit pass. 8; An LEA should NOT be substituted for the ADD instruction 9; that increments the array pointer if it is greater than 5 instructions 10; away from the memory reference that uses it. 11 12; Original C code: clang -m32 -S -O2 13;int test(int n, int * array, int * m, int * array2) 14;{ 15; int i, j = 0; 16; int sum = 0; 17; for (i = 0, j = 0; i < n;) { 18; ++i; 19; *m += array2[j++]; 20; sum += array[i]; 21; } 22; return sum; 23;} 24 25define i32 @test(i32 %n, i32* nocapture %array, i32* nocapture %k, i32* nocapture %l, i32* nocapture %m, i32* nocapture %array2) #0 { 26entry: 27 %cmp7 = icmp sgt i32 %n, 0 28 br i1 %cmp7, label %for.body.lr.ph, label %for.end 29 30for.body.lr.ph: ; preds = %entry 31 %.pre = load i32, i32* %m, align 4 32 br label %for.body 33 34for.body: ; preds = %for.body, %for.body.lr.ph 35 %0 = phi i32 [ %.pre, %for.body.lr.ph ], [ %add, %for.body ] 36 %sum.010 = phi i32 [ 0, %for.body.lr.ph ], [ %add3, %for.body ] 37 %j.09 = phi i32 [ 0, %for.body.lr.ph ], [ %inc1, %for.body ] 38 %inc1 = add nsw i32 %j.09, 1 39 %arrayidx = getelementptr inbounds i32, i32* %array2, i32 %j.09 40 store i32 %0, i32* %m, align 4 41 store i32 %sum.010, i32* %m, align 4 42 store i32 %0, i32* %m, align 4 43 %1 = load i32, i32* %arrayidx, align 4 44 %add = add nsw i32 %0, %1 45 store i32 %add, i32* %m, align 4 46 %arrayidx2 = getelementptr inbounds i32, i32* %array, i32 %inc1 47 %2 = load i32, i32* %arrayidx2, align 4 48 %add3 = add nsw i32 %2, %sum.010 49 %exitcond = icmp eq i32 %inc1, %n 50 br i1 %exitcond, label %for.end, label %for.body 51 52for.end: ; preds = %for.body, %entry 53 %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add3, %for.body ] 54 ret i32 %sum.0.lcssa 55} 56 57