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