1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 3
2 ; RUN: llc -mtriple=riscv64 < %s | FileCheck -check-prefix=RV64 %s
4 define void @add_sext_shl_moreOneUse_add(ptr %array1, i32 %a, i32 %b) {
5 ; RV64-LABEL: add_sext_shl_moreOneUse_add:
6 ; RV64: # %bb.0: # %entry
7 ; RV64-NEXT: addi a3, a1, 5
8 ; RV64-NEXT: sext.w a1, a1
9 ; RV64-NEXT: slli a1, a1, 2
10 ; RV64-NEXT: add a0, a1, a0
11 ; RV64-NEXT: sw a2, 20(a0)
12 ; RV64-NEXT: sw a2, 24(a0)
13 ; RV64-NEXT: sw a3, 140(a0)
16 %add = add nsw i32 %a, 5
17 %idxprom = sext i32 %add to i64
18 %arrayidx = getelementptr inbounds i32, ptr %array1, i64 %idxprom
19 store i32 %b, ptr %arrayidx
20 %add3 = add nsw i32 %a, 6
21 %idxprom4 = sext i32 %add3 to i64
22 %arrayidx5 = getelementptr inbounds i32, ptr %array1, i64 %idxprom4
23 store i32 %b, ptr %arrayidx5
24 %add6 = add nsw i32 %a, 35
25 %idxprom7 = sext i32 %add6 to i64
26 %arrayidx8 = getelementptr inbounds i32, ptr %array1, i64 %idxprom7
27 store i32 %add, ptr %arrayidx8
31 define void @add_sext_shl_moreOneUse_addexceedsign12(ptr %array1, i32 %a, i32 %b) {
32 ; RV64-LABEL: add_sext_shl_moreOneUse_addexceedsign12:
33 ; RV64: # %bb.0: # %entry
34 ; RV64-NEXT: addi a3, a1, 2047
35 ; RV64-NEXT: lui a4, 2
36 ; RV64-NEXT: sext.w a1, a1
37 ; RV64-NEXT: addi a3, a3, 1
38 ; RV64-NEXT: slli a1, a1, 2
39 ; RV64-NEXT: add a0, a0, a4
40 ; RV64-NEXT: add a0, a0, a1
41 ; RV64-NEXT: sw a2, 0(a0)
42 ; RV64-NEXT: sw a3, 4(a0)
43 ; RV64-NEXT: sw a2, 120(a0)
46 %add = add nsw i32 %a, 2048
47 %idxprom = sext i32 %add to i64
48 %arrayidx = getelementptr inbounds i32, ptr %array1, i64 %idxprom
49 store i32 %b, ptr %arrayidx
50 %0 = sext i32 %a to i64
51 %1 = getelementptr i32, ptr %array1, i64 %0
52 %arrayidx3 = getelementptr i8, ptr %1, i64 8196
53 store i32 %add, ptr %arrayidx3
54 %arrayidx6 = getelementptr i8, ptr %1, i64 8312
55 store i32 %b, ptr %arrayidx6
59 define void @add_sext_shl_moreOneUse_sext(ptr %array1, i32 %a, i32 %b) {
60 ; RV64-LABEL: add_sext_shl_moreOneUse_sext:
61 ; RV64: # %bb.0: # %entry
62 ; RV64-NEXT: sext.w a1, a1
63 ; RV64-NEXT: addi a3, a1, 5
64 ; RV64-NEXT: slli a1, a1, 2
65 ; RV64-NEXT: add a0, a1, a0
66 ; RV64-NEXT: sw a2, 20(a0)
67 ; RV64-NEXT: sw a2, 24(a0)
68 ; RV64-NEXT: sd a3, 140(a0)
71 %add = add nsw i32 %a, 5
72 %idxprom = sext i32 %add to i64
73 %arrayidx = getelementptr inbounds i32, ptr %array1, i64 %idxprom
74 store i32 %b, ptr %arrayidx
75 %add3 = add nsw i32 %a, 6
76 %idxprom4 = sext i32 %add3 to i64
77 %arrayidx5 = getelementptr inbounds i32, ptr %array1, i64 %idxprom4
78 store i32 %b, ptr %arrayidx5
79 %add6 = add nsw i32 %a, 35
80 %idxprom7 = sext i32 %add6 to i64
81 %arrayidx8 = getelementptr inbounds i32, ptr %array1, i64 %idxprom7
82 store i64 %idxprom, ptr %arrayidx8
86 ; test of jumpping, find add's operand has one more use can simplified
87 define void @add_sext_shl_moreOneUse_add_inSelect(ptr %array1, i32 signext %a, i32 %b, i32 signext %x) {
88 ; RV64-LABEL: add_sext_shl_moreOneUse_add_inSelect:
89 ; RV64: # %bb.0: # %entry
90 ; RV64-NEXT: addi a4, a1, 5
91 ; RV64-NEXT: mv a5, a4
92 ; RV64-NEXT: bgtz a3, .LBB3_2
93 ; RV64-NEXT: # %bb.1: # %entry
94 ; RV64-NEXT: mv a5, a2
95 ; RV64-NEXT: .LBB3_2: # %entry
96 ; RV64-NEXT: slli a1, a1, 2
97 ; RV64-NEXT: add a0, a1, a0
98 ; RV64-NEXT: sw a5, 20(a0)
99 ; RV64-NEXT: sw a5, 24(a0)
100 ; RV64-NEXT: sw a4, 140(a0)
103 %add = add nsw i32 %a, 5
104 %cmp = icmp sgt i32 %x, 0
105 %idxprom = sext i32 %add to i64
106 %arrayidx = getelementptr inbounds i32, ptr %array1, i64 %idxprom
107 %add.b = select i1 %cmp, i32 %add, i32 %b
108 store i32 %add.b, ptr %arrayidx
109 %add5 = add nsw i32 %a, 6
110 %idxprom6 = sext i32 %add5 to i64
111 %arrayidx7 = getelementptr inbounds i32, ptr %array1, i64 %idxprom6
112 store i32 %add.b, ptr %arrayidx7
113 %add8 = add nsw i32 %a, 35
114 %idxprom9 = sext i32 %add8 to i64
115 %arrayidx10 = getelementptr inbounds i32, ptr %array1, i64 %idxprom9
116 store i32 %add, ptr %arrayidx10
120 define void @add_sext_shl_moreOneUse_add_inSelect_addexceedsign12(ptr %array1, i32 signext %a, i32 %b, i32 signext %x) {
121 ; RV64-LABEL: add_sext_shl_moreOneUse_add_inSelect_addexceedsign12:
122 ; RV64: # %bb.0: # %entry
123 ; RV64-NEXT: addi a4, a1, 2047
124 ; RV64-NEXT: lui a5, 2
125 ; RV64-NEXT: slli a6, a1, 2
126 ; RV64-NEXT: addi a1, a4, 1
127 ; RV64-NEXT: add a0, a0, a6
128 ; RV64-NEXT: add a0, a0, a5
129 ; RV64-NEXT: mv a4, a1
130 ; RV64-NEXT: bgtz a3, .LBB4_2
131 ; RV64-NEXT: # %bb.1: # %entry
132 ; RV64-NEXT: mv a4, a2
133 ; RV64-NEXT: .LBB4_2: # %entry
134 ; RV64-NEXT: sw a4, 0(a0)
135 ; RV64-NEXT: sw a4, 4(a0)
136 ; RV64-NEXT: sw a1, 120(a0)
139 %add = add nsw i32 %a, 2048
140 %cmp = icmp sgt i32 %x, 0
141 %idxprom = sext i32 %add to i64
142 %arrayidx = getelementptr inbounds i32, ptr %array1, i64 %idxprom
143 %add.b = select i1 %cmp, i32 %add, i32 %b
144 store i32 %add.b, ptr %arrayidx
145 %0 = sext i32 %a to i64
146 %1 = getelementptr i32, ptr %array1, i64 %0
147 %arrayidx7 = getelementptr i8, ptr %1, i64 8196
148 store i32 %add.b, ptr %arrayidx7
149 %arrayidx10 = getelementptr i8, ptr %1, i64 8312
150 store i32 %add, ptr %arrayidx10
154 define void @add_shl_moreOneUse_inSelect(ptr %array1, i64 %a, i64 %b, i64 %x) {
155 ; RV64-LABEL: add_shl_moreOneUse_inSelect:
156 ; RV64: # %bb.0: # %entry
157 ; RV64-NEXT: addi a4, a1, 5
158 ; RV64-NEXT: mv a5, a4
159 ; RV64-NEXT: bgtz a3, .LBB5_2
160 ; RV64-NEXT: # %bb.1: # %entry
161 ; RV64-NEXT: mv a5, a2
162 ; RV64-NEXT: .LBB5_2: # %entry
163 ; RV64-NEXT: slli a1, a1, 3
164 ; RV64-NEXT: add a0, a1, a0
165 ; RV64-NEXT: sd a5, 40(a0)
166 ; RV64-NEXT: sd a5, 48(a0)
167 ; RV64-NEXT: sd a4, 280(a0)
170 %add = add nsw i64 %a, 5
171 %cmp = icmp sgt i64 %x, 0
172 %spec.select = select i1 %cmp, i64 %add, i64 %b
173 %0 = getelementptr inbounds i64, ptr %array1, i64 %add
174 store i64 %spec.select, ptr %0
175 %add3 = add nsw i64 %a, 6
176 %arrayidx4 = getelementptr inbounds i64, ptr %array1, i64 %add3
177 store i64 %spec.select, ptr %arrayidx4
178 %add5 = add nsw i64 %a, 35
179 %arrayidx6 = getelementptr inbounds i64, ptr %array1, i64 %add5
180 store i64 %add, ptr %arrayidx6