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