1 ; RUN: llc -march=hexagon < %s | FileCheck %s
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]+}}
19 target triple = "hexagon-unknown-linux-gnu"
21 @g0 = external global i32
22 @g1 = external global [13595 x i32], align 8
23 @g2 = external global [13595 x i32], align 8
25 define i32 @f0(i32 %a0, ptr nocapture %a1) {
27 %v0 = load i32, ptr %a1, align 4
28 %v1 = getelementptr inbounds [13595 x i32], ptr @g1, i32 0, i32 %v0
29 %v2 = load i32, ptr %v1, align 4
30 %v3 = icmp sgt i32 %v2, %a0
31 br i1 %v3, label %b1, label %b2
34 %v4 = load i32, ptr @g0, align 4
35 store i32 %v4, ptr %a1, align 4
36 %v5 = load i32, ptr @g0, align 4
37 %v6 = getelementptr inbounds [13595 x i32], ptr @g2, i32 0, i32 %v5
38 %v7 = load i32, ptr %v6, align 4
39 store i32 %v7, ptr @g0, align 4
40 %v8 = load i32, ptr %a1, align 4
41 %v9 = getelementptr inbounds [13595 x i32], ptr @g2, i32 0, i32 %v8
42 store i32 %v0, ptr %v9, align 4
43 %v10 = load i32, ptr %a1, align 4
44 %v11 = getelementptr inbounds [13595 x i32], ptr @g1, i32 0, i32 %v10
45 store i32 %a0, ptr %v11, align 4
49 %v12 = icmp eq i32 %v2, %a0
50 br i1 %v12, label %b16, label %b3
55 b4: ; preds = %b13, %b3
56 %v13 = phi i32 [ %v45, %b13 ], [ %v0, %b3 ]
57 %v14 = getelementptr inbounds [13595 x i32], ptr @g2, i32 0, i32 %v13
58 %v15 = load i32, ptr %v14, align 4
59 %v16 = getelementptr inbounds [13595 x i32], ptr @g1, i32 0, i32 %v15
60 %v17 = load i32, ptr %v16, align 4
61 %v18 = icmp slt i32 %v17, %a0
62 br i1 %v18, label %b7, label %b5
65 %v19 = icmp eq i32 %v17, %a0
66 br i1 %v19, label %b16, label %b6
69 %v20 = load i32, ptr @g0, align 4
70 store i32 %v20, ptr %v14, align 4
71 %v21 = getelementptr inbounds [13595 x i32], ptr @g1, i32 0, i32 %v20
72 store i32 %a0, ptr %v21, align 4
73 %v22 = getelementptr inbounds [13595 x i32], ptr @g2, i32 0, i32 %v20
74 %v23 = load i32, ptr %v22, align 4
75 store i32 %v23, ptr @g0, align 4
76 store i32 %v15, ptr %v22, align 4
80 %v24 = getelementptr inbounds [13595 x i32], ptr @g2, i32 0, i32 %v15
81 %v25 = load i32, ptr %v24, align 4
82 %v26 = getelementptr inbounds [13595 x i32], ptr @g1, i32 0, i32 %v25
83 %v27 = load i32, ptr %v26, align 4
84 %v28 = icmp slt i32 %v27, %a0
85 br i1 %v28, label %b10, label %b8
88 %v29 = icmp eq i32 %v27, %a0
89 br i1 %v29, label %b16, label %b9
92 %v30 = load i32, ptr @g0, align 4
93 store i32 %v30, ptr %v24, align 4
94 %v31 = getelementptr inbounds [13595 x i32], ptr @g1, i32 0, i32 %v30
95 store i32 %a0, ptr %v31, align 4
96 %v32 = getelementptr inbounds [13595 x i32], ptr @g2, i32 0, i32 %v30
97 %v33 = load i32, ptr %v32, align 4
98 store i32 %v33, ptr @g0, align 4
99 store i32 %v25, ptr %v32, align 4
103 %v34 = getelementptr inbounds [13595 x i32], ptr @g2, i32 0, i32 %v25
104 %v35 = load i32, ptr %v34, align 4
105 %v36 = getelementptr inbounds [13595 x i32], ptr @g1, i32 0, i32 %v35
106 %v37 = load i32, ptr %v36, align 4
107 %v38 = icmp slt i32 %v37, %a0
108 br i1 %v38, label %b13, label %b11
111 %v39 = icmp eq i32 %v37, %a0
112 br i1 %v39, label %b16, label %b12
115 %v40 = load i32, ptr @g0, align 4
116 store i32 %v40, ptr %v34, align 4
117 %v41 = getelementptr inbounds [13595 x i32], ptr @g1, i32 0, i32 %v40
118 store i32 %a0, ptr %v41, align 4
119 %v42 = getelementptr inbounds [13595 x i32], ptr @g2, i32 0, i32 %v40
120 %v43 = load i32, ptr %v42, align 4
121 store i32 %v43, ptr @g0, align 4
122 store i32 %v35, ptr %v42, align 4
126 %v44 = getelementptr inbounds [13595 x i32], ptr @g2, i32 0, i32 %v35
127 %v45 = load i32, ptr %v44, align 4
128 %v46 = getelementptr inbounds [13595 x i32], ptr @g1, i32 0, i32 %v45
129 %v47 = load i32, ptr %v46, align 4
130 %v48 = icmp slt i32 %v47, %a0
131 br i1 %v48, label %b4, label %b14
134 %v49 = icmp eq i32 %v47, %a0
135 br i1 %v49, label %b16, label %b15
138 %v50 = load i32, ptr @g0, align 4
139 store i32 %v50, ptr %v44, align 4
140 %v51 = getelementptr inbounds [13595 x i32], ptr @g1, i32 0, i32 %v50
141 store i32 %a0, ptr %v51, align 4
142 %v52 = getelementptr inbounds [13595 x i32], ptr @g2, i32 0, i32 %v50
143 %v53 = load i32, ptr %v52, align 4
144 store i32 %v53, ptr @g0, align 4
145 store i32 %v45, ptr %v52, align 4
148 b16: ; 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 ]