1; RUN: llc -march=hexagon < %s | FileCheck %s
2
3; Check that 3 or more addressing modes using the same constant extender are
4; transformed into using a register.
5; CHECK: r{{[0-9]+}} = ##g1
6; CHECK: r{{[0-9]+}} = memw(r{{[0-9]+}}+r{{[0-9]+}}<<#2)
7; CHECK: r{{[0-9]+}} = memw(r{{[0-9]+}}+r{{[0-9]+}}<<#2)
8; CHECK: r{{[0-9]+}} = memw(r{{[0-9]+}}+r{{[0-9]+}}<<#2)
9; CHECK-NOT: r{{[0-9]+}} = memw(r{{[0-9]+}}<<#2+##g1)
10; CHECK-NOT: r{{[0-9]+}} = memw(r{{[0-9]+}}<<#2+##g1)
11; CHECK-NOT: r{{[0-9]+}} = memw(r{{[0-9]+}}<<#2+##g1)
12; CHECK:  memw(r{{[0-9]+}}+r{{[0-9]+}}<<#2) = r{{[0-9]+}}
13; CHECK:  memw(r{{[0-9]+}}+r{{[0-9]+}}<<#2) = r{{[0-9]+}}
14; CHECK:  memw(r{{[0-9]+}}+r{{[0-9]+}}<<#2) = r{{[0-9]+}}
15; CHECK-NOT:  memw(r{{[0-9]+}}<<#2+##g1) = r{{[0-9]+}}
16; CHECK-NOT:  memw(r{{[0-9]+}}<<#2+##g1) = r{{[0-9]+}}
17; CHECK-NOT:  memw(r{{[0-9]+}}<<#2+##g1) = r{{[0-9]+}}
18
19target triple = "hexagon-unknown-linux-gnu"
20
21@g0 = external global i32
22@g1 = external global [13595 x i32], align 8
23@g2 = external global [13595 x i32], align 8
24
25define i32 @f0(i32 %a0, i32* nocapture %a1) {
26b0:
27  %v0 = load i32, i32* %a1, align 4
28  %v1 = getelementptr inbounds [13595 x i32], [13595 x i32]* @g1, i32 0, i32 %v0
29  %v2 = load i32, i32* %v1, align 4
30  %v3 = icmp sgt i32 %v2, %a0
31  br i1 %v3, label %b1, label %b2
32
33b1:                                               ; preds = %b0
34  %v4 = load i32, i32* @g0, align 4
35  store i32 %v4, i32* %a1, align 4
36  %v5 = load i32, i32* @g0, align 4
37  %v6 = getelementptr inbounds [13595 x i32], [13595 x i32]* @g2, i32 0, i32 %v5
38  %v7 = load i32, i32* %v6, align 4
39  store i32 %v7, i32* @g0, align 4
40  %v8 = load i32, i32* %a1, align 4
41  %v9 = getelementptr inbounds [13595 x i32], [13595 x i32]* @g2, i32 0, i32 %v8
42  store i32 %v0, i32* %v9, align 4
43  %v10 = load i32, i32* %a1, align 4
44  %v11 = getelementptr inbounds [13595 x i32], [13595 x i32]* @g1, i32 0, i32 %v10
45  store i32 %a0, i32* %v11, align 4
46  br label %b16
47
48b2:                                               ; preds = %b0
49  %v12 = icmp eq i32 %v2, %a0
50  br i1 %v12, label %b16, label %b3
51
52b3:                                               ; preds = %b2
53  br label %b4
54
55b4:                                               ; preds = %b13, %b3
56  %v13 = phi i32 [ %v45, %b13 ], [ %v0, %b3 ]
57  %v14 = getelementptr inbounds [13595 x i32], [13595 x i32]* @g2, i32 0, i32 %v13
58  %v15 = load i32, i32* %v14, align 4
59  %v16 = getelementptr inbounds [13595 x i32], [13595 x i32]* @g1, i32 0, i32 %v15
60  %v17 = load i32, i32* %v16, align 4
61  %v18 = icmp slt i32 %v17, %a0
62  br i1 %v18, label %b7, label %b5
63
64b5:                                               ; preds = %b4
65  %v19 = icmp eq i32 %v17, %a0
66  br i1 %v19, label %b16, label %b6
67
68b6:                                               ; preds = %b5
69  %v20 = load i32, i32* @g0, align 4
70  store i32 %v20, i32* %v14, align 4
71  %v21 = getelementptr inbounds [13595 x i32], [13595 x i32]* @g1, i32 0, i32 %v20
72  store i32 %a0, i32* %v21, align 4
73  %v22 = getelementptr inbounds [13595 x i32], [13595 x i32]* @g2, i32 0, i32 %v20
74  %v23 = load i32, i32* %v22, align 4
75  store i32 %v23, i32* @g0, align 4
76  store i32 %v15, i32* %v22, align 4
77  br label %b16
78
79b7:                                               ; preds = %b4
80  %v24 = getelementptr inbounds [13595 x i32], [13595 x i32]* @g2, i32 0, i32 %v15
81  %v25 = load i32, i32* %v24, align 4
82  %v26 = getelementptr inbounds [13595 x i32], [13595 x i32]* @g1, i32 0, i32 %v25
83  %v27 = load i32, i32* %v26, align 4
84  %v28 = icmp slt i32 %v27, %a0
85  br i1 %v28, label %b10, label %b8
86
87b8:                                               ; preds = %b7
88  %v29 = icmp eq i32 %v27, %a0
89  br i1 %v29, label %b16, label %b9
90
91b9:                                               ; preds = %b8
92  %v30 = load i32, i32* @g0, align 4
93  store i32 %v30, i32* %v24, align 4
94  %v31 = getelementptr inbounds [13595 x i32], [13595 x i32]* @g1, i32 0, i32 %v30
95  store i32 %a0, i32* %v31, align 4
96  %v32 = getelementptr inbounds [13595 x i32], [13595 x i32]* @g2, i32 0, i32 %v30
97  %v33 = load i32, i32* %v32, align 4
98  store i32 %v33, i32* @g0, align 4
99  store i32 %v25, i32* %v32, align 4
100  br label %b16
101
102b10:                                              ; preds = %b7
103  %v34 = getelementptr inbounds [13595 x i32], [13595 x i32]* @g2, i32 0, i32 %v25
104  %v35 = load i32, i32* %v34, align 4
105  %v36 = getelementptr inbounds [13595 x i32], [13595 x i32]* @g1, i32 0, i32 %v35
106  %v37 = load i32, i32* %v36, align 4
107  %v38 = icmp slt i32 %v37, %a0
108  br i1 %v38, label %b13, label %b11
109
110b11:                                              ; preds = %b10
111  %v39 = icmp eq i32 %v37, %a0
112  br i1 %v39, label %b16, label %b12
113
114b12:                                              ; preds = %b11
115  %v40 = load i32, i32* @g0, align 4
116  store i32 %v40, i32* %v34, align 4
117  %v41 = getelementptr inbounds [13595 x i32], [13595 x i32]* @g1, i32 0, i32 %v40
118  store i32 %a0, i32* %v41, align 4
119  %v42 = getelementptr inbounds [13595 x i32], [13595 x i32]* @g2, i32 0, i32 %v40
120  %v43 = load i32, i32* %v42, align 4
121  store i32 %v43, i32* @g0, align 4
122  store i32 %v35, i32* %v42, align 4
123  br label %b16
124
125b13:                                              ; preds = %b10
126  %v44 = getelementptr inbounds [13595 x i32], [13595 x i32]* @g2, i32 0, i32 %v35
127  %v45 = load i32, i32* %v44, align 4
128  %v46 = getelementptr inbounds [13595 x i32], [13595 x i32]* @g1, i32 0, i32 %v45
129  %v47 = load i32, i32* %v46, align 4
130  %v48 = icmp slt i32 %v47, %a0
131  br i1 %v48, label %b4, label %b14
132
133b14:                                              ; preds = %b13
134  %v49 = icmp eq i32 %v47, %a0
135  br i1 %v49, label %b16, label %b15
136
137b15:                                              ; preds = %b14
138  %v50 = load i32, i32* @g0, align 4
139  store i32 %v50, i32* %v44, align 4
140  %v51 = getelementptr inbounds [13595 x i32], [13595 x i32]* @g1, i32 0, i32 %v50
141  store i32 %a0, i32* %v51, align 4
142  %v52 = getelementptr inbounds [13595 x i32], [13595 x i32]* @g2, i32 0, i32 %v50
143  %v53 = load i32, i32* %v52, align 4
144  store i32 %v53, i32* @g0, align 4
145  store i32 %v45, i32* %v52, align 4
146  br label %b16
147
148b16:                                              ; preds = %b15, %b14, %b12, %b11, %b9, %b8, %b6, %b5, %b2, %b1
149  %v54 = phi i32 [ 1, %b1 ], [ 1, %b6 ], [ 1, %b9 ], [ 1, %b12 ], [ 1, %b15 ], [ 0, %b2 ], [ 0, %b5 ], [ 0, %b8 ], [ 0, %b11 ], [ 0, %b14 ]
150  ret i32 %v54
151}
152