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