blob: 7dff179a2c319db6bbc2864b9077ba6eac18cda7 [file] [log] [blame]
Keith Randall0dca7352015-06-06 16:03:33 -07001// autogenerated from gen/generic.rules: do not edit!
2// generated with: cd gen; go run *.go
Matthew Dempsky9ace4552016-03-01 10:58:06 -08003
Keith Randall0dca7352015-06-06 16:03:33 -07004package ssa
5
David Chase3a9d0ac2015-08-28 14:24:10 -04006import "math"
7
8var _ = math.MinInt8 // in case not otherwise used
Keith Randall0dca7352015-06-06 16:03:33 -07009func rewriteValuegeneric(v *Value, config *Config) bool {
10 switch v.Op {
Keith Randall582baae2015-11-02 21:28:13 -080011 case OpAdd16:
12 return rewriteValuegeneric_OpAdd16(v, config)
13 case OpAdd32:
14 return rewriteValuegeneric_OpAdd32(v, config)
Todd Nealf6ceed22016-03-11 19:36:54 -060015 case OpAdd32F:
16 return rewriteValuegeneric_OpAdd32F(v, config)
Keith Randall67fdb0d2015-07-19 15:48:20 -070017 case OpAdd64:
Keith Randalla347ab72015-10-26 21:49:31 -070018 return rewriteValuegeneric_OpAdd64(v, config)
Todd Nealf6ceed22016-03-11 19:36:54 -060019 case OpAdd64F:
20 return rewriteValuegeneric_OpAdd64F(v, config)
Keith Randall582baae2015-11-02 21:28:13 -080021 case OpAdd8:
22 return rewriteValuegeneric_OpAdd8(v, config)
Alexandru Moșoia7a19992016-03-18 10:50:00 +010023 case OpAddPtr:
24 return rewriteValuegeneric_OpAddPtr(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +020025 case OpAnd16:
Keith Randalla347ab72015-10-26 21:49:31 -070026 return rewriteValuegeneric_OpAnd16(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +020027 case OpAnd32:
Keith Randalla347ab72015-10-26 21:49:31 -070028 return rewriteValuegeneric_OpAnd32(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +020029 case OpAnd64:
Keith Randalla347ab72015-10-26 21:49:31 -070030 return rewriteValuegeneric_OpAnd64(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +020031 case OpAnd8:
Keith Randalla347ab72015-10-26 21:49:31 -070032 return rewriteValuegeneric_OpAnd8(v, config)
Keith Randall02f4d0a2015-11-02 08:10:26 -080033 case OpArg:
34 return rewriteValuegeneric_OpArg(v, config)
Keith Randall0dca7352015-06-06 16:03:33 -070035 case OpArrayIndex:
Keith Randalla347ab72015-10-26 21:49:31 -070036 return rewriteValuegeneric_OpArrayIndex(v, config)
Todd Neal38ed6c12015-07-30 16:02:24 -040037 case OpCom16:
Keith Randalla347ab72015-10-26 21:49:31 -070038 return rewriteValuegeneric_OpCom16(v, config)
Todd Neal38ed6c12015-07-30 16:02:24 -040039 case OpCom32:
Keith Randalla347ab72015-10-26 21:49:31 -070040 return rewriteValuegeneric_OpCom32(v, config)
Todd Neal38ed6c12015-07-30 16:02:24 -040041 case OpCom64:
Keith Randalla347ab72015-10-26 21:49:31 -070042 return rewriteValuegeneric_OpCom64(v, config)
Todd Neal38ed6c12015-07-30 16:02:24 -040043 case OpCom8:
Keith Randalla347ab72015-10-26 21:49:31 -070044 return rewriteValuegeneric_OpCom8(v, config)
Keith Randall9f954db2015-08-18 10:26:28 -070045 case OpConstInterface:
Keith Randalla347ab72015-10-26 21:49:31 -070046 return rewriteValuegeneric_OpConstInterface(v, config)
Keith Randall9f954db2015-08-18 10:26:28 -070047 case OpConstSlice:
Keith Randalla347ab72015-10-26 21:49:31 -070048 return rewriteValuegeneric_OpConstSlice(v, config)
Keith Randall9cb332e2015-07-28 14:19:20 -070049 case OpConstString:
Keith Randalla347ab72015-10-26 21:49:31 -070050 return rewriteValuegeneric_OpConstString(v, config)
Keith Randalla3180d82015-10-23 14:08:50 -070051 case OpConvert:
Keith Randalla347ab72015-10-26 21:49:31 -070052 return rewriteValuegeneric_OpConvert(v, config)
Todd Nealf6ceed22016-03-11 19:36:54 -060053 case OpCvt32Fto64F:
54 return rewriteValuegeneric_OpCvt32Fto64F(v, config)
55 case OpCvt64Fto32F:
56 return rewriteValuegeneric_OpCvt64Fto32F(v, config)
Cherry Zhang7d70f842016-07-06 10:04:45 -040057 case OpDiv32F:
58 return rewriteValuegeneric_OpDiv32F(v, config)
Keith Randalla3055af2016-02-05 20:26:18 -080059 case OpDiv64:
60 return rewriteValuegeneric_OpDiv64(v, config)
Cherry Zhang7d70f842016-07-06 10:04:45 -040061 case OpDiv64F:
62 return rewriteValuegeneric_OpDiv64F(v, config)
Keith Randalla3055af2016-02-05 20:26:18 -080063 case OpDiv64u:
64 return rewriteValuegeneric_OpDiv64u(v, config)
Alexandru Moșoi9b25da72015-07-31 12:32:22 +020065 case OpEq16:
Keith Randalla347ab72015-10-26 21:49:31 -070066 return rewriteValuegeneric_OpEq16(v, config)
Alexandru Moșoi9b25da72015-07-31 12:32:22 +020067 case OpEq32:
Keith Randalla347ab72015-10-26 21:49:31 -070068 return rewriteValuegeneric_OpEq32(v, config)
Alexandru Moșoi9b25da72015-07-31 12:32:22 +020069 case OpEq64:
Keith Randalla347ab72015-10-26 21:49:31 -070070 return rewriteValuegeneric_OpEq64(v, config)
Alexandru Moșoi9b25da72015-07-31 12:32:22 +020071 case OpEq8:
Keith Randalla347ab72015-10-26 21:49:31 -070072 return rewriteValuegeneric_OpEq8(v, config)
Alexandru Moșoi8b923972016-04-24 21:21:07 +020073 case OpEqB:
74 return rewriteValuegeneric_OpEqB(v, config)
Keith Randall1e4ebfd2015-09-10 13:53:27 -070075 case OpEqInter:
Keith Randalla347ab72015-10-26 21:49:31 -070076 return rewriteValuegeneric_OpEqInter(v, config)
Todd Nealec8a5972015-08-30 21:19:20 -050077 case OpEqPtr:
Keith Randalla347ab72015-10-26 21:49:31 -070078 return rewriteValuegeneric_OpEqPtr(v, config)
Keith Randall1e4ebfd2015-09-10 13:53:27 -070079 case OpEqSlice:
Keith Randalla347ab72015-10-26 21:49:31 -070080 return rewriteValuegeneric_OpEqSlice(v, config)
Todd Nealcdc36252015-10-27 17:46:53 -050081 case OpGeq16:
82 return rewriteValuegeneric_OpGeq16(v, config)
83 case OpGeq16U:
84 return rewriteValuegeneric_OpGeq16U(v, config)
85 case OpGeq32:
86 return rewriteValuegeneric_OpGeq32(v, config)
87 case OpGeq32U:
88 return rewriteValuegeneric_OpGeq32U(v, config)
89 case OpGeq64:
90 return rewriteValuegeneric_OpGeq64(v, config)
91 case OpGeq64U:
92 return rewriteValuegeneric_OpGeq64U(v, config)
93 case OpGeq8:
94 return rewriteValuegeneric_OpGeq8(v, config)
95 case OpGeq8U:
96 return rewriteValuegeneric_OpGeq8U(v, config)
97 case OpGreater16:
98 return rewriteValuegeneric_OpGreater16(v, config)
99 case OpGreater16U:
100 return rewriteValuegeneric_OpGreater16U(v, config)
101 case OpGreater32:
102 return rewriteValuegeneric_OpGreater32(v, config)
103 case OpGreater32U:
104 return rewriteValuegeneric_OpGreater32U(v, config)
105 case OpGreater64:
106 return rewriteValuegeneric_OpGreater64(v, config)
107 case OpGreater64U:
108 return rewriteValuegeneric_OpGreater64U(v, config)
109 case OpGreater8:
110 return rewriteValuegeneric_OpGreater8(v, config)
111 case OpGreater8U:
112 return rewriteValuegeneric_OpGreater8U(v, config)
Keith Randall0dca7352015-06-06 16:03:33 -0700113 case OpIsInBounds:
Keith Randalla347ab72015-10-26 21:49:31 -0700114 return rewriteValuegeneric_OpIsInBounds(v, config)
Keith Randall582baae2015-11-02 21:28:13 -0800115 case OpIsSliceInBounds:
116 return rewriteValuegeneric_OpIsSliceInBounds(v, config)
Todd Nealcdc36252015-10-27 17:46:53 -0500117 case OpLeq16:
118 return rewriteValuegeneric_OpLeq16(v, config)
119 case OpLeq16U:
120 return rewriteValuegeneric_OpLeq16U(v, config)
121 case OpLeq32:
122 return rewriteValuegeneric_OpLeq32(v, config)
123 case OpLeq32U:
124 return rewriteValuegeneric_OpLeq32U(v, config)
125 case OpLeq64:
126 return rewriteValuegeneric_OpLeq64(v, config)
127 case OpLeq64U:
128 return rewriteValuegeneric_OpLeq64U(v, config)
129 case OpLeq8:
130 return rewriteValuegeneric_OpLeq8(v, config)
131 case OpLeq8U:
132 return rewriteValuegeneric_OpLeq8U(v, config)
133 case OpLess16:
134 return rewriteValuegeneric_OpLess16(v, config)
135 case OpLess16U:
136 return rewriteValuegeneric_OpLess16U(v, config)
137 case OpLess32:
138 return rewriteValuegeneric_OpLess32(v, config)
139 case OpLess32U:
140 return rewriteValuegeneric_OpLess32U(v, config)
141 case OpLess64:
142 return rewriteValuegeneric_OpLess64(v, config)
143 case OpLess64U:
144 return rewriteValuegeneric_OpLess64U(v, config)
145 case OpLess8:
146 return rewriteValuegeneric_OpLess8(v, config)
147 case OpLess8U:
148 return rewriteValuegeneric_OpLess8U(v, config)
Keith Randall0dca7352015-06-06 16:03:33 -0700149 case OpLoad:
Keith Randalla347ab72015-10-26 21:49:31 -0700150 return rewriteValuegeneric_OpLoad(v, config)
Todd Neal93a0b0f2016-02-03 06:21:24 -0500151 case OpLsh16x16:
152 return rewriteValuegeneric_OpLsh16x16(v, config)
153 case OpLsh16x32:
154 return rewriteValuegeneric_OpLsh16x32(v, config)
155 case OpLsh16x64:
156 return rewriteValuegeneric_OpLsh16x64(v, config)
157 case OpLsh16x8:
158 return rewriteValuegeneric_OpLsh16x8(v, config)
159 case OpLsh32x16:
160 return rewriteValuegeneric_OpLsh32x16(v, config)
161 case OpLsh32x32:
162 return rewriteValuegeneric_OpLsh32x32(v, config)
163 case OpLsh32x64:
164 return rewriteValuegeneric_OpLsh32x64(v, config)
165 case OpLsh32x8:
166 return rewriteValuegeneric_OpLsh32x8(v, config)
167 case OpLsh64x16:
168 return rewriteValuegeneric_OpLsh64x16(v, config)
169 case OpLsh64x32:
170 return rewriteValuegeneric_OpLsh64x32(v, config)
171 case OpLsh64x64:
172 return rewriteValuegeneric_OpLsh64x64(v, config)
173 case OpLsh64x8:
174 return rewriteValuegeneric_OpLsh64x8(v, config)
175 case OpLsh8x16:
176 return rewriteValuegeneric_OpLsh8x16(v, config)
177 case OpLsh8x32:
178 return rewriteValuegeneric_OpLsh8x32(v, config)
179 case OpLsh8x64:
180 return rewriteValuegeneric_OpLsh8x64(v, config)
181 case OpLsh8x8:
182 return rewriteValuegeneric_OpLsh8x8(v, config)
Alexandru Moșoi060501d2016-04-04 16:13:35 +0200183 case OpMod16:
184 return rewriteValuegeneric_OpMod16(v, config)
185 case OpMod16u:
186 return rewriteValuegeneric_OpMod16u(v, config)
187 case OpMod32:
188 return rewriteValuegeneric_OpMod32(v, config)
189 case OpMod32u:
190 return rewriteValuegeneric_OpMod32u(v, config)
Keith Randalla3055af2016-02-05 20:26:18 -0800191 case OpMod64:
192 return rewriteValuegeneric_OpMod64(v, config)
193 case OpMod64u:
194 return rewriteValuegeneric_OpMod64u(v, config)
Alexandru Moșoi060501d2016-04-04 16:13:35 +0200195 case OpMod8:
196 return rewriteValuegeneric_OpMod8(v, config)
197 case OpMod8u:
198 return rewriteValuegeneric_OpMod8u(v, config)
Keith Randall582baae2015-11-02 21:28:13 -0800199 case OpMul16:
200 return rewriteValuegeneric_OpMul16(v, config)
201 case OpMul32:
202 return rewriteValuegeneric_OpMul32(v, config)
Todd Nealf6ceed22016-03-11 19:36:54 -0600203 case OpMul32F:
204 return rewriteValuegeneric_OpMul32F(v, config)
Keith Randallbe1eb572015-07-22 13:46:15 -0700205 case OpMul64:
Keith Randalla347ab72015-10-26 21:49:31 -0700206 return rewriteValuegeneric_OpMul64(v, config)
Todd Nealf6ceed22016-03-11 19:36:54 -0600207 case OpMul64F:
208 return rewriteValuegeneric_OpMul64F(v, config)
Keith Randall582baae2015-11-02 21:28:13 -0800209 case OpMul8:
210 return rewriteValuegeneric_OpMul8(v, config)
Alexandru Moșoi964dda92016-02-08 18:55:56 +0100211 case OpNeg16:
212 return rewriteValuegeneric_OpNeg16(v, config)
213 case OpNeg32:
214 return rewriteValuegeneric_OpNeg32(v, config)
215 case OpNeg64:
216 return rewriteValuegeneric_OpNeg64(v, config)
217 case OpNeg8:
218 return rewriteValuegeneric_OpNeg8(v, config)
Alexandru Moșoi9b25da72015-07-31 12:32:22 +0200219 case OpNeq16:
Keith Randalla347ab72015-10-26 21:49:31 -0700220 return rewriteValuegeneric_OpNeq16(v, config)
Alexandru Moșoi9b25da72015-07-31 12:32:22 +0200221 case OpNeq32:
Keith Randalla347ab72015-10-26 21:49:31 -0700222 return rewriteValuegeneric_OpNeq32(v, config)
Alexandru Moșoi9b25da72015-07-31 12:32:22 +0200223 case OpNeq64:
Keith Randalla347ab72015-10-26 21:49:31 -0700224 return rewriteValuegeneric_OpNeq64(v, config)
Alexandru Moșoi9b25da72015-07-31 12:32:22 +0200225 case OpNeq8:
Keith Randalla347ab72015-10-26 21:49:31 -0700226 return rewriteValuegeneric_OpNeq8(v, config)
Alexandru Moșoi8b923972016-04-24 21:21:07 +0200227 case OpNeqB:
228 return rewriteValuegeneric_OpNeqB(v, config)
Keith Randall1e4ebfd2015-09-10 13:53:27 -0700229 case OpNeqInter:
Keith Randalla347ab72015-10-26 21:49:31 -0700230 return rewriteValuegeneric_OpNeqInter(v, config)
Todd Nealec8a5972015-08-30 21:19:20 -0500231 case OpNeqPtr:
Keith Randalla347ab72015-10-26 21:49:31 -0700232 return rewriteValuegeneric_OpNeqPtr(v, config)
Keith Randall1e4ebfd2015-09-10 13:53:27 -0700233 case OpNeqSlice:
Keith Randalla347ab72015-10-26 21:49:31 -0700234 return rewriteValuegeneric_OpNeqSlice(v, config)
Keith Randall3134ab32016-09-13 17:01:01 -0700235 case OpNilCheck:
236 return rewriteValuegeneric_OpNilCheck(v, config)
Martin Möhrmann00459f052016-08-31 12:37:19 +0200237 case OpNot:
238 return rewriteValuegeneric_OpNot(v, config)
Josh Bleecher Snyder32940142016-03-04 14:12:44 -0800239 case OpOffPtr:
240 return rewriteValuegeneric_OpOffPtr(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200241 case OpOr16:
Keith Randalla347ab72015-10-26 21:49:31 -0700242 return rewriteValuegeneric_OpOr16(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200243 case OpOr32:
Keith Randalla347ab72015-10-26 21:49:31 -0700244 return rewriteValuegeneric_OpOr32(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200245 case OpOr64:
Keith Randalla347ab72015-10-26 21:49:31 -0700246 return rewriteValuegeneric_OpOr64(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200247 case OpOr8:
Keith Randalla347ab72015-10-26 21:49:31 -0700248 return rewriteValuegeneric_OpOr8(v, config)
Alexandru Moșoid0d04d22016-02-09 19:46:26 +0100249 case OpPhi:
250 return rewriteValuegeneric_OpPhi(v, config)
Keith Randall0dca7352015-06-06 16:03:33 -0700251 case OpPtrIndex:
Keith Randalla347ab72015-10-26 21:49:31 -0700252 return rewriteValuegeneric_OpPtrIndex(v, config)
Todd Neal93a0b0f2016-02-03 06:21:24 -0500253 case OpRsh16Ux16:
254 return rewriteValuegeneric_OpRsh16Ux16(v, config)
255 case OpRsh16Ux32:
256 return rewriteValuegeneric_OpRsh16Ux32(v, config)
257 case OpRsh16Ux64:
258 return rewriteValuegeneric_OpRsh16Ux64(v, config)
259 case OpRsh16Ux8:
260 return rewriteValuegeneric_OpRsh16Ux8(v, config)
261 case OpRsh16x16:
262 return rewriteValuegeneric_OpRsh16x16(v, config)
263 case OpRsh16x32:
264 return rewriteValuegeneric_OpRsh16x32(v, config)
265 case OpRsh16x64:
266 return rewriteValuegeneric_OpRsh16x64(v, config)
267 case OpRsh16x8:
268 return rewriteValuegeneric_OpRsh16x8(v, config)
269 case OpRsh32Ux16:
270 return rewriteValuegeneric_OpRsh32Ux16(v, config)
271 case OpRsh32Ux32:
272 return rewriteValuegeneric_OpRsh32Ux32(v, config)
273 case OpRsh32Ux64:
274 return rewriteValuegeneric_OpRsh32Ux64(v, config)
275 case OpRsh32Ux8:
276 return rewriteValuegeneric_OpRsh32Ux8(v, config)
277 case OpRsh32x16:
278 return rewriteValuegeneric_OpRsh32x16(v, config)
279 case OpRsh32x32:
280 return rewriteValuegeneric_OpRsh32x32(v, config)
281 case OpRsh32x64:
282 return rewriteValuegeneric_OpRsh32x64(v, config)
283 case OpRsh32x8:
284 return rewriteValuegeneric_OpRsh32x8(v, config)
285 case OpRsh64Ux16:
286 return rewriteValuegeneric_OpRsh64Ux16(v, config)
287 case OpRsh64Ux32:
288 return rewriteValuegeneric_OpRsh64Ux32(v, config)
289 case OpRsh64Ux64:
290 return rewriteValuegeneric_OpRsh64Ux64(v, config)
291 case OpRsh64Ux8:
292 return rewriteValuegeneric_OpRsh64Ux8(v, config)
293 case OpRsh64x16:
294 return rewriteValuegeneric_OpRsh64x16(v, config)
295 case OpRsh64x32:
296 return rewriteValuegeneric_OpRsh64x32(v, config)
297 case OpRsh64x64:
298 return rewriteValuegeneric_OpRsh64x64(v, config)
299 case OpRsh64x8:
300 return rewriteValuegeneric_OpRsh64x8(v, config)
301 case OpRsh8Ux16:
302 return rewriteValuegeneric_OpRsh8Ux16(v, config)
303 case OpRsh8Ux32:
304 return rewriteValuegeneric_OpRsh8Ux32(v, config)
305 case OpRsh8Ux64:
306 return rewriteValuegeneric_OpRsh8Ux64(v, config)
307 case OpRsh8Ux8:
308 return rewriteValuegeneric_OpRsh8Ux8(v, config)
309 case OpRsh8x16:
310 return rewriteValuegeneric_OpRsh8x16(v, config)
311 case OpRsh8x32:
312 return rewriteValuegeneric_OpRsh8x32(v, config)
313 case OpRsh8x64:
314 return rewriteValuegeneric_OpRsh8x64(v, config)
315 case OpRsh8x8:
316 return rewriteValuegeneric_OpRsh8x8(v, config)
Keith Randall0dca7352015-06-06 16:03:33 -0700317 case OpSliceCap:
Keith Randalla347ab72015-10-26 21:49:31 -0700318 return rewriteValuegeneric_OpSliceCap(v, config)
Keith Randall0dca7352015-06-06 16:03:33 -0700319 case OpSliceLen:
Keith Randalla347ab72015-10-26 21:49:31 -0700320 return rewriteValuegeneric_OpSliceLen(v, config)
Keith Randall0dca7352015-06-06 16:03:33 -0700321 case OpSlicePtr:
Keith Randalla347ab72015-10-26 21:49:31 -0700322 return rewriteValuegeneric_OpSlicePtr(v, config)
Kevin Burke8e24a982016-08-20 22:05:47 -0700323 case OpSqrt:
324 return rewriteValuegeneric_OpSqrt(v, config)
Keith Randall0dca7352015-06-06 16:03:33 -0700325 case OpStore:
Keith Randalla347ab72015-10-26 21:49:31 -0700326 return rewriteValuegeneric_OpStore(v, config)
Keith Randall0dca7352015-06-06 16:03:33 -0700327 case OpStringLen:
Keith Randalla347ab72015-10-26 21:49:31 -0700328 return rewriteValuegeneric_OpStringLen(v, config)
Keith Randall0dca7352015-06-06 16:03:33 -0700329 case OpStringPtr:
Keith Randalla347ab72015-10-26 21:49:31 -0700330 return rewriteValuegeneric_OpStringPtr(v, config)
Keith Randallcd7e0592015-07-15 21:33:49 -0700331 case OpStructSelect:
Keith Randalla347ab72015-10-26 21:49:31 -0700332 return rewriteValuegeneric_OpStructSelect(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200333 case OpSub16:
Keith Randalla347ab72015-10-26 21:49:31 -0700334 return rewriteValuegeneric_OpSub16(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200335 case OpSub32:
Keith Randalla347ab72015-10-26 21:49:31 -0700336 return rewriteValuegeneric_OpSub32(v, config)
Todd Nealf6ceed22016-03-11 19:36:54 -0600337 case OpSub32F:
338 return rewriteValuegeneric_OpSub32F(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200339 case OpSub64:
Keith Randalla347ab72015-10-26 21:49:31 -0700340 return rewriteValuegeneric_OpSub64(v, config)
Todd Nealf6ceed22016-03-11 19:36:54 -0600341 case OpSub64F:
342 return rewriteValuegeneric_OpSub64F(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200343 case OpSub8:
Keith Randalla347ab72015-10-26 21:49:31 -0700344 return rewriteValuegeneric_OpSub8(v, config)
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +0100345 case OpTrunc16to8:
346 return rewriteValuegeneric_OpTrunc16to8(v, config)
347 case OpTrunc32to16:
348 return rewriteValuegeneric_OpTrunc32to16(v, config)
349 case OpTrunc32to8:
350 return rewriteValuegeneric_OpTrunc32to8(v, config)
351 case OpTrunc64to16:
352 return rewriteValuegeneric_OpTrunc64to16(v, config)
353 case OpTrunc64to32:
354 return rewriteValuegeneric_OpTrunc64to32(v, config)
355 case OpTrunc64to8:
356 return rewriteValuegeneric_OpTrunc64to8(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200357 case OpXor16:
Keith Randalla347ab72015-10-26 21:49:31 -0700358 return rewriteValuegeneric_OpXor16(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200359 case OpXor32:
Keith Randalla347ab72015-10-26 21:49:31 -0700360 return rewriteValuegeneric_OpXor32(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200361 case OpXor64:
Keith Randalla347ab72015-10-26 21:49:31 -0700362 return rewriteValuegeneric_OpXor64(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200363 case OpXor8:
Keith Randalla347ab72015-10-26 21:49:31 -0700364 return rewriteValuegeneric_OpXor8(v, config)
Cherry Zhangb2e0e962016-08-26 15:41:51 -0400365 case OpZero:
366 return rewriteValuegeneric_OpZero(v, config)
Keith Randall0dca7352015-06-06 16:03:33 -0700367 }
368 return false
369}
Keith Randall582baae2015-11-02 21:28:13 -0800370func rewriteValuegeneric_OpAdd16(v *Value, config *Config) bool {
371 b := v.Block
372 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -0700373 // match: (Add16 (Const16 [c]) (Const16 [d]))
Keith Randall582baae2015-11-02 21:28:13 -0800374 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -0700375 // result: (Const16 [int64(int16(c+d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +0100376 for {
Keith Randall259b7ed2016-03-21 16:18:45 -0700377 v_0 := v.Args[0]
378 if v_0.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100379 break
Keith Randall582baae2015-11-02 21:28:13 -0800380 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700381 c := v_0.AuxInt
382 v_1 := v.Args[1]
383 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100384 break
Keith Randall582baae2015-11-02 21:28:13 -0800385 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700386 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100387 v.reset(OpConst16)
Keith Randall7fc56212016-03-29 16:39:53 -0700388 v.AuxInt = int64(int16(c + d))
Keith Randall582baae2015-11-02 21:28:13 -0800389 return true
390 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100391 // match: (Add16 x (Const16 <t> [c]))
392 // cond: x.Op != OpConst16
393 // result: (Add16 (Const16 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +0100394 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100395 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -0700396 v_1 := v.Args[1]
397 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100398 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100399 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700400 t := v_1.Type
401 c := v_1.AuxInt
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100402 if !(x.Op != OpConst16) {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100403 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100404 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100405 v.reset(OpAdd16)
Todd Neal93a0b0f2016-02-03 06:21:24 -0500406 v0 := b.NewValue0(v.Line, OpConst16, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100407 v0.AuxInt = c
408 v.AddArg(v0)
409 v.AddArg(x)
410 return true
411 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100412 // match: (Add16 (Const16 [0]) x)
413 // cond:
414 // result: x
415 for {
Keith Randall259b7ed2016-03-21 16:18:45 -0700416 v_0 := v.Args[0]
417 if v_0.Op != OpConst16 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100418 break
419 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700420 if v_0.AuxInt != 0 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100421 break
422 }
423 x := v.Args[1]
424 v.reset(OpCopy)
425 v.Type = x.Type
426 v.AddArg(x)
427 return true
428 }
Keith Randall582baae2015-11-02 21:28:13 -0800429 return false
430}
431func rewriteValuegeneric_OpAdd32(v *Value, config *Config) bool {
432 b := v.Block
433 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -0700434 // match: (Add32 (Const32 [c]) (Const32 [d]))
Keith Randall582baae2015-11-02 21:28:13 -0800435 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -0700436 // result: (Const32 [int64(int32(c+d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +0100437 for {
Keith Randall259b7ed2016-03-21 16:18:45 -0700438 v_0 := v.Args[0]
439 if v_0.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100440 break
Keith Randall582baae2015-11-02 21:28:13 -0800441 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700442 c := v_0.AuxInt
443 v_1 := v.Args[1]
444 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100445 break
Keith Randall582baae2015-11-02 21:28:13 -0800446 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700447 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100448 v.reset(OpConst32)
Keith Randall7fc56212016-03-29 16:39:53 -0700449 v.AuxInt = int64(int32(c + d))
Keith Randall582baae2015-11-02 21:28:13 -0800450 return true
451 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100452 // match: (Add32 x (Const32 <t> [c]))
453 // cond: x.Op != OpConst32
454 // result: (Add32 (Const32 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +0100455 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100456 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -0700457 v_1 := v.Args[1]
458 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100459 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100460 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700461 t := v_1.Type
462 c := v_1.AuxInt
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100463 if !(x.Op != OpConst32) {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100464 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100465 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100466 v.reset(OpAdd32)
Todd Neal93a0b0f2016-02-03 06:21:24 -0500467 v0 := b.NewValue0(v.Line, OpConst32, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100468 v0.AuxInt = c
469 v.AddArg(v0)
470 v.AddArg(x)
471 return true
472 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100473 // match: (Add32 (Const32 [0]) x)
474 // cond:
475 // result: x
476 for {
Keith Randall259b7ed2016-03-21 16:18:45 -0700477 v_0 := v.Args[0]
478 if v_0.Op != OpConst32 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100479 break
480 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700481 if v_0.AuxInt != 0 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100482 break
483 }
484 x := v.Args[1]
485 v.reset(OpCopy)
486 v.Type = x.Type
487 v.AddArg(x)
488 return true
489 }
Keith Randall582baae2015-11-02 21:28:13 -0800490 return false
491}
Todd Nealf6ceed22016-03-11 19:36:54 -0600492func rewriteValuegeneric_OpAdd32F(v *Value, config *Config) bool {
493 b := v.Block
494 _ = b
495 // match: (Add32F (Const32F [c]) (Const32F [d]))
496 // cond:
497 // result: (Const32F [f2i(float64(i2f32(c) + i2f32(d)))])
498 for {
Keith Randall259b7ed2016-03-21 16:18:45 -0700499 v_0 := v.Args[0]
500 if v_0.Op != OpConst32F {
Todd Nealf6ceed22016-03-11 19:36:54 -0600501 break
502 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700503 c := v_0.AuxInt
504 v_1 := v.Args[1]
505 if v_1.Op != OpConst32F {
Todd Nealf6ceed22016-03-11 19:36:54 -0600506 break
507 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700508 d := v_1.AuxInt
Todd Nealf6ceed22016-03-11 19:36:54 -0600509 v.reset(OpConst32F)
510 v.AuxInt = f2i(float64(i2f32(c) + i2f32(d)))
511 return true
512 }
Cherry Zhang7d70f842016-07-06 10:04:45 -0400513 // match: (Add32F x (Const32F [0]))
514 // cond:
515 // result: x
516 for {
517 x := v.Args[0]
518 v_1 := v.Args[1]
519 if v_1.Op != OpConst32F {
520 break
521 }
522 if v_1.AuxInt != 0 {
523 break
524 }
525 v.reset(OpCopy)
526 v.Type = x.Type
527 v.AddArg(x)
528 return true
529 }
530 // match: (Add32F (Const32F [0]) x)
531 // cond:
532 // result: x
533 for {
534 v_0 := v.Args[0]
535 if v_0.Op != OpConst32F {
536 break
537 }
538 if v_0.AuxInt != 0 {
539 break
540 }
541 x := v.Args[1]
542 v.reset(OpCopy)
543 v.Type = x.Type
544 v.AddArg(x)
545 return true
546 }
Todd Nealf6ceed22016-03-11 19:36:54 -0600547 return false
548}
Keith Randalla347ab72015-10-26 21:49:31 -0700549func rewriteValuegeneric_OpAdd64(v *Value, config *Config) bool {
550 b := v.Block
551 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -0700552 // match: (Add64 (Const64 [c]) (Const64 [d]))
Keith Randalla347ab72015-10-26 21:49:31 -0700553 // cond:
554 // result: (Const64 [c+d])
Alexandru Moșoi05434472016-02-04 19:52:10 +0100555 for {
Keith Randall259b7ed2016-03-21 16:18:45 -0700556 v_0 := v.Args[0]
557 if v_0.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100558 break
Keith Randalla347ab72015-10-26 21:49:31 -0700559 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700560 c := v_0.AuxInt
561 v_1 := v.Args[1]
562 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100563 break
Keith Randalla347ab72015-10-26 21:49:31 -0700564 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700565 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100566 v.reset(OpConst64)
Keith Randalla347ab72015-10-26 21:49:31 -0700567 v.AuxInt = c + d
568 return true
569 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100570 // match: (Add64 x (Const64 <t> [c]))
571 // cond: x.Op != OpConst64
572 // result: (Add64 (Const64 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +0100573 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100574 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -0700575 v_1 := v.Args[1]
576 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100577 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100578 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700579 t := v_1.Type
580 c := v_1.AuxInt
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100581 if !(x.Op != OpConst64) {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100582 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100583 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100584 v.reset(OpAdd64)
Todd Neal93a0b0f2016-02-03 06:21:24 -0500585 v0 := b.NewValue0(v.Line, OpConst64, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100586 v0.AuxInt = c
587 v.AddArg(v0)
588 v.AddArg(x)
589 return true
590 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100591 // match: (Add64 (Const64 [0]) x)
592 // cond:
593 // result: x
594 for {
Keith Randall259b7ed2016-03-21 16:18:45 -0700595 v_0 := v.Args[0]
596 if v_0.Op != OpConst64 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100597 break
598 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700599 if v_0.AuxInt != 0 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100600 break
601 }
602 x := v.Args[1]
603 v.reset(OpCopy)
604 v.Type = x.Type
605 v.AddArg(x)
606 return true
607 }
Keith Randalla347ab72015-10-26 21:49:31 -0700608 return false
609}
Todd Nealf6ceed22016-03-11 19:36:54 -0600610func rewriteValuegeneric_OpAdd64F(v *Value, config *Config) bool {
611 b := v.Block
612 _ = b
613 // match: (Add64F (Const64F [c]) (Const64F [d]))
614 // cond:
615 // result: (Const64F [f2i(i2f(c) + i2f(d))])
616 for {
Keith Randall259b7ed2016-03-21 16:18:45 -0700617 v_0 := v.Args[0]
618 if v_0.Op != OpConst64F {
Todd Nealf6ceed22016-03-11 19:36:54 -0600619 break
620 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700621 c := v_0.AuxInt
622 v_1 := v.Args[1]
623 if v_1.Op != OpConst64F {
Todd Nealf6ceed22016-03-11 19:36:54 -0600624 break
625 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700626 d := v_1.AuxInt
Todd Nealf6ceed22016-03-11 19:36:54 -0600627 v.reset(OpConst64F)
628 v.AuxInt = f2i(i2f(c) + i2f(d))
629 return true
630 }
Cherry Zhang7d70f842016-07-06 10:04:45 -0400631 // match: (Add64F x (Const64F [0]))
632 // cond:
633 // result: x
634 for {
635 x := v.Args[0]
636 v_1 := v.Args[1]
637 if v_1.Op != OpConst64F {
638 break
639 }
640 if v_1.AuxInt != 0 {
641 break
642 }
643 v.reset(OpCopy)
644 v.Type = x.Type
645 v.AddArg(x)
646 return true
647 }
648 // match: (Add64F (Const64F [0]) x)
649 // cond:
650 // result: x
651 for {
652 v_0 := v.Args[0]
653 if v_0.Op != OpConst64F {
654 break
655 }
656 if v_0.AuxInt != 0 {
657 break
658 }
659 x := v.Args[1]
660 v.reset(OpCopy)
661 v.Type = x.Type
662 v.AddArg(x)
663 return true
664 }
Todd Nealf6ceed22016-03-11 19:36:54 -0600665 return false
666}
Keith Randall582baae2015-11-02 21:28:13 -0800667func rewriteValuegeneric_OpAdd8(v *Value, config *Config) bool {
Keith Randalla347ab72015-10-26 21:49:31 -0700668 b := v.Block
669 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -0700670 // match: (Add8 (Const8 [c]) (Const8 [d]))
Keith Randalla347ab72015-10-26 21:49:31 -0700671 // cond:
Keith Randallfa9435c2016-04-26 12:08:31 -0700672 // result: (Const8 [int64(int8(c+d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +0100673 for {
Keith Randall259b7ed2016-03-21 16:18:45 -0700674 v_0 := v.Args[0]
675 if v_0.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100676 break
Keith Randalla347ab72015-10-26 21:49:31 -0700677 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700678 c := v_0.AuxInt
679 v_1 := v.Args[1]
680 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100681 break
Keith Randalla347ab72015-10-26 21:49:31 -0700682 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700683 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100684 v.reset(OpConst8)
Keith Randall7fc56212016-03-29 16:39:53 -0700685 v.AuxInt = int64(int8(c + d))
Keith Randalla347ab72015-10-26 21:49:31 -0700686 return true
687 }
Keith Randallfa9435c2016-04-26 12:08:31 -0700688 // match: (Add8 x (Const8 <t> [c]))
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100689 // cond: x.Op != OpConst8
Keith Randallfa9435c2016-04-26 12:08:31 -0700690 // result: (Add8 (Const8 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +0100691 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100692 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -0700693 v_1 := v.Args[1]
694 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100695 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100696 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700697 t := v_1.Type
698 c := v_1.AuxInt
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100699 if !(x.Op != OpConst8) {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100700 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100701 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100702 v.reset(OpAdd8)
Todd Neal93a0b0f2016-02-03 06:21:24 -0500703 v0 := b.NewValue0(v.Line, OpConst8, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100704 v0.AuxInt = c
705 v.AddArg(v0)
706 v.AddArg(x)
707 return true
708 }
Keith Randallfa9435c2016-04-26 12:08:31 -0700709 // match: (Add8 (Const8 [0]) x)
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100710 // cond:
711 // result: x
712 for {
Keith Randall259b7ed2016-03-21 16:18:45 -0700713 v_0 := v.Args[0]
714 if v_0.Op != OpConst8 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100715 break
716 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700717 if v_0.AuxInt != 0 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100718 break
719 }
720 x := v.Args[1]
721 v.reset(OpCopy)
722 v.Type = x.Type
723 v.AddArg(x)
724 return true
725 }
Keith Randalla347ab72015-10-26 21:49:31 -0700726 return false
727}
Alexandru Moșoia7a19992016-03-18 10:50:00 +0100728func rewriteValuegeneric_OpAddPtr(v *Value, config *Config) bool {
729 b := v.Block
730 _ = b
731 // match: (AddPtr <t> x (Const64 [c]))
732 // cond:
733 // result: (OffPtr <t> x [c])
734 for {
735 t := v.Type
736 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -0700737 v_1 := v.Args[1]
738 if v_1.Op != OpConst64 {
Alexandru Moșoia7a19992016-03-18 10:50:00 +0100739 break
740 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700741 c := v_1.AuxInt
Alexandru Moșoia7a19992016-03-18 10:50:00 +0100742 v.reset(OpOffPtr)
743 v.Type = t
Alexandru Moșoia7a19992016-03-18 10:50:00 +0100744 v.AuxInt = c
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -0700745 v.AddArg(x)
Alexandru Moșoia7a19992016-03-18 10:50:00 +0100746 return true
747 }
748 return false
749}
Keith Randalla347ab72015-10-26 21:49:31 -0700750func rewriteValuegeneric_OpAnd16(v *Value, config *Config) bool {
751 b := v.Block
752 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100753 // match: (And16 x (Const16 <t> [c]))
754 // cond: x.Op != OpConst16
755 // result: (And16 (Const16 <t> [c]) x)
756 for {
757 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -0700758 v_1 := v.Args[1]
759 if v_1.Op != OpConst16 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100760 break
761 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700762 t := v_1.Type
763 c := v_1.AuxInt
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100764 if !(x.Op != OpConst16) {
765 break
766 }
767 v.reset(OpAnd16)
768 v0 := b.NewValue0(v.Line, OpConst16, t)
769 v0.AuxInt = c
770 v.AddArg(v0)
771 v.AddArg(x)
772 return true
773 }
Keith Randalla347ab72015-10-26 21:49:31 -0700774 // match: (And16 x x)
775 // cond:
776 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +0100777 for {
Keith Randalla347ab72015-10-26 21:49:31 -0700778 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -0700779 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100780 break
Keith Randalla347ab72015-10-26 21:49:31 -0700781 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100782 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -0700783 v.Type = x.Type
784 v.AddArg(x)
785 return true
786 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100787 // match: (And16 (Const16 [-1]) x)
788 // cond:
789 // result: x
790 for {
Keith Randall259b7ed2016-03-21 16:18:45 -0700791 v_0 := v.Args[0]
792 if v_0.Op != OpConst16 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100793 break
794 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700795 if v_0.AuxInt != -1 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100796 break
797 }
798 x := v.Args[1]
799 v.reset(OpCopy)
800 v.Type = x.Type
801 v.AddArg(x)
802 return true
803 }
804 // match: (And16 (Const16 [0]) _)
805 // cond:
806 // result: (Const16 [0])
807 for {
Keith Randall259b7ed2016-03-21 16:18:45 -0700808 v_0 := v.Args[0]
809 if v_0.Op != OpConst16 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100810 break
811 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700812 if v_0.AuxInt != 0 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100813 break
814 }
815 v.reset(OpConst16)
816 v.AuxInt = 0
817 return true
818 }
Keith Randall4d5adf12016-04-18 09:28:50 -0700819 // match: (And16 x (And16 x y))
820 // cond:
821 // result: (And16 x y)
822 for {
823 x := v.Args[0]
824 v_1 := v.Args[1]
825 if v_1.Op != OpAnd16 {
826 break
827 }
828 if x != v_1.Args[0] {
829 break
830 }
831 y := v_1.Args[1]
832 v.reset(OpAnd16)
833 v.AddArg(x)
834 v.AddArg(y)
835 return true
836 }
837 // match: (And16 x (And16 y x))
838 // cond:
839 // result: (And16 x y)
840 for {
841 x := v.Args[0]
842 v_1 := v.Args[1]
843 if v_1.Op != OpAnd16 {
844 break
845 }
846 y := v_1.Args[0]
847 if x != v_1.Args[1] {
848 break
849 }
850 v.reset(OpAnd16)
851 v.AddArg(x)
852 v.AddArg(y)
853 return true
854 }
855 // match: (And16 (And16 x y) x)
856 // cond:
857 // result: (And16 x y)
858 for {
859 v_0 := v.Args[0]
860 if v_0.Op != OpAnd16 {
861 break
862 }
863 x := v_0.Args[0]
864 y := v_0.Args[1]
865 if x != v.Args[1] {
866 break
867 }
868 v.reset(OpAnd16)
869 v.AddArg(x)
870 v.AddArg(y)
871 return true
872 }
873 // match: (And16 (And16 x y) y)
874 // cond:
875 // result: (And16 x y)
876 for {
877 v_0 := v.Args[0]
878 if v_0.Op != OpAnd16 {
879 break
880 }
881 x := v_0.Args[0]
882 y := v_0.Args[1]
883 if y != v.Args[1] {
884 break
885 }
886 v.reset(OpAnd16)
887 v.AddArg(x)
888 v.AddArg(y)
889 return true
890 }
Keith Randalla347ab72015-10-26 21:49:31 -0700891 return false
892}
893func rewriteValuegeneric_OpAnd32(v *Value, config *Config) bool {
894 b := v.Block
895 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100896 // match: (And32 x (Const32 <t> [c]))
897 // cond: x.Op != OpConst32
898 // result: (And32 (Const32 <t> [c]) x)
899 for {
900 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -0700901 v_1 := v.Args[1]
902 if v_1.Op != OpConst32 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100903 break
904 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700905 t := v_1.Type
906 c := v_1.AuxInt
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100907 if !(x.Op != OpConst32) {
908 break
909 }
910 v.reset(OpAnd32)
911 v0 := b.NewValue0(v.Line, OpConst32, t)
912 v0.AuxInt = c
913 v.AddArg(v0)
914 v.AddArg(x)
915 return true
916 }
Keith Randalla347ab72015-10-26 21:49:31 -0700917 // match: (And32 x x)
918 // cond:
919 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +0100920 for {
Keith Randalla347ab72015-10-26 21:49:31 -0700921 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -0700922 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100923 break
Keith Randalla347ab72015-10-26 21:49:31 -0700924 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100925 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -0700926 v.Type = x.Type
927 v.AddArg(x)
928 return true
929 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100930 // match: (And32 (Const32 [-1]) x)
931 // cond:
932 // result: x
933 for {
Keith Randall259b7ed2016-03-21 16:18:45 -0700934 v_0 := v.Args[0]
935 if v_0.Op != OpConst32 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100936 break
937 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700938 if v_0.AuxInt != -1 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100939 break
940 }
941 x := v.Args[1]
942 v.reset(OpCopy)
943 v.Type = x.Type
944 v.AddArg(x)
945 return true
946 }
947 // match: (And32 (Const32 [0]) _)
948 // cond:
949 // result: (Const32 [0])
950 for {
Keith Randall259b7ed2016-03-21 16:18:45 -0700951 v_0 := v.Args[0]
952 if v_0.Op != OpConst32 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100953 break
954 }
Keith Randall259b7ed2016-03-21 16:18:45 -0700955 if v_0.AuxInt != 0 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100956 break
957 }
958 v.reset(OpConst32)
959 v.AuxInt = 0
960 return true
961 }
Keith Randall4d5adf12016-04-18 09:28:50 -0700962 // match: (And32 x (And32 x y))
963 // cond:
964 // result: (And32 x y)
965 for {
966 x := v.Args[0]
967 v_1 := v.Args[1]
968 if v_1.Op != OpAnd32 {
969 break
970 }
971 if x != v_1.Args[0] {
972 break
973 }
974 y := v_1.Args[1]
975 v.reset(OpAnd32)
976 v.AddArg(x)
977 v.AddArg(y)
978 return true
979 }
980 // match: (And32 x (And32 y x))
981 // cond:
982 // result: (And32 x y)
983 for {
984 x := v.Args[0]
985 v_1 := v.Args[1]
986 if v_1.Op != OpAnd32 {
987 break
988 }
989 y := v_1.Args[0]
990 if x != v_1.Args[1] {
991 break
992 }
993 v.reset(OpAnd32)
994 v.AddArg(x)
995 v.AddArg(y)
996 return true
997 }
998 // match: (And32 (And32 x y) x)
999 // cond:
1000 // result: (And32 x y)
1001 for {
1002 v_0 := v.Args[0]
1003 if v_0.Op != OpAnd32 {
1004 break
1005 }
1006 x := v_0.Args[0]
1007 y := v_0.Args[1]
1008 if x != v.Args[1] {
1009 break
1010 }
1011 v.reset(OpAnd32)
1012 v.AddArg(x)
1013 v.AddArg(y)
1014 return true
1015 }
1016 // match: (And32 (And32 x y) y)
1017 // cond:
1018 // result: (And32 x y)
1019 for {
1020 v_0 := v.Args[0]
1021 if v_0.Op != OpAnd32 {
1022 break
1023 }
1024 x := v_0.Args[0]
1025 y := v_0.Args[1]
1026 if y != v.Args[1] {
1027 break
1028 }
1029 v.reset(OpAnd32)
1030 v.AddArg(x)
1031 v.AddArg(y)
1032 return true
1033 }
Keith Randalla347ab72015-10-26 21:49:31 -07001034 return false
1035}
1036func rewriteValuegeneric_OpAnd64(v *Value, config *Config) bool {
1037 b := v.Block
1038 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01001039 // match: (And64 x (Const64 <t> [c]))
1040 // cond: x.Op != OpConst64
1041 // result: (And64 (Const64 <t> [c]) x)
1042 for {
1043 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07001044 v_1 := v.Args[1]
1045 if v_1.Op != OpConst64 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01001046 break
1047 }
Keith Randall259b7ed2016-03-21 16:18:45 -07001048 t := v_1.Type
1049 c := v_1.AuxInt
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01001050 if !(x.Op != OpConst64) {
1051 break
1052 }
1053 v.reset(OpAnd64)
1054 v0 := b.NewValue0(v.Line, OpConst64, t)
1055 v0.AuxInt = c
1056 v.AddArg(v0)
1057 v.AddArg(x)
1058 return true
1059 }
Keith Randalla347ab72015-10-26 21:49:31 -07001060 // match: (And64 x x)
1061 // cond:
1062 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01001063 for {
Keith Randalla347ab72015-10-26 21:49:31 -07001064 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07001065 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001066 break
Keith Randalla347ab72015-10-26 21:49:31 -07001067 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001068 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07001069 v.Type = x.Type
1070 v.AddArg(x)
1071 return true
1072 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01001073 // match: (And64 (Const64 [-1]) x)
1074 // cond:
1075 // result: x
1076 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07001077 v_0 := v.Args[0]
1078 if v_0.Op != OpConst64 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01001079 break
1080 }
Keith Randall259b7ed2016-03-21 16:18:45 -07001081 if v_0.AuxInt != -1 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01001082 break
1083 }
1084 x := v.Args[1]
1085 v.reset(OpCopy)
1086 v.Type = x.Type
1087 v.AddArg(x)
1088 return true
1089 }
1090 // match: (And64 (Const64 [0]) _)
1091 // cond:
1092 // result: (Const64 [0])
1093 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07001094 v_0 := v.Args[0]
1095 if v_0.Op != OpConst64 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01001096 break
1097 }
Keith Randall259b7ed2016-03-21 16:18:45 -07001098 if v_0.AuxInt != 0 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01001099 break
1100 }
1101 v.reset(OpConst64)
1102 v.AuxInt = 0
1103 return true
1104 }
Keith Randall4d5adf12016-04-18 09:28:50 -07001105 // match: (And64 x (And64 x y))
1106 // cond:
1107 // result: (And64 x y)
1108 for {
1109 x := v.Args[0]
1110 v_1 := v.Args[1]
1111 if v_1.Op != OpAnd64 {
1112 break
1113 }
1114 if x != v_1.Args[0] {
1115 break
1116 }
1117 y := v_1.Args[1]
1118 v.reset(OpAnd64)
1119 v.AddArg(x)
1120 v.AddArg(y)
1121 return true
1122 }
1123 // match: (And64 x (And64 y x))
1124 // cond:
1125 // result: (And64 x y)
1126 for {
1127 x := v.Args[0]
1128 v_1 := v.Args[1]
1129 if v_1.Op != OpAnd64 {
1130 break
1131 }
1132 y := v_1.Args[0]
1133 if x != v_1.Args[1] {
1134 break
1135 }
1136 v.reset(OpAnd64)
1137 v.AddArg(x)
1138 v.AddArg(y)
1139 return true
1140 }
1141 // match: (And64 (And64 x y) x)
1142 // cond:
1143 // result: (And64 x y)
1144 for {
1145 v_0 := v.Args[0]
1146 if v_0.Op != OpAnd64 {
1147 break
1148 }
1149 x := v_0.Args[0]
1150 y := v_0.Args[1]
1151 if x != v.Args[1] {
1152 break
1153 }
1154 v.reset(OpAnd64)
1155 v.AddArg(x)
1156 v.AddArg(y)
1157 return true
1158 }
1159 // match: (And64 (And64 x y) y)
1160 // cond:
1161 // result: (And64 x y)
1162 for {
1163 v_0 := v.Args[0]
1164 if v_0.Op != OpAnd64 {
1165 break
1166 }
1167 x := v_0.Args[0]
1168 y := v_0.Args[1]
1169 if y != v.Args[1] {
1170 break
1171 }
1172 v.reset(OpAnd64)
1173 v.AddArg(x)
1174 v.AddArg(y)
1175 return true
1176 }
Todd Nealadc8d492016-02-11 20:43:15 -06001177 // match: (And64 <t> (Const64 [y]) x)
David Chase0321cab2016-03-08 15:08:25 -05001178 // cond: nlz(y) + nto(y) == 64 && nto(y) >= 32
Todd Nealadc8d492016-02-11 20:43:15 -06001179 // result: (Rsh64Ux64 (Lsh64x64 <t> x (Const64 <t> [nlz(y)])) (Const64 <t> [nlz(y)]))
1180 for {
1181 t := v.Type
Keith Randall259b7ed2016-03-21 16:18:45 -07001182 v_0 := v.Args[0]
1183 if v_0.Op != OpConst64 {
Todd Nealadc8d492016-02-11 20:43:15 -06001184 break
1185 }
Keith Randall259b7ed2016-03-21 16:18:45 -07001186 y := v_0.AuxInt
Todd Nealadc8d492016-02-11 20:43:15 -06001187 x := v.Args[1]
David Chase0321cab2016-03-08 15:08:25 -05001188 if !(nlz(y)+nto(y) == 64 && nto(y) >= 32) {
Todd Nealadc8d492016-02-11 20:43:15 -06001189 break
1190 }
1191 v.reset(OpRsh64Ux64)
1192 v0 := b.NewValue0(v.Line, OpLsh64x64, t)
1193 v0.AddArg(x)
1194 v1 := b.NewValue0(v.Line, OpConst64, t)
1195 v1.AuxInt = nlz(y)
1196 v0.AddArg(v1)
1197 v.AddArg(v0)
1198 v2 := b.NewValue0(v.Line, OpConst64, t)
1199 v2.AuxInt = nlz(y)
1200 v.AddArg(v2)
1201 return true
1202 }
1203 // match: (And64 <t> (Const64 [y]) x)
David Chase0321cab2016-03-08 15:08:25 -05001204 // cond: nlo(y) + ntz(y) == 64 && ntz(y) >= 32
Todd Nealadc8d492016-02-11 20:43:15 -06001205 // result: (Lsh64x64 (Rsh64Ux64 <t> x (Const64 <t> [ntz(y)])) (Const64 <t> [ntz(y)]))
1206 for {
1207 t := v.Type
Keith Randall259b7ed2016-03-21 16:18:45 -07001208 v_0 := v.Args[0]
1209 if v_0.Op != OpConst64 {
Todd Nealadc8d492016-02-11 20:43:15 -06001210 break
1211 }
Keith Randall259b7ed2016-03-21 16:18:45 -07001212 y := v_0.AuxInt
Todd Nealadc8d492016-02-11 20:43:15 -06001213 x := v.Args[1]
David Chase0321cab2016-03-08 15:08:25 -05001214 if !(nlo(y)+ntz(y) == 64 && ntz(y) >= 32) {
Todd Nealadc8d492016-02-11 20:43:15 -06001215 break
1216 }
1217 v.reset(OpLsh64x64)
1218 v0 := b.NewValue0(v.Line, OpRsh64Ux64, t)
1219 v0.AddArg(x)
1220 v1 := b.NewValue0(v.Line, OpConst64, t)
1221 v1.AuxInt = ntz(y)
1222 v0.AddArg(v1)
1223 v.AddArg(v0)
1224 v2 := b.NewValue0(v.Line, OpConst64, t)
1225 v2.AuxInt = ntz(y)
1226 v.AddArg(v2)
1227 return true
1228 }
Keith Randalla347ab72015-10-26 21:49:31 -07001229 return false
1230}
1231func rewriteValuegeneric_OpAnd8(v *Value, config *Config) bool {
1232 b := v.Block
1233 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07001234 // match: (And8 x (Const8 <t> [c]))
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01001235 // cond: x.Op != OpConst8
Keith Randallfa9435c2016-04-26 12:08:31 -07001236 // result: (And8 (Const8 <t> [c]) x)
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01001237 for {
1238 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07001239 v_1 := v.Args[1]
1240 if v_1.Op != OpConst8 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01001241 break
1242 }
Keith Randall259b7ed2016-03-21 16:18:45 -07001243 t := v_1.Type
1244 c := v_1.AuxInt
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01001245 if !(x.Op != OpConst8) {
1246 break
1247 }
1248 v.reset(OpAnd8)
1249 v0 := b.NewValue0(v.Line, OpConst8, t)
1250 v0.AuxInt = c
1251 v.AddArg(v0)
1252 v.AddArg(x)
1253 return true
1254 }
Keith Randallfa9435c2016-04-26 12:08:31 -07001255 // match: (And8 x x)
Keith Randalla347ab72015-10-26 21:49:31 -07001256 // cond:
1257 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01001258 for {
Keith Randalla347ab72015-10-26 21:49:31 -07001259 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07001260 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001261 break
Keith Randalla347ab72015-10-26 21:49:31 -07001262 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001263 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07001264 v.Type = x.Type
1265 v.AddArg(x)
1266 return true
1267 }
Keith Randallfa9435c2016-04-26 12:08:31 -07001268 // match: (And8 (Const8 [-1]) x)
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01001269 // cond:
1270 // result: x
1271 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07001272 v_0 := v.Args[0]
1273 if v_0.Op != OpConst8 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01001274 break
1275 }
Keith Randall259b7ed2016-03-21 16:18:45 -07001276 if v_0.AuxInt != -1 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01001277 break
1278 }
1279 x := v.Args[1]
1280 v.reset(OpCopy)
1281 v.Type = x.Type
1282 v.AddArg(x)
1283 return true
1284 }
Keith Randallfa9435c2016-04-26 12:08:31 -07001285 // match: (And8 (Const8 [0]) _)
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01001286 // cond:
Keith Randallfa9435c2016-04-26 12:08:31 -07001287 // result: (Const8 [0])
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01001288 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07001289 v_0 := v.Args[0]
1290 if v_0.Op != OpConst8 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01001291 break
1292 }
Keith Randall259b7ed2016-03-21 16:18:45 -07001293 if v_0.AuxInt != 0 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01001294 break
1295 }
1296 v.reset(OpConst8)
1297 v.AuxInt = 0
1298 return true
1299 }
Keith Randall4d5adf12016-04-18 09:28:50 -07001300 // match: (And8 x (And8 x y))
1301 // cond:
1302 // result: (And8 x y)
1303 for {
1304 x := v.Args[0]
1305 v_1 := v.Args[1]
1306 if v_1.Op != OpAnd8 {
1307 break
1308 }
1309 if x != v_1.Args[0] {
1310 break
1311 }
1312 y := v_1.Args[1]
1313 v.reset(OpAnd8)
1314 v.AddArg(x)
1315 v.AddArg(y)
1316 return true
1317 }
1318 // match: (And8 x (And8 y x))
1319 // cond:
1320 // result: (And8 x y)
1321 for {
1322 x := v.Args[0]
1323 v_1 := v.Args[1]
1324 if v_1.Op != OpAnd8 {
1325 break
1326 }
1327 y := v_1.Args[0]
1328 if x != v_1.Args[1] {
1329 break
1330 }
1331 v.reset(OpAnd8)
1332 v.AddArg(x)
1333 v.AddArg(y)
1334 return true
1335 }
1336 // match: (And8 (And8 x y) x)
1337 // cond:
1338 // result: (And8 x y)
1339 for {
1340 v_0 := v.Args[0]
1341 if v_0.Op != OpAnd8 {
1342 break
1343 }
1344 x := v_0.Args[0]
1345 y := v_0.Args[1]
1346 if x != v.Args[1] {
1347 break
1348 }
1349 v.reset(OpAnd8)
1350 v.AddArg(x)
1351 v.AddArg(y)
1352 return true
1353 }
1354 // match: (And8 (And8 x y) y)
1355 // cond:
1356 // result: (And8 x y)
1357 for {
1358 v_0 := v.Args[0]
1359 if v_0.Op != OpAnd8 {
1360 break
1361 }
1362 x := v_0.Args[0]
1363 y := v_0.Args[1]
1364 if y != v.Args[1] {
1365 break
1366 }
1367 v.reset(OpAnd8)
1368 v.AddArg(x)
1369 v.AddArg(y)
1370 return true
1371 }
Keith Randalla347ab72015-10-26 21:49:31 -07001372 return false
1373}
Keith Randall02f4d0a2015-11-02 08:10:26 -08001374func rewriteValuegeneric_OpArg(v *Value, config *Config) bool {
1375 b := v.Block
1376 _ = b
1377 // match: (Arg {n} [off])
1378 // cond: v.Type.IsString()
1379 // result: (StringMake (Arg <config.fe.TypeBytePtr()> {n} [off]) (Arg <config.fe.TypeInt()> {n} [off+config.PtrSize]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001380 for {
Keith Randall02f4d0a2015-11-02 08:10:26 -08001381 off := v.AuxInt
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001382 n := v.Aux
Keith Randall02f4d0a2015-11-02 08:10:26 -08001383 if !(v.Type.IsString()) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001384 break
Keith Randall02f4d0a2015-11-02 08:10:26 -08001385 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001386 v.reset(OpStringMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001387 v0 := b.NewValue0(v.Line, OpArg, config.fe.TypeBytePtr())
Keith Randall02f4d0a2015-11-02 08:10:26 -08001388 v0.AuxInt = off
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001389 v0.Aux = n
Keith Randall02f4d0a2015-11-02 08:10:26 -08001390 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001391 v1 := b.NewValue0(v.Line, OpArg, config.fe.TypeInt())
Keith Randall02f4d0a2015-11-02 08:10:26 -08001392 v1.AuxInt = off + config.PtrSize
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001393 v1.Aux = n
Keith Randall02f4d0a2015-11-02 08:10:26 -08001394 v.AddArg(v1)
1395 return true
1396 }
Keith Randall02f4d0a2015-11-02 08:10:26 -08001397 // match: (Arg {n} [off])
1398 // cond: v.Type.IsSlice()
Keith Randall4a7aba72016-03-28 11:25:17 -07001399 // result: (SliceMake (Arg <v.Type.ElemType().PtrTo()> {n} [off]) (Arg <config.fe.TypeInt()> {n} [off+config.PtrSize]) (Arg <config.fe.TypeInt()> {n} [off+2*config.PtrSize]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001400 for {
Keith Randall02f4d0a2015-11-02 08:10:26 -08001401 off := v.AuxInt
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001402 n := v.Aux
Keith Randall02f4d0a2015-11-02 08:10:26 -08001403 if !(v.Type.IsSlice()) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001404 break
Keith Randall02f4d0a2015-11-02 08:10:26 -08001405 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001406 v.reset(OpSliceMake)
Keith Randall4a7aba72016-03-28 11:25:17 -07001407 v0 := b.NewValue0(v.Line, OpArg, v.Type.ElemType().PtrTo())
Keith Randall02f4d0a2015-11-02 08:10:26 -08001408 v0.AuxInt = off
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001409 v0.Aux = n
Keith Randall02f4d0a2015-11-02 08:10:26 -08001410 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001411 v1 := b.NewValue0(v.Line, OpArg, config.fe.TypeInt())
Keith Randall02f4d0a2015-11-02 08:10:26 -08001412 v1.AuxInt = off + config.PtrSize
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001413 v1.Aux = n
Keith Randall02f4d0a2015-11-02 08:10:26 -08001414 v.AddArg(v1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001415 v2 := b.NewValue0(v.Line, OpArg, config.fe.TypeInt())
Keith Randall02f4d0a2015-11-02 08:10:26 -08001416 v2.AuxInt = off + 2*config.PtrSize
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001417 v2.Aux = n
Keith Randall02f4d0a2015-11-02 08:10:26 -08001418 v.AddArg(v2)
1419 return true
1420 }
Keith Randall02f4d0a2015-11-02 08:10:26 -08001421 // match: (Arg {n} [off])
1422 // cond: v.Type.IsInterface()
1423 // result: (IMake (Arg <config.fe.TypeBytePtr()> {n} [off]) (Arg <config.fe.TypeBytePtr()> {n} [off+config.PtrSize]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001424 for {
Keith Randall02f4d0a2015-11-02 08:10:26 -08001425 off := v.AuxInt
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001426 n := v.Aux
Keith Randall02f4d0a2015-11-02 08:10:26 -08001427 if !(v.Type.IsInterface()) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001428 break
Keith Randall02f4d0a2015-11-02 08:10:26 -08001429 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001430 v.reset(OpIMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001431 v0 := b.NewValue0(v.Line, OpArg, config.fe.TypeBytePtr())
Keith Randall02f4d0a2015-11-02 08:10:26 -08001432 v0.AuxInt = off
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001433 v0.Aux = n
Keith Randall02f4d0a2015-11-02 08:10:26 -08001434 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001435 v1 := b.NewValue0(v.Line, OpArg, config.fe.TypeBytePtr())
Keith Randall02f4d0a2015-11-02 08:10:26 -08001436 v1.AuxInt = off + config.PtrSize
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001437 v1.Aux = n
Keith Randall02f4d0a2015-11-02 08:10:26 -08001438 v.AddArg(v1)
1439 return true
1440 }
Keith Randall02f4d0a2015-11-02 08:10:26 -08001441 // match: (Arg {n} [off])
1442 // cond: v.Type.IsComplex() && v.Type.Size() == 16
1443 // result: (ComplexMake (Arg <config.fe.TypeFloat64()> {n} [off]) (Arg <config.fe.TypeFloat64()> {n} [off+8]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001444 for {
Keith Randall02f4d0a2015-11-02 08:10:26 -08001445 off := v.AuxInt
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001446 n := v.Aux
Keith Randall02f4d0a2015-11-02 08:10:26 -08001447 if !(v.Type.IsComplex() && v.Type.Size() == 16) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001448 break
Keith Randall02f4d0a2015-11-02 08:10:26 -08001449 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001450 v.reset(OpComplexMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001451 v0 := b.NewValue0(v.Line, OpArg, config.fe.TypeFloat64())
Keith Randall02f4d0a2015-11-02 08:10:26 -08001452 v0.AuxInt = off
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001453 v0.Aux = n
Keith Randall02f4d0a2015-11-02 08:10:26 -08001454 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001455 v1 := b.NewValue0(v.Line, OpArg, config.fe.TypeFloat64())
Keith Randall02f4d0a2015-11-02 08:10:26 -08001456 v1.AuxInt = off + 8
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001457 v1.Aux = n
Keith Randall02f4d0a2015-11-02 08:10:26 -08001458 v.AddArg(v1)
1459 return true
1460 }
Keith Randall02f4d0a2015-11-02 08:10:26 -08001461 // match: (Arg {n} [off])
1462 // cond: v.Type.IsComplex() && v.Type.Size() == 8
1463 // result: (ComplexMake (Arg <config.fe.TypeFloat32()> {n} [off]) (Arg <config.fe.TypeFloat32()> {n} [off+4]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001464 for {
Keith Randall02f4d0a2015-11-02 08:10:26 -08001465 off := v.AuxInt
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001466 n := v.Aux
Keith Randall02f4d0a2015-11-02 08:10:26 -08001467 if !(v.Type.IsComplex() && v.Type.Size() == 8) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001468 break
Keith Randall02f4d0a2015-11-02 08:10:26 -08001469 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001470 v.reset(OpComplexMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001471 v0 := b.NewValue0(v.Line, OpArg, config.fe.TypeFloat32())
Keith Randall02f4d0a2015-11-02 08:10:26 -08001472 v0.AuxInt = off
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001473 v0.Aux = n
Keith Randall02f4d0a2015-11-02 08:10:26 -08001474 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001475 v1 := b.NewValue0(v.Line, OpArg, config.fe.TypeFloat32())
Keith Randall02f4d0a2015-11-02 08:10:26 -08001476 v1.AuxInt = off + 4
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001477 v1.Aux = n
Keith Randall02f4d0a2015-11-02 08:10:26 -08001478 v.AddArg(v1)
1479 return true
1480 }
Keith Randalla734bbc2016-01-11 21:05:33 -08001481 // match: (Arg <t>)
1482 // cond: t.IsStruct() && t.NumFields() == 0 && config.fe.CanSSA(t)
1483 // result: (StructMake0)
Alexandru Moșoi05434472016-02-04 19:52:10 +01001484 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08001485 t := v.Type
1486 if !(t.IsStruct() && t.NumFields() == 0 && config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001487 break
Keith Randalla734bbc2016-01-11 21:05:33 -08001488 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001489 v.reset(OpStructMake0)
Keith Randalla734bbc2016-01-11 21:05:33 -08001490 return true
1491 }
Keith Randalla734bbc2016-01-11 21:05:33 -08001492 // match: (Arg <t> {n} [off])
1493 // cond: t.IsStruct() && t.NumFields() == 1 && config.fe.CanSSA(t)
1494 // result: (StructMake1 (Arg <t.FieldType(0)> {n} [off+t.FieldOff(0)]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001495 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08001496 t := v.Type
Keith Randalla734bbc2016-01-11 21:05:33 -08001497 off := v.AuxInt
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001498 n := v.Aux
Keith Randalla734bbc2016-01-11 21:05:33 -08001499 if !(t.IsStruct() && t.NumFields() == 1 && config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001500 break
Keith Randalla734bbc2016-01-11 21:05:33 -08001501 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001502 v.reset(OpStructMake1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001503 v0 := b.NewValue0(v.Line, OpArg, t.FieldType(0))
Keith Randalla734bbc2016-01-11 21:05:33 -08001504 v0.AuxInt = off + t.FieldOff(0)
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001505 v0.Aux = n
Keith Randalla734bbc2016-01-11 21:05:33 -08001506 v.AddArg(v0)
1507 return true
1508 }
Keith Randalla734bbc2016-01-11 21:05:33 -08001509 // match: (Arg <t> {n} [off])
1510 // cond: t.IsStruct() && t.NumFields() == 2 && config.fe.CanSSA(t)
1511 // result: (StructMake2 (Arg <t.FieldType(0)> {n} [off+t.FieldOff(0)]) (Arg <t.FieldType(1)> {n} [off+t.FieldOff(1)]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001512 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08001513 t := v.Type
Keith Randalla734bbc2016-01-11 21:05:33 -08001514 off := v.AuxInt
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001515 n := v.Aux
Keith Randalla734bbc2016-01-11 21:05:33 -08001516 if !(t.IsStruct() && t.NumFields() == 2 && config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001517 break
Keith Randalla734bbc2016-01-11 21:05:33 -08001518 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001519 v.reset(OpStructMake2)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001520 v0 := b.NewValue0(v.Line, OpArg, t.FieldType(0))
Keith Randalla734bbc2016-01-11 21:05:33 -08001521 v0.AuxInt = off + t.FieldOff(0)
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001522 v0.Aux = n
Keith Randalla734bbc2016-01-11 21:05:33 -08001523 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001524 v1 := b.NewValue0(v.Line, OpArg, t.FieldType(1))
Keith Randalla734bbc2016-01-11 21:05:33 -08001525 v1.AuxInt = off + t.FieldOff(1)
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001526 v1.Aux = n
Keith Randalla734bbc2016-01-11 21:05:33 -08001527 v.AddArg(v1)
1528 return true
1529 }
Keith Randalla734bbc2016-01-11 21:05:33 -08001530 // match: (Arg <t> {n} [off])
1531 // cond: t.IsStruct() && t.NumFields() == 3 && config.fe.CanSSA(t)
1532 // result: (StructMake3 (Arg <t.FieldType(0)> {n} [off+t.FieldOff(0)]) (Arg <t.FieldType(1)> {n} [off+t.FieldOff(1)]) (Arg <t.FieldType(2)> {n} [off+t.FieldOff(2)]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001533 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08001534 t := v.Type
Keith Randalla734bbc2016-01-11 21:05:33 -08001535 off := v.AuxInt
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001536 n := v.Aux
Keith Randalla734bbc2016-01-11 21:05:33 -08001537 if !(t.IsStruct() && t.NumFields() == 3 && config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001538 break
Keith Randalla734bbc2016-01-11 21:05:33 -08001539 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001540 v.reset(OpStructMake3)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001541 v0 := b.NewValue0(v.Line, OpArg, t.FieldType(0))
Keith Randalla734bbc2016-01-11 21:05:33 -08001542 v0.AuxInt = off + t.FieldOff(0)
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001543 v0.Aux = n
Keith Randalla734bbc2016-01-11 21:05:33 -08001544 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001545 v1 := b.NewValue0(v.Line, OpArg, t.FieldType(1))
Keith Randalla734bbc2016-01-11 21:05:33 -08001546 v1.AuxInt = off + t.FieldOff(1)
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001547 v1.Aux = n
Keith Randalla734bbc2016-01-11 21:05:33 -08001548 v.AddArg(v1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001549 v2 := b.NewValue0(v.Line, OpArg, t.FieldType(2))
Keith Randalla734bbc2016-01-11 21:05:33 -08001550 v2.AuxInt = off + t.FieldOff(2)
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001551 v2.Aux = n
Keith Randalla734bbc2016-01-11 21:05:33 -08001552 v.AddArg(v2)
1553 return true
1554 }
Keith Randalla734bbc2016-01-11 21:05:33 -08001555 // match: (Arg <t> {n} [off])
1556 // cond: t.IsStruct() && t.NumFields() == 4 && config.fe.CanSSA(t)
1557 // result: (StructMake4 (Arg <t.FieldType(0)> {n} [off+t.FieldOff(0)]) (Arg <t.FieldType(1)> {n} [off+t.FieldOff(1)]) (Arg <t.FieldType(2)> {n} [off+t.FieldOff(2)]) (Arg <t.FieldType(3)> {n} [off+t.FieldOff(3)]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001558 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08001559 t := v.Type
Keith Randalla734bbc2016-01-11 21:05:33 -08001560 off := v.AuxInt
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001561 n := v.Aux
Keith Randalla734bbc2016-01-11 21:05:33 -08001562 if !(t.IsStruct() && t.NumFields() == 4 && config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001563 break
Keith Randalla734bbc2016-01-11 21:05:33 -08001564 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001565 v.reset(OpStructMake4)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001566 v0 := b.NewValue0(v.Line, OpArg, t.FieldType(0))
Keith Randalla734bbc2016-01-11 21:05:33 -08001567 v0.AuxInt = off + t.FieldOff(0)
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001568 v0.Aux = n
Keith Randalla734bbc2016-01-11 21:05:33 -08001569 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001570 v1 := b.NewValue0(v.Line, OpArg, t.FieldType(1))
Keith Randalla734bbc2016-01-11 21:05:33 -08001571 v1.AuxInt = off + t.FieldOff(1)
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001572 v1.Aux = n
Keith Randalla734bbc2016-01-11 21:05:33 -08001573 v.AddArg(v1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001574 v2 := b.NewValue0(v.Line, OpArg, t.FieldType(2))
Keith Randalla734bbc2016-01-11 21:05:33 -08001575 v2.AuxInt = off + t.FieldOff(2)
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001576 v2.Aux = n
Keith Randalla734bbc2016-01-11 21:05:33 -08001577 v.AddArg(v2)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001578 v3 := b.NewValue0(v.Line, OpArg, t.FieldType(3))
Keith Randalla734bbc2016-01-11 21:05:33 -08001579 v3.AuxInt = off + t.FieldOff(3)
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07001580 v3.Aux = n
Keith Randalla734bbc2016-01-11 21:05:33 -08001581 v.AddArg(v3)
1582 return true
1583 }
Keith Randall02f4d0a2015-11-02 08:10:26 -08001584 return false
1585}
Keith Randalla347ab72015-10-26 21:49:31 -07001586func rewriteValuegeneric_OpArrayIndex(v *Value, config *Config) bool {
1587 b := v.Block
1588 _ = b
Keith Randall259b7ed2016-03-21 16:18:45 -07001589 // match: (ArrayIndex <t> [0] x:(Load ptr mem))
Keith Randall62ac1072016-03-01 15:59:15 -08001590 // cond:
Keith Randall259b7ed2016-03-21 16:18:45 -07001591 // result: @x.Block (Load <t> ptr mem)
Alexandru Moșoi05434472016-02-04 19:52:10 +01001592 for {
Keith Randall62ac1072016-03-01 15:59:15 -08001593 t := v.Type
1594 if v.AuxInt != 0 {
1595 break
1596 }
Keith Randall259b7ed2016-03-21 16:18:45 -07001597 x := v.Args[0]
1598 if x.Op != OpLoad {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001599 break
Keith Randalla347ab72015-10-26 21:49:31 -07001600 }
Keith Randall259b7ed2016-03-21 16:18:45 -07001601 ptr := x.Args[0]
1602 mem := x.Args[1]
1603 b = x.Block
Keith Randall62ac1072016-03-01 15:59:15 -08001604 v0 := b.NewValue0(v.Line, OpLoad, t)
1605 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07001606 v.AddArg(v0)
Keith Randall62ac1072016-03-01 15:59:15 -08001607 v0.AddArg(ptr)
1608 v0.AddArg(mem)
Keith Randalla347ab72015-10-26 21:49:31 -07001609 return true
1610 }
Keith Randalla347ab72015-10-26 21:49:31 -07001611 return false
1612}
1613func rewriteValuegeneric_OpCom16(v *Value, config *Config) bool {
1614 b := v.Block
1615 _ = b
1616 // match: (Com16 (Com16 x))
1617 // cond:
1618 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01001619 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07001620 v_0 := v.Args[0]
1621 if v_0.Op != OpCom16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001622 break
Keith Randalla347ab72015-10-26 21:49:31 -07001623 }
Keith Randall259b7ed2016-03-21 16:18:45 -07001624 x := v_0.Args[0]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001625 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07001626 v.Type = x.Type
1627 v.AddArg(x)
1628 return true
1629 }
Keith Randalla347ab72015-10-26 21:49:31 -07001630 return false
1631}
1632func rewriteValuegeneric_OpCom32(v *Value, config *Config) bool {
1633 b := v.Block
1634 _ = b
1635 // match: (Com32 (Com32 x))
1636 // cond:
1637 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01001638 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07001639 v_0 := v.Args[0]
1640 if v_0.Op != OpCom32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001641 break
Keith Randalla347ab72015-10-26 21:49:31 -07001642 }
Keith Randall259b7ed2016-03-21 16:18:45 -07001643 x := v_0.Args[0]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001644 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07001645 v.Type = x.Type
1646 v.AddArg(x)
1647 return true
1648 }
Keith Randalla347ab72015-10-26 21:49:31 -07001649 return false
1650}
1651func rewriteValuegeneric_OpCom64(v *Value, config *Config) bool {
1652 b := v.Block
1653 _ = b
1654 // match: (Com64 (Com64 x))
1655 // cond:
1656 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01001657 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07001658 v_0 := v.Args[0]
1659 if v_0.Op != OpCom64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001660 break
Keith Randalla347ab72015-10-26 21:49:31 -07001661 }
Keith Randall259b7ed2016-03-21 16:18:45 -07001662 x := v_0.Args[0]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001663 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07001664 v.Type = x.Type
1665 v.AddArg(x)
1666 return true
1667 }
Keith Randalla347ab72015-10-26 21:49:31 -07001668 return false
1669}
1670func rewriteValuegeneric_OpCom8(v *Value, config *Config) bool {
1671 b := v.Block
1672 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07001673 // match: (Com8 (Com8 x))
Keith Randalla347ab72015-10-26 21:49:31 -07001674 // cond:
1675 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01001676 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07001677 v_0 := v.Args[0]
1678 if v_0.Op != OpCom8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001679 break
Keith Randalla347ab72015-10-26 21:49:31 -07001680 }
Keith Randall259b7ed2016-03-21 16:18:45 -07001681 x := v_0.Args[0]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001682 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07001683 v.Type = x.Type
1684 v.AddArg(x)
1685 return true
1686 }
Keith Randalla347ab72015-10-26 21:49:31 -07001687 return false
1688}
Keith Randalla347ab72015-10-26 21:49:31 -07001689func rewriteValuegeneric_OpConstInterface(v *Value, config *Config) bool {
1690 b := v.Block
1691 _ = b
1692 // match: (ConstInterface)
1693 // cond:
1694 // result: (IMake (ConstNil <config.fe.TypeBytePtr()>) (ConstNil <config.fe.TypeBytePtr()>))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001695 for {
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001696 v.reset(OpIMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001697 v0 := b.NewValue0(v.Line, OpConstNil, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07001698 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001699 v1 := b.NewValue0(v.Line, OpConstNil, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07001700 v.AddArg(v1)
1701 return true
1702 }
Keith Randalla347ab72015-10-26 21:49:31 -07001703}
1704func rewriteValuegeneric_OpConstSlice(v *Value, config *Config) bool {
1705 b := v.Block
1706 _ = b
1707 // match: (ConstSlice)
Keith Randall582baae2015-11-02 21:28:13 -08001708 // cond: config.PtrSize == 4
Keith Randall4a7aba72016-03-28 11:25:17 -07001709 // result: (SliceMake (ConstNil <v.Type.ElemType().PtrTo()>) (Const32 <config.fe.TypeInt()> [0]) (Const32 <config.fe.TypeInt()> [0]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001710 for {
Keith Randall582baae2015-11-02 21:28:13 -08001711 if !(config.PtrSize == 4) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001712 break
Keith Randall582baae2015-11-02 21:28:13 -08001713 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001714 v.reset(OpSliceMake)
Keith Randall4a7aba72016-03-28 11:25:17 -07001715 v0 := b.NewValue0(v.Line, OpConstNil, v.Type.ElemType().PtrTo())
Keith Randalla347ab72015-10-26 21:49:31 -07001716 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001717 v1 := b.NewValue0(v.Line, OpConst32, config.fe.TypeInt())
Keith Randalla347ab72015-10-26 21:49:31 -07001718 v1.AuxInt = 0
Keith Randalla347ab72015-10-26 21:49:31 -07001719 v.AddArg(v1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001720 v2 := b.NewValue0(v.Line, OpConst32, config.fe.TypeInt())
Keith Randalla347ab72015-10-26 21:49:31 -07001721 v2.AuxInt = 0
Keith Randalla347ab72015-10-26 21:49:31 -07001722 v.AddArg(v2)
1723 return true
1724 }
Keith Randall582baae2015-11-02 21:28:13 -08001725 // match: (ConstSlice)
1726 // cond: config.PtrSize == 8
Keith Randall4a7aba72016-03-28 11:25:17 -07001727 // result: (SliceMake (ConstNil <v.Type.ElemType().PtrTo()>) (Const64 <config.fe.TypeInt()> [0]) (Const64 <config.fe.TypeInt()> [0]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001728 for {
Keith Randall582baae2015-11-02 21:28:13 -08001729 if !(config.PtrSize == 8) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001730 break
Keith Randall582baae2015-11-02 21:28:13 -08001731 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001732 v.reset(OpSliceMake)
Keith Randall4a7aba72016-03-28 11:25:17 -07001733 v0 := b.NewValue0(v.Line, OpConstNil, v.Type.ElemType().PtrTo())
Keith Randall582baae2015-11-02 21:28:13 -08001734 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001735 v1 := b.NewValue0(v.Line, OpConst64, config.fe.TypeInt())
Keith Randall582baae2015-11-02 21:28:13 -08001736 v1.AuxInt = 0
1737 v.AddArg(v1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001738 v2 := b.NewValue0(v.Line, OpConst64, config.fe.TypeInt())
Keith Randall582baae2015-11-02 21:28:13 -08001739 v2.AuxInt = 0
1740 v.AddArg(v2)
1741 return true
1742 }
Keith Randalla347ab72015-10-26 21:49:31 -07001743 return false
1744}
1745func rewriteValuegeneric_OpConstString(v *Value, config *Config) bool {
1746 b := v.Block
1747 _ = b
1748 // match: (ConstString {s})
Keith Randall170589e2015-11-09 20:54:34 -08001749 // cond: config.PtrSize == 4 && s.(string) == ""
1750 // result: (StringMake (ConstNil) (Const32 <config.fe.TypeInt()> [0]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001751 for {
Keith Randall170589e2015-11-09 20:54:34 -08001752 s := v.Aux
1753 if !(config.PtrSize == 4 && s.(string) == "") {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001754 break
Keith Randall170589e2015-11-09 20:54:34 -08001755 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001756 v.reset(OpStringMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001757 v0 := b.NewValue0(v.Line, OpConstNil, config.fe.TypeBytePtr())
Keith Randall170589e2015-11-09 20:54:34 -08001758 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001759 v1 := b.NewValue0(v.Line, OpConst32, config.fe.TypeInt())
Keith Randall170589e2015-11-09 20:54:34 -08001760 v1.AuxInt = 0
1761 v.AddArg(v1)
1762 return true
1763 }
Keith Randall170589e2015-11-09 20:54:34 -08001764 // match: (ConstString {s})
1765 // cond: config.PtrSize == 8 && s.(string) == ""
1766 // result: (StringMake (ConstNil) (Const64 <config.fe.TypeInt()> [0]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001767 for {
Keith Randall170589e2015-11-09 20:54:34 -08001768 s := v.Aux
1769 if !(config.PtrSize == 8 && s.(string) == "") {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001770 break
Keith Randall170589e2015-11-09 20:54:34 -08001771 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001772 v.reset(OpStringMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001773 v0 := b.NewValue0(v.Line, OpConstNil, config.fe.TypeBytePtr())
Keith Randall170589e2015-11-09 20:54:34 -08001774 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001775 v1 := b.NewValue0(v.Line, OpConst64, config.fe.TypeInt())
Keith Randall170589e2015-11-09 20:54:34 -08001776 v1.AuxInt = 0
1777 v.AddArg(v1)
1778 return true
1779 }
Keith Randall170589e2015-11-09 20:54:34 -08001780 // match: (ConstString {s})
1781 // cond: config.PtrSize == 4 && s.(string) != ""
Keith Randall582baae2015-11-02 21:28:13 -08001782 // result: (StringMake (Addr <config.fe.TypeBytePtr()> {config.fe.StringData(s.(string))} (SB)) (Const32 <config.fe.TypeInt()> [int64(len(s.(string)))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001783 for {
Keith Randalla347ab72015-10-26 21:49:31 -07001784 s := v.Aux
Keith Randall170589e2015-11-09 20:54:34 -08001785 if !(config.PtrSize == 4 && s.(string) != "") {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001786 break
Keith Randall582baae2015-11-02 21:28:13 -08001787 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001788 v.reset(OpStringMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001789 v0 := b.NewValue0(v.Line, OpAddr, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07001790 v0.Aux = config.fe.StringData(s.(string))
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001791 v1 := b.NewValue0(v.Line, OpSB, config.fe.TypeUintptr())
Keith Randalla347ab72015-10-26 21:49:31 -07001792 v0.AddArg(v1)
1793 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001794 v2 := b.NewValue0(v.Line, OpConst32, config.fe.TypeInt())
Keith Randalla347ab72015-10-26 21:49:31 -07001795 v2.AuxInt = int64(len(s.(string)))
Keith Randalla347ab72015-10-26 21:49:31 -07001796 v.AddArg(v2)
1797 return true
1798 }
Keith Randall582baae2015-11-02 21:28:13 -08001799 // match: (ConstString {s})
Keith Randall170589e2015-11-09 20:54:34 -08001800 // cond: config.PtrSize == 8 && s.(string) != ""
Keith Randall582baae2015-11-02 21:28:13 -08001801 // result: (StringMake (Addr <config.fe.TypeBytePtr()> {config.fe.StringData(s.(string))} (SB)) (Const64 <config.fe.TypeInt()> [int64(len(s.(string)))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001802 for {
Keith Randall582baae2015-11-02 21:28:13 -08001803 s := v.Aux
Keith Randall170589e2015-11-09 20:54:34 -08001804 if !(config.PtrSize == 8 && s.(string) != "") {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001805 break
Keith Randall582baae2015-11-02 21:28:13 -08001806 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001807 v.reset(OpStringMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001808 v0 := b.NewValue0(v.Line, OpAddr, config.fe.TypeBytePtr())
Keith Randall582baae2015-11-02 21:28:13 -08001809 v0.Aux = config.fe.StringData(s.(string))
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001810 v1 := b.NewValue0(v.Line, OpSB, config.fe.TypeUintptr())
Keith Randall582baae2015-11-02 21:28:13 -08001811 v0.AddArg(v1)
1812 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001813 v2 := b.NewValue0(v.Line, OpConst64, config.fe.TypeInt())
Keith Randall582baae2015-11-02 21:28:13 -08001814 v2.AuxInt = int64(len(s.(string)))
1815 v.AddArg(v2)
1816 return true
1817 }
Keith Randalla347ab72015-10-26 21:49:31 -07001818 return false
1819}
1820func rewriteValuegeneric_OpConvert(v *Value, config *Config) bool {
1821 b := v.Block
1822 _ = b
Keith Randall7807bda2015-11-10 15:35:36 -08001823 // match: (Convert (Add64 (Convert ptr mem) off) mem)
Keith Randalla347ab72015-10-26 21:49:31 -07001824 // cond:
1825 // result: (Add64 ptr off)
Alexandru Moșoi05434472016-02-04 19:52:10 +01001826 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07001827 v_0 := v.Args[0]
1828 if v_0.Op != OpAdd64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001829 break
Keith Randalla347ab72015-10-26 21:49:31 -07001830 }
Keith Randall259b7ed2016-03-21 16:18:45 -07001831 v_0_0 := v_0.Args[0]
1832 if v_0_0.Op != OpConvert {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001833 break
Keith Randalla347ab72015-10-26 21:49:31 -07001834 }
Keith Randall259b7ed2016-03-21 16:18:45 -07001835 ptr := v_0_0.Args[0]
1836 mem := v_0_0.Args[1]
1837 off := v_0.Args[1]
1838 if mem != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001839 break
Keith Randall7807bda2015-11-10 15:35:36 -08001840 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001841 v.reset(OpAdd64)
Keith Randalla347ab72015-10-26 21:49:31 -07001842 v.AddArg(ptr)
1843 v.AddArg(off)
1844 return true
1845 }
Alexandru Moșoid337e552016-02-23 21:48:33 +01001846 // match: (Convert (Add64 off (Convert ptr mem)) mem)
1847 // cond:
1848 // result: (Add64 ptr off)
1849 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07001850 v_0 := v.Args[0]
1851 if v_0.Op != OpAdd64 {
Alexandru Moșoid337e552016-02-23 21:48:33 +01001852 break
1853 }
Keith Randall259b7ed2016-03-21 16:18:45 -07001854 off := v_0.Args[0]
1855 v_0_1 := v_0.Args[1]
1856 if v_0_1.Op != OpConvert {
Alexandru Moșoid337e552016-02-23 21:48:33 +01001857 break
1858 }
Keith Randall259b7ed2016-03-21 16:18:45 -07001859 ptr := v_0_1.Args[0]
1860 mem := v_0_1.Args[1]
1861 if mem != v.Args[1] {
Alexandru Moșoid337e552016-02-23 21:48:33 +01001862 break
1863 }
1864 v.reset(OpAdd64)
1865 v.AddArg(ptr)
1866 v.AddArg(off)
1867 return true
1868 }
Keith Randall7807bda2015-11-10 15:35:36 -08001869 // match: (Convert (Convert ptr mem) mem)
1870 // cond:
1871 // result: ptr
Alexandru Moșoi05434472016-02-04 19:52:10 +01001872 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07001873 v_0 := v.Args[0]
1874 if v_0.Op != OpConvert {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001875 break
Keith Randall7807bda2015-11-10 15:35:36 -08001876 }
Keith Randall259b7ed2016-03-21 16:18:45 -07001877 ptr := v_0.Args[0]
1878 mem := v_0.Args[1]
1879 if mem != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001880 break
Keith Randall7807bda2015-11-10 15:35:36 -08001881 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001882 v.reset(OpCopy)
Keith Randall7807bda2015-11-10 15:35:36 -08001883 v.Type = ptr.Type
1884 v.AddArg(ptr)
1885 return true
1886 }
Keith Randalla347ab72015-10-26 21:49:31 -07001887 return false
1888}
Todd Nealf6ceed22016-03-11 19:36:54 -06001889func rewriteValuegeneric_OpCvt32Fto64F(v *Value, config *Config) bool {
1890 b := v.Block
1891 _ = b
1892 // match: (Cvt32Fto64F (Const32F [c]))
1893 // cond:
1894 // result: (Const64F [c])
1895 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07001896 v_0 := v.Args[0]
1897 if v_0.Op != OpConst32F {
Todd Nealf6ceed22016-03-11 19:36:54 -06001898 break
1899 }
Keith Randall259b7ed2016-03-21 16:18:45 -07001900 c := v_0.AuxInt
Todd Nealf6ceed22016-03-11 19:36:54 -06001901 v.reset(OpConst64F)
1902 v.AuxInt = c
1903 return true
1904 }
1905 return false
1906}
1907func rewriteValuegeneric_OpCvt64Fto32F(v *Value, config *Config) bool {
1908 b := v.Block
1909 _ = b
1910 // match: (Cvt64Fto32F (Const64F [c]))
1911 // cond:
1912 // result: (Const32F [f2i(float64(i2f32(c)))])
1913 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07001914 v_0 := v.Args[0]
1915 if v_0.Op != OpConst64F {
Todd Nealf6ceed22016-03-11 19:36:54 -06001916 break
1917 }
Keith Randall259b7ed2016-03-21 16:18:45 -07001918 c := v_0.AuxInt
Todd Nealf6ceed22016-03-11 19:36:54 -06001919 v.reset(OpConst32F)
1920 v.AuxInt = f2i(float64(i2f32(c)))
1921 return true
1922 }
1923 return false
1924}
Cherry Zhang7d70f842016-07-06 10:04:45 -04001925func rewriteValuegeneric_OpDiv32F(v *Value, config *Config) bool {
1926 b := v.Block
1927 _ = b
1928 // match: (Div32F x (Const32F [f2i(1)]))
1929 // cond:
1930 // result: x
1931 for {
1932 x := v.Args[0]
1933 v_1 := v.Args[1]
1934 if v_1.Op != OpConst32F {
1935 break
1936 }
1937 if v_1.AuxInt != f2i(1) {
1938 break
1939 }
1940 v.reset(OpCopy)
1941 v.Type = x.Type
1942 v.AddArg(x)
1943 return true
1944 }
1945 // match: (Div32F x (Const32F [f2i(-1)]))
1946 // cond:
1947 // result: (Neg32F x)
1948 for {
1949 x := v.Args[0]
1950 v_1 := v.Args[1]
1951 if v_1.Op != OpConst32F {
1952 break
1953 }
1954 if v_1.AuxInt != f2i(-1) {
1955 break
1956 }
1957 v.reset(OpNeg32F)
1958 v.AddArg(x)
1959 return true
1960 }
1961 return false
1962}
Keith Randalla3055af2016-02-05 20:26:18 -08001963func rewriteValuegeneric_OpDiv64(v *Value, config *Config) bool {
1964 b := v.Block
1965 _ = b
1966 // match: (Div64 <t> x (Const64 [c]))
1967 // cond: c > 0 && smagic64ok(c) && smagic64m(c) > 0
1968 // result: (Sub64 <t> (Rsh64x64 <t> (Hmul64 <t> (Const64 <t> [smagic64m(c)]) x) (Const64 <t> [smagic64s(c)])) (Rsh64x64 <t> x (Const64 <t> [63])))
1969 for {
1970 t := v.Type
1971 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07001972 v_1 := v.Args[1]
1973 if v_1.Op != OpConst64 {
Keith Randalla3055af2016-02-05 20:26:18 -08001974 break
1975 }
Keith Randall259b7ed2016-03-21 16:18:45 -07001976 c := v_1.AuxInt
Keith Randalla3055af2016-02-05 20:26:18 -08001977 if !(c > 0 && smagic64ok(c) && smagic64m(c) > 0) {
1978 break
1979 }
1980 v.reset(OpSub64)
1981 v.Type = t
1982 v0 := b.NewValue0(v.Line, OpRsh64x64, t)
1983 v1 := b.NewValue0(v.Line, OpHmul64, t)
1984 v2 := b.NewValue0(v.Line, OpConst64, t)
1985 v2.AuxInt = smagic64m(c)
1986 v1.AddArg(v2)
1987 v1.AddArg(x)
1988 v0.AddArg(v1)
1989 v3 := b.NewValue0(v.Line, OpConst64, t)
1990 v3.AuxInt = smagic64s(c)
1991 v0.AddArg(v3)
1992 v.AddArg(v0)
1993 v4 := b.NewValue0(v.Line, OpRsh64x64, t)
1994 v4.AddArg(x)
1995 v5 := b.NewValue0(v.Line, OpConst64, t)
1996 v5.AuxInt = 63
1997 v4.AddArg(v5)
1998 v.AddArg(v4)
1999 return true
2000 }
2001 // match: (Div64 <t> x (Const64 [c]))
2002 // cond: c > 0 && smagic64ok(c) && smagic64m(c) < 0
2003 // result: (Sub64 <t> (Rsh64x64 <t> (Add64 <t> (Hmul64 <t> (Const64 <t> [smagic64m(c)]) x) x) (Const64 <t> [smagic64s(c)])) (Rsh64x64 <t> x (Const64 <t> [63])))
2004 for {
2005 t := v.Type
2006 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07002007 v_1 := v.Args[1]
2008 if v_1.Op != OpConst64 {
Keith Randalla3055af2016-02-05 20:26:18 -08002009 break
2010 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002011 c := v_1.AuxInt
Keith Randalla3055af2016-02-05 20:26:18 -08002012 if !(c > 0 && smagic64ok(c) && smagic64m(c) < 0) {
2013 break
2014 }
2015 v.reset(OpSub64)
2016 v.Type = t
2017 v0 := b.NewValue0(v.Line, OpRsh64x64, t)
2018 v1 := b.NewValue0(v.Line, OpAdd64, t)
2019 v2 := b.NewValue0(v.Line, OpHmul64, t)
2020 v3 := b.NewValue0(v.Line, OpConst64, t)
2021 v3.AuxInt = smagic64m(c)
2022 v2.AddArg(v3)
2023 v2.AddArg(x)
2024 v1.AddArg(v2)
2025 v1.AddArg(x)
2026 v0.AddArg(v1)
2027 v4 := b.NewValue0(v.Line, OpConst64, t)
2028 v4.AuxInt = smagic64s(c)
2029 v0.AddArg(v4)
2030 v.AddArg(v0)
2031 v5 := b.NewValue0(v.Line, OpRsh64x64, t)
2032 v5.AddArg(x)
2033 v6 := b.NewValue0(v.Line, OpConst64, t)
2034 v6.AuxInt = 63
2035 v5.AddArg(v6)
2036 v.AddArg(v5)
2037 return true
2038 }
2039 // match: (Div64 <t> x (Const64 [c]))
2040 // cond: c < 0 && smagic64ok(c) && smagic64m(c) > 0
2041 // result: (Neg64 <t> (Sub64 <t> (Rsh64x64 <t> (Hmul64 <t> (Const64 <t> [smagic64m(c)]) x) (Const64 <t> [smagic64s(c)])) (Rsh64x64 <t> x (Const64 <t> [63]))))
2042 for {
2043 t := v.Type
2044 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07002045 v_1 := v.Args[1]
2046 if v_1.Op != OpConst64 {
Keith Randalla3055af2016-02-05 20:26:18 -08002047 break
2048 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002049 c := v_1.AuxInt
Keith Randalla3055af2016-02-05 20:26:18 -08002050 if !(c < 0 && smagic64ok(c) && smagic64m(c) > 0) {
2051 break
2052 }
2053 v.reset(OpNeg64)
2054 v.Type = t
2055 v0 := b.NewValue0(v.Line, OpSub64, t)
2056 v1 := b.NewValue0(v.Line, OpRsh64x64, t)
2057 v2 := b.NewValue0(v.Line, OpHmul64, t)
2058 v3 := b.NewValue0(v.Line, OpConst64, t)
2059 v3.AuxInt = smagic64m(c)
2060 v2.AddArg(v3)
2061 v2.AddArg(x)
2062 v1.AddArg(v2)
2063 v4 := b.NewValue0(v.Line, OpConst64, t)
2064 v4.AuxInt = smagic64s(c)
2065 v1.AddArg(v4)
2066 v0.AddArg(v1)
2067 v5 := b.NewValue0(v.Line, OpRsh64x64, t)
2068 v5.AddArg(x)
2069 v6 := b.NewValue0(v.Line, OpConst64, t)
2070 v6.AuxInt = 63
2071 v5.AddArg(v6)
2072 v0.AddArg(v5)
2073 v.AddArg(v0)
2074 return true
2075 }
2076 // match: (Div64 <t> x (Const64 [c]))
2077 // cond: c < 0 && smagic64ok(c) && smagic64m(c) < 0
2078 // result: (Neg64 <t> (Sub64 <t> (Rsh64x64 <t> (Add64 <t> (Hmul64 <t> (Const64 <t> [smagic64m(c)]) x) x) (Const64 <t> [smagic64s(c)])) (Rsh64x64 <t> x (Const64 <t> [63]))))
2079 for {
2080 t := v.Type
2081 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07002082 v_1 := v.Args[1]
2083 if v_1.Op != OpConst64 {
Keith Randalla3055af2016-02-05 20:26:18 -08002084 break
2085 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002086 c := v_1.AuxInt
Keith Randalla3055af2016-02-05 20:26:18 -08002087 if !(c < 0 && smagic64ok(c) && smagic64m(c) < 0) {
2088 break
2089 }
2090 v.reset(OpNeg64)
2091 v.Type = t
2092 v0 := b.NewValue0(v.Line, OpSub64, t)
2093 v1 := b.NewValue0(v.Line, OpRsh64x64, t)
2094 v2 := b.NewValue0(v.Line, OpAdd64, t)
2095 v3 := b.NewValue0(v.Line, OpHmul64, t)
2096 v4 := b.NewValue0(v.Line, OpConst64, t)
2097 v4.AuxInt = smagic64m(c)
2098 v3.AddArg(v4)
2099 v3.AddArg(x)
2100 v2.AddArg(v3)
2101 v2.AddArg(x)
2102 v1.AddArg(v2)
2103 v5 := b.NewValue0(v.Line, OpConst64, t)
2104 v5.AuxInt = smagic64s(c)
2105 v1.AddArg(v5)
2106 v0.AddArg(v1)
2107 v6 := b.NewValue0(v.Line, OpRsh64x64, t)
2108 v6.AddArg(x)
2109 v7 := b.NewValue0(v.Line, OpConst64, t)
2110 v7.AuxInt = 63
2111 v6.AddArg(v7)
2112 v0.AddArg(v6)
2113 v.AddArg(v0)
2114 return true
2115 }
2116 return false
2117}
Cherry Zhang7d70f842016-07-06 10:04:45 -04002118func rewriteValuegeneric_OpDiv64F(v *Value, config *Config) bool {
2119 b := v.Block
2120 _ = b
2121 // match: (Div64F x (Const64F [f2i(1)]))
2122 // cond:
2123 // result: x
2124 for {
2125 x := v.Args[0]
2126 v_1 := v.Args[1]
2127 if v_1.Op != OpConst64F {
2128 break
2129 }
2130 if v_1.AuxInt != f2i(1) {
2131 break
2132 }
2133 v.reset(OpCopy)
2134 v.Type = x.Type
2135 v.AddArg(x)
2136 return true
2137 }
2138 // match: (Div64F x (Const64F [f2i(-1)]))
2139 // cond:
2140 // result: (Neg32F x)
2141 for {
2142 x := v.Args[0]
2143 v_1 := v.Args[1]
2144 if v_1.Op != OpConst64F {
2145 break
2146 }
2147 if v_1.AuxInt != f2i(-1) {
2148 break
2149 }
2150 v.reset(OpNeg32F)
2151 v.AddArg(x)
2152 return true
2153 }
2154 return false
2155}
Keith Randalla3055af2016-02-05 20:26:18 -08002156func rewriteValuegeneric_OpDiv64u(v *Value, config *Config) bool {
2157 b := v.Block
2158 _ = b
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01002159 // match: (Div64u <t> n (Const64 [c]))
2160 // cond: isPowerOfTwo(c)
2161 // result: (Rsh64Ux64 n (Const64 <t> [log2(c)]))
2162 for {
2163 t := v.Type
2164 n := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07002165 v_1 := v.Args[1]
2166 if v_1.Op != OpConst64 {
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01002167 break
2168 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002169 c := v_1.AuxInt
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01002170 if !(isPowerOfTwo(c)) {
2171 break
2172 }
2173 v.reset(OpRsh64Ux64)
2174 v.AddArg(n)
2175 v0 := b.NewValue0(v.Line, OpConst64, t)
2176 v0.AuxInt = log2(c)
2177 v.AddArg(v0)
2178 return true
2179 }
Keith Randalla3055af2016-02-05 20:26:18 -08002180 // match: (Div64u <t> x (Const64 [c]))
2181 // cond: umagic64ok(c) && !umagic64a(c)
2182 // result: (Rsh64Ux64 (Hmul64u <t> (Const64 <t> [umagic64m(c)]) x) (Const64 <t> [umagic64s(c)]))
2183 for {
2184 t := v.Type
2185 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07002186 v_1 := v.Args[1]
2187 if v_1.Op != OpConst64 {
Keith Randalla3055af2016-02-05 20:26:18 -08002188 break
2189 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002190 c := v_1.AuxInt
Keith Randalla3055af2016-02-05 20:26:18 -08002191 if !(umagic64ok(c) && !umagic64a(c)) {
2192 break
2193 }
2194 v.reset(OpRsh64Ux64)
2195 v0 := b.NewValue0(v.Line, OpHmul64u, t)
2196 v1 := b.NewValue0(v.Line, OpConst64, t)
2197 v1.AuxInt = umagic64m(c)
2198 v0.AddArg(v1)
2199 v0.AddArg(x)
2200 v.AddArg(v0)
2201 v2 := b.NewValue0(v.Line, OpConst64, t)
2202 v2.AuxInt = umagic64s(c)
2203 v.AddArg(v2)
2204 return true
2205 }
2206 // match: (Div64u <t> x (Const64 [c]))
2207 // cond: umagic64ok(c) && umagic64a(c)
2208 // result: (Rsh64Ux64 (Avg64u <t> (Hmul64u <t> x (Const64 <t> [umagic64m(c)])) x) (Const64 <t> [umagic64s(c)-1]))
2209 for {
2210 t := v.Type
2211 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07002212 v_1 := v.Args[1]
2213 if v_1.Op != OpConst64 {
Keith Randalla3055af2016-02-05 20:26:18 -08002214 break
2215 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002216 c := v_1.AuxInt
Keith Randalla3055af2016-02-05 20:26:18 -08002217 if !(umagic64ok(c) && umagic64a(c)) {
2218 break
2219 }
2220 v.reset(OpRsh64Ux64)
2221 v0 := b.NewValue0(v.Line, OpAvg64u, t)
2222 v1 := b.NewValue0(v.Line, OpHmul64u, t)
2223 v1.AddArg(x)
2224 v2 := b.NewValue0(v.Line, OpConst64, t)
2225 v2.AuxInt = umagic64m(c)
2226 v1.AddArg(v2)
2227 v0.AddArg(v1)
2228 v0.AddArg(x)
2229 v.AddArg(v0)
2230 v3 := b.NewValue0(v.Line, OpConst64, t)
2231 v3.AuxInt = umagic64s(c) - 1
2232 v.AddArg(v3)
2233 return true
2234 }
2235 return false
2236}
Keith Randalla347ab72015-10-26 21:49:31 -07002237func rewriteValuegeneric_OpEq16(v *Value, config *Config) bool {
2238 b := v.Block
2239 _ = b
2240 // match: (Eq16 x x)
2241 // cond:
2242 // result: (ConstBool [1])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002243 for {
Keith Randalla347ab72015-10-26 21:49:31 -07002244 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07002245 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002246 break
Keith Randalla347ab72015-10-26 21:49:31 -07002247 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002248 v.reset(OpConstBool)
Keith Randalla347ab72015-10-26 21:49:31 -07002249 v.AuxInt = 1
2250 return true
2251 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002252 // match: (Eq16 (Const16 <t> [c]) (Add16 (Const16 <t> [d]) x))
2253 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07002254 // result: (Eq16 (Const16 <t> [int64(int16(c-d))]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01002255 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07002256 v_0 := v.Args[0]
2257 if v_0.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002258 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002259 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002260 t := v_0.Type
2261 c := v_0.AuxInt
2262 v_1 := v.Args[1]
2263 if v_1.Op != OpAdd16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002264 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002265 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002266 v_1_0 := v_1.Args[0]
2267 if v_1_0.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002268 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002269 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002270 if v_1_0.Type != t {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002271 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002272 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002273 d := v_1_0.AuxInt
2274 x := v_1.Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002275 v.reset(OpEq16)
Todd Neal93a0b0f2016-02-03 06:21:24 -05002276 v0 := b.NewValue0(v.Line, OpConst16, t)
Keith Randall7fc56212016-03-29 16:39:53 -07002277 v0.AuxInt = int64(int16(c - d))
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002278 v.AddArg(v0)
2279 v.AddArg(x)
2280 return true
2281 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002282 // match: (Eq16 x (Const16 <t> [c]))
2283 // cond: x.Op != OpConst16
2284 // result: (Eq16 (Const16 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01002285 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002286 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07002287 v_1 := v.Args[1]
2288 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002289 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002290 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002291 t := v_1.Type
2292 c := v_1.AuxInt
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002293 if !(x.Op != OpConst16) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002294 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002295 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002296 v.reset(OpEq16)
Todd Neal93a0b0f2016-02-03 06:21:24 -05002297 v0 := b.NewValue0(v.Line, OpConst16, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002298 v0.AuxInt = c
2299 v.AddArg(v0)
2300 v.AddArg(x)
2301 return true
2302 }
Todd Nealcdc36252015-10-27 17:46:53 -05002303 // match: (Eq16 (Const16 [c]) (Const16 [d]))
2304 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07002305 // result: (ConstBool [b2i(c == d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002306 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07002307 v_0 := v.Args[0]
2308 if v_0.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002309 break
Todd Nealcdc36252015-10-27 17:46:53 -05002310 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002311 c := v_0.AuxInt
2312 v_1 := v.Args[1]
2313 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002314 break
Todd Nealcdc36252015-10-27 17:46:53 -05002315 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002316 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002317 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07002318 v.AuxInt = b2i(c == d)
Todd Nealcdc36252015-10-27 17:46:53 -05002319 return true
2320 }
Keith Randalla347ab72015-10-26 21:49:31 -07002321 return false
2322}
2323func rewriteValuegeneric_OpEq32(v *Value, config *Config) bool {
2324 b := v.Block
2325 _ = b
2326 // match: (Eq32 x x)
2327 // cond:
2328 // result: (ConstBool [1])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002329 for {
Keith Randalla347ab72015-10-26 21:49:31 -07002330 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07002331 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002332 break
Keith Randalla347ab72015-10-26 21:49:31 -07002333 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002334 v.reset(OpConstBool)
Keith Randalla347ab72015-10-26 21:49:31 -07002335 v.AuxInt = 1
2336 return true
2337 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002338 // match: (Eq32 (Const32 <t> [c]) (Add32 (Const32 <t> [d]) x))
2339 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07002340 // result: (Eq32 (Const32 <t> [int64(int32(c-d))]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01002341 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07002342 v_0 := v.Args[0]
2343 if v_0.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002344 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002345 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002346 t := v_0.Type
2347 c := v_0.AuxInt
2348 v_1 := v.Args[1]
2349 if v_1.Op != OpAdd32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002350 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002351 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002352 v_1_0 := v_1.Args[0]
2353 if v_1_0.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002354 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002355 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002356 if v_1_0.Type != t {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002357 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002358 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002359 d := v_1_0.AuxInt
2360 x := v_1.Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002361 v.reset(OpEq32)
Todd Neal93a0b0f2016-02-03 06:21:24 -05002362 v0 := b.NewValue0(v.Line, OpConst32, t)
Keith Randall7fc56212016-03-29 16:39:53 -07002363 v0.AuxInt = int64(int32(c - d))
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002364 v.AddArg(v0)
2365 v.AddArg(x)
2366 return true
2367 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002368 // match: (Eq32 x (Const32 <t> [c]))
2369 // cond: x.Op != OpConst32
2370 // result: (Eq32 (Const32 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01002371 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002372 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07002373 v_1 := v.Args[1]
2374 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002375 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002376 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002377 t := v_1.Type
2378 c := v_1.AuxInt
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002379 if !(x.Op != OpConst32) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002380 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002381 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002382 v.reset(OpEq32)
Todd Neal93a0b0f2016-02-03 06:21:24 -05002383 v0 := b.NewValue0(v.Line, OpConst32, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002384 v0.AuxInt = c
2385 v.AddArg(v0)
2386 v.AddArg(x)
2387 return true
2388 }
Todd Nealcdc36252015-10-27 17:46:53 -05002389 // match: (Eq32 (Const32 [c]) (Const32 [d]))
2390 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07002391 // result: (ConstBool [b2i(c == d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002392 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07002393 v_0 := v.Args[0]
2394 if v_0.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002395 break
Todd Nealcdc36252015-10-27 17:46:53 -05002396 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002397 c := v_0.AuxInt
2398 v_1 := v.Args[1]
2399 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002400 break
Todd Nealcdc36252015-10-27 17:46:53 -05002401 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002402 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002403 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07002404 v.AuxInt = b2i(c == d)
Todd Nealcdc36252015-10-27 17:46:53 -05002405 return true
2406 }
Keith Randalla347ab72015-10-26 21:49:31 -07002407 return false
2408}
2409func rewriteValuegeneric_OpEq64(v *Value, config *Config) bool {
2410 b := v.Block
2411 _ = b
2412 // match: (Eq64 x x)
2413 // cond:
2414 // result: (ConstBool [1])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002415 for {
Keith Randalla347ab72015-10-26 21:49:31 -07002416 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07002417 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002418 break
Keith Randalla347ab72015-10-26 21:49:31 -07002419 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002420 v.reset(OpConstBool)
Keith Randalla347ab72015-10-26 21:49:31 -07002421 v.AuxInt = 1
2422 return true
2423 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002424 // match: (Eq64 (Const64 <t> [c]) (Add64 (Const64 <t> [d]) x))
2425 // cond:
2426 // result: (Eq64 (Const64 <t> [c-d]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01002427 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07002428 v_0 := v.Args[0]
2429 if v_0.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002430 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002431 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002432 t := v_0.Type
2433 c := v_0.AuxInt
2434 v_1 := v.Args[1]
2435 if v_1.Op != OpAdd64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002436 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002437 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002438 v_1_0 := v_1.Args[0]
2439 if v_1_0.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002440 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002441 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002442 if v_1_0.Type != t {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002443 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002444 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002445 d := v_1_0.AuxInt
2446 x := v_1.Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002447 v.reset(OpEq64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05002448 v0 := b.NewValue0(v.Line, OpConst64, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002449 v0.AuxInt = c - d
2450 v.AddArg(v0)
2451 v.AddArg(x)
2452 return true
2453 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002454 // match: (Eq64 x (Const64 <t> [c]))
2455 // cond: x.Op != OpConst64
2456 // result: (Eq64 (Const64 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01002457 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002458 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07002459 v_1 := v.Args[1]
2460 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002461 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002462 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002463 t := v_1.Type
2464 c := v_1.AuxInt
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002465 if !(x.Op != OpConst64) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002466 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002467 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002468 v.reset(OpEq64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05002469 v0 := b.NewValue0(v.Line, OpConst64, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002470 v0.AuxInt = c
2471 v.AddArg(v0)
2472 v.AddArg(x)
2473 return true
2474 }
Todd Nealcdc36252015-10-27 17:46:53 -05002475 // match: (Eq64 (Const64 [c]) (Const64 [d]))
2476 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07002477 // result: (ConstBool [b2i(c == d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002478 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07002479 v_0 := v.Args[0]
2480 if v_0.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002481 break
Todd Nealcdc36252015-10-27 17:46:53 -05002482 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002483 c := v_0.AuxInt
2484 v_1 := v.Args[1]
2485 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002486 break
Todd Nealcdc36252015-10-27 17:46:53 -05002487 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002488 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002489 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07002490 v.AuxInt = b2i(c == d)
Todd Nealcdc36252015-10-27 17:46:53 -05002491 return true
2492 }
Keith Randalla347ab72015-10-26 21:49:31 -07002493 return false
2494}
2495func rewriteValuegeneric_OpEq8(v *Value, config *Config) bool {
2496 b := v.Block
2497 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07002498 // match: (Eq8 x x)
Keith Randalla347ab72015-10-26 21:49:31 -07002499 // cond:
2500 // result: (ConstBool [1])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002501 for {
Keith Randalla347ab72015-10-26 21:49:31 -07002502 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07002503 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002504 break
Keith Randalla347ab72015-10-26 21:49:31 -07002505 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002506 v.reset(OpConstBool)
Keith Randalla347ab72015-10-26 21:49:31 -07002507 v.AuxInt = 1
2508 return true
2509 }
Keith Randallfa9435c2016-04-26 12:08:31 -07002510 // match: (Eq8 (Const8 <t> [c]) (Add8 (Const8 <t> [d]) x))
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002511 // cond:
Keith Randallfa9435c2016-04-26 12:08:31 -07002512 // result: (Eq8 (Const8 <t> [int64(int8(c-d))]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01002513 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07002514 v_0 := v.Args[0]
2515 if v_0.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002516 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002517 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002518 t := v_0.Type
2519 c := v_0.AuxInt
2520 v_1 := v.Args[1]
2521 if v_1.Op != OpAdd8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002522 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002523 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002524 v_1_0 := v_1.Args[0]
2525 if v_1_0.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002526 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002527 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002528 if v_1_0.Type != t {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002529 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002530 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002531 d := v_1_0.AuxInt
2532 x := v_1.Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002533 v.reset(OpEq8)
Todd Neal93a0b0f2016-02-03 06:21:24 -05002534 v0 := b.NewValue0(v.Line, OpConst8, t)
Keith Randall7fc56212016-03-29 16:39:53 -07002535 v0.AuxInt = int64(int8(c - d))
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002536 v.AddArg(v0)
2537 v.AddArg(x)
2538 return true
2539 }
Keith Randallfa9435c2016-04-26 12:08:31 -07002540 // match: (Eq8 x (Const8 <t> [c]))
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002541 // cond: x.Op != OpConst8
Keith Randallfa9435c2016-04-26 12:08:31 -07002542 // result: (Eq8 (Const8 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01002543 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002544 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07002545 v_1 := v.Args[1]
2546 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002547 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002548 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002549 t := v_1.Type
2550 c := v_1.AuxInt
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002551 if !(x.Op != OpConst8) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002552 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002553 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002554 v.reset(OpEq8)
Todd Neal93a0b0f2016-02-03 06:21:24 -05002555 v0 := b.NewValue0(v.Line, OpConst8, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002556 v0.AuxInt = c
2557 v.AddArg(v0)
2558 v.AddArg(x)
2559 return true
2560 }
Todd Nealcdc36252015-10-27 17:46:53 -05002561 // match: (Eq8 (Const8 [c]) (Const8 [d]))
2562 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07002563 // result: (ConstBool [b2i(c == d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002564 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07002565 v_0 := v.Args[0]
2566 if v_0.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002567 break
Todd Nealcdc36252015-10-27 17:46:53 -05002568 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002569 c := v_0.AuxInt
2570 v_1 := v.Args[1]
2571 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002572 break
Todd Nealcdc36252015-10-27 17:46:53 -05002573 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002574 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002575 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07002576 v.AuxInt = b2i(c == d)
Todd Nealcdc36252015-10-27 17:46:53 -05002577 return true
2578 }
Keith Randalla347ab72015-10-26 21:49:31 -07002579 return false
2580}
Alexandru Moșoi8b923972016-04-24 21:21:07 +02002581func rewriteValuegeneric_OpEqB(v *Value, config *Config) bool {
2582 b := v.Block
2583 _ = b
2584 // match: (EqB (ConstBool [c]) (ConstBool [d]))
2585 // cond:
2586 // result: (ConstBool [b2i(c == d)])
2587 for {
2588 v_0 := v.Args[0]
2589 if v_0.Op != OpConstBool {
2590 break
2591 }
2592 c := v_0.AuxInt
2593 v_1 := v.Args[1]
2594 if v_1.Op != OpConstBool {
2595 break
2596 }
2597 d := v_1.AuxInt
2598 v.reset(OpConstBool)
2599 v.AuxInt = b2i(c == d)
2600 return true
2601 }
2602 // match: (EqB (ConstBool [0]) x)
2603 // cond:
2604 // result: (Not x)
2605 for {
2606 v_0 := v.Args[0]
2607 if v_0.Op != OpConstBool {
2608 break
2609 }
2610 if v_0.AuxInt != 0 {
2611 break
2612 }
2613 x := v.Args[1]
2614 v.reset(OpNot)
2615 v.AddArg(x)
2616 return true
2617 }
2618 // match: (EqB (ConstBool [1]) x)
2619 // cond:
2620 // result: x
2621 for {
2622 v_0 := v.Args[0]
2623 if v_0.Op != OpConstBool {
2624 break
2625 }
2626 if v_0.AuxInt != 1 {
2627 break
2628 }
2629 x := v.Args[1]
2630 v.reset(OpCopy)
2631 v.Type = x.Type
2632 v.AddArg(x)
2633 return true
2634 }
2635 return false
2636}
Keith Randalla347ab72015-10-26 21:49:31 -07002637func rewriteValuegeneric_OpEqInter(v *Value, config *Config) bool {
2638 b := v.Block
2639 _ = b
2640 // match: (EqInter x y)
2641 // cond:
2642 // result: (EqPtr (ITab x) (ITab y))
Alexandru Moșoi05434472016-02-04 19:52:10 +01002643 for {
Keith Randalla347ab72015-10-26 21:49:31 -07002644 x := v.Args[0]
2645 y := v.Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002646 v.reset(OpEqPtr)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01002647 v0 := b.NewValue0(v.Line, OpITab, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07002648 v0.AddArg(x)
Keith Randalla347ab72015-10-26 21:49:31 -07002649 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01002650 v1 := b.NewValue0(v.Line, OpITab, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07002651 v1.AddArg(y)
Keith Randalla347ab72015-10-26 21:49:31 -07002652 v.AddArg(v1)
2653 return true
2654 }
Keith Randalla347ab72015-10-26 21:49:31 -07002655}
2656func rewriteValuegeneric_OpEqPtr(v *Value, config *Config) bool {
2657 b := v.Block
2658 _ = b
2659 // match: (EqPtr p (ConstNil))
2660 // cond:
2661 // result: (Not (IsNonNil p))
Alexandru Moșoi05434472016-02-04 19:52:10 +01002662 for {
Keith Randalla347ab72015-10-26 21:49:31 -07002663 p := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07002664 v_1 := v.Args[1]
2665 if v_1.Op != OpConstNil {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002666 break
Keith Randalla347ab72015-10-26 21:49:31 -07002667 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002668 v.reset(OpNot)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01002669 v0 := b.NewValue0(v.Line, OpIsNonNil, config.fe.TypeBool())
Keith Randalla347ab72015-10-26 21:49:31 -07002670 v0.AddArg(p)
Keith Randalla347ab72015-10-26 21:49:31 -07002671 v.AddArg(v0)
2672 return true
2673 }
Keith Randalla347ab72015-10-26 21:49:31 -07002674 // match: (EqPtr (ConstNil) p)
2675 // cond:
2676 // result: (Not (IsNonNil p))
Alexandru Moșoi05434472016-02-04 19:52:10 +01002677 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07002678 v_0 := v.Args[0]
2679 if v_0.Op != OpConstNil {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002680 break
Keith Randalla347ab72015-10-26 21:49:31 -07002681 }
2682 p := v.Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002683 v.reset(OpNot)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01002684 v0 := b.NewValue0(v.Line, OpIsNonNil, config.fe.TypeBool())
Keith Randalla347ab72015-10-26 21:49:31 -07002685 v0.AddArg(p)
Keith Randalla347ab72015-10-26 21:49:31 -07002686 v.AddArg(v0)
2687 return true
2688 }
Keith Randalla347ab72015-10-26 21:49:31 -07002689 return false
2690}
2691func rewriteValuegeneric_OpEqSlice(v *Value, config *Config) bool {
2692 b := v.Block
2693 _ = b
2694 // match: (EqSlice x y)
2695 // cond:
2696 // result: (EqPtr (SlicePtr x) (SlicePtr y))
Alexandru Moșoi05434472016-02-04 19:52:10 +01002697 for {
Keith Randalla347ab72015-10-26 21:49:31 -07002698 x := v.Args[0]
2699 y := v.Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002700 v.reset(OpEqPtr)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01002701 v0 := b.NewValue0(v.Line, OpSlicePtr, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07002702 v0.AddArg(x)
Keith Randalla347ab72015-10-26 21:49:31 -07002703 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01002704 v1 := b.NewValue0(v.Line, OpSlicePtr, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07002705 v1.AddArg(y)
Keith Randalla347ab72015-10-26 21:49:31 -07002706 v.AddArg(v1)
2707 return true
2708 }
Keith Randalla347ab72015-10-26 21:49:31 -07002709}
Todd Nealcdc36252015-10-27 17:46:53 -05002710func rewriteValuegeneric_OpGeq16(v *Value, config *Config) bool {
2711 b := v.Block
2712 _ = b
2713 // match: (Geq16 (Const16 [c]) (Const16 [d]))
2714 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07002715 // result: (ConstBool [b2i(c >= d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002716 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07002717 v_0 := v.Args[0]
2718 if v_0.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002719 break
Todd Nealcdc36252015-10-27 17:46:53 -05002720 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002721 c := v_0.AuxInt
2722 v_1 := v.Args[1]
2723 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002724 break
Todd Nealcdc36252015-10-27 17:46:53 -05002725 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002726 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002727 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07002728 v.AuxInt = b2i(c >= d)
Todd Nealcdc36252015-10-27 17:46:53 -05002729 return true
2730 }
Todd Nealcdc36252015-10-27 17:46:53 -05002731 return false
2732}
2733func rewriteValuegeneric_OpGeq16U(v *Value, config *Config) bool {
2734 b := v.Block
2735 _ = b
2736 // match: (Geq16U (Const16 [c]) (Const16 [d]))
2737 // cond:
2738 // result: (ConstBool [b2i(uint16(c) >= uint16(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002739 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07002740 v_0 := v.Args[0]
2741 if v_0.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002742 break
Todd Nealcdc36252015-10-27 17:46:53 -05002743 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002744 c := v_0.AuxInt
2745 v_1 := v.Args[1]
2746 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002747 break
Todd Nealcdc36252015-10-27 17:46:53 -05002748 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002749 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002750 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002751 v.AuxInt = b2i(uint16(c) >= uint16(d))
2752 return true
2753 }
Todd Nealcdc36252015-10-27 17:46:53 -05002754 return false
2755}
2756func rewriteValuegeneric_OpGeq32(v *Value, config *Config) bool {
2757 b := v.Block
2758 _ = b
2759 // match: (Geq32 (Const32 [c]) (Const32 [d]))
2760 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07002761 // result: (ConstBool [b2i(c >= d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002762 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07002763 v_0 := v.Args[0]
2764 if v_0.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002765 break
Todd Nealcdc36252015-10-27 17:46:53 -05002766 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002767 c := v_0.AuxInt
2768 v_1 := v.Args[1]
2769 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002770 break
Todd Nealcdc36252015-10-27 17:46:53 -05002771 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002772 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002773 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07002774 v.AuxInt = b2i(c >= d)
Todd Nealcdc36252015-10-27 17:46:53 -05002775 return true
2776 }
Todd Nealcdc36252015-10-27 17:46:53 -05002777 return false
2778}
2779func rewriteValuegeneric_OpGeq32U(v *Value, config *Config) bool {
2780 b := v.Block
2781 _ = b
2782 // match: (Geq32U (Const32 [c]) (Const32 [d]))
2783 // cond:
2784 // result: (ConstBool [b2i(uint32(c) >= uint32(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002785 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07002786 v_0 := v.Args[0]
2787 if v_0.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002788 break
Todd Nealcdc36252015-10-27 17:46:53 -05002789 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002790 c := v_0.AuxInt
2791 v_1 := v.Args[1]
2792 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002793 break
Todd Nealcdc36252015-10-27 17:46:53 -05002794 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002795 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002796 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002797 v.AuxInt = b2i(uint32(c) >= uint32(d))
2798 return true
2799 }
Todd Nealcdc36252015-10-27 17:46:53 -05002800 return false
2801}
2802func rewriteValuegeneric_OpGeq64(v *Value, config *Config) bool {
2803 b := v.Block
2804 _ = b
2805 // match: (Geq64 (Const64 [c]) (Const64 [d]))
2806 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07002807 // result: (ConstBool [b2i(c >= d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002808 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07002809 v_0 := v.Args[0]
2810 if v_0.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002811 break
Todd Nealcdc36252015-10-27 17:46:53 -05002812 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002813 c := v_0.AuxInt
2814 v_1 := v.Args[1]
2815 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002816 break
Todd Nealcdc36252015-10-27 17:46:53 -05002817 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002818 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002819 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07002820 v.AuxInt = b2i(c >= d)
Todd Nealcdc36252015-10-27 17:46:53 -05002821 return true
2822 }
Todd Nealcdc36252015-10-27 17:46:53 -05002823 return false
2824}
2825func rewriteValuegeneric_OpGeq64U(v *Value, config *Config) bool {
2826 b := v.Block
2827 _ = b
2828 // match: (Geq64U (Const64 [c]) (Const64 [d]))
2829 // cond:
2830 // result: (ConstBool [b2i(uint64(c) >= uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002831 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07002832 v_0 := v.Args[0]
2833 if v_0.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002834 break
Todd Nealcdc36252015-10-27 17:46:53 -05002835 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002836 c := v_0.AuxInt
2837 v_1 := v.Args[1]
2838 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002839 break
Todd Nealcdc36252015-10-27 17:46:53 -05002840 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002841 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002842 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002843 v.AuxInt = b2i(uint64(c) >= uint64(d))
2844 return true
2845 }
Todd Nealcdc36252015-10-27 17:46:53 -05002846 return false
2847}
2848func rewriteValuegeneric_OpGeq8(v *Value, config *Config) bool {
2849 b := v.Block
2850 _ = b
2851 // match: (Geq8 (Const8 [c]) (Const8 [d]))
2852 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07002853 // result: (ConstBool [b2i(c >= d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002854 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07002855 v_0 := v.Args[0]
2856 if v_0.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002857 break
Todd Nealcdc36252015-10-27 17:46:53 -05002858 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002859 c := v_0.AuxInt
2860 v_1 := v.Args[1]
2861 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002862 break
Todd Nealcdc36252015-10-27 17:46:53 -05002863 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002864 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002865 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07002866 v.AuxInt = b2i(c >= d)
Todd Nealcdc36252015-10-27 17:46:53 -05002867 return true
2868 }
Todd Nealcdc36252015-10-27 17:46:53 -05002869 return false
2870}
2871func rewriteValuegeneric_OpGeq8U(v *Value, config *Config) bool {
2872 b := v.Block
2873 _ = b
2874 // match: (Geq8U (Const8 [c]) (Const8 [d]))
2875 // cond:
2876 // result: (ConstBool [b2i(uint8(c) >= uint8(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002877 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07002878 v_0 := v.Args[0]
2879 if v_0.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002880 break
Todd Nealcdc36252015-10-27 17:46:53 -05002881 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002882 c := v_0.AuxInt
2883 v_1 := v.Args[1]
2884 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002885 break
Todd Nealcdc36252015-10-27 17:46:53 -05002886 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002887 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002888 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002889 v.AuxInt = b2i(uint8(c) >= uint8(d))
2890 return true
2891 }
Todd Nealcdc36252015-10-27 17:46:53 -05002892 return false
2893}
2894func rewriteValuegeneric_OpGreater16(v *Value, config *Config) bool {
2895 b := v.Block
2896 _ = b
2897 // match: (Greater16 (Const16 [c]) (Const16 [d]))
2898 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07002899 // result: (ConstBool [b2i(c > d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002900 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07002901 v_0 := v.Args[0]
2902 if v_0.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002903 break
Todd Nealcdc36252015-10-27 17:46:53 -05002904 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002905 c := v_0.AuxInt
2906 v_1 := v.Args[1]
2907 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002908 break
Todd Nealcdc36252015-10-27 17:46:53 -05002909 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002910 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002911 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07002912 v.AuxInt = b2i(c > d)
Todd Nealcdc36252015-10-27 17:46:53 -05002913 return true
2914 }
Todd Nealcdc36252015-10-27 17:46:53 -05002915 return false
2916}
2917func rewriteValuegeneric_OpGreater16U(v *Value, config *Config) bool {
2918 b := v.Block
2919 _ = b
2920 // match: (Greater16U (Const16 [c]) (Const16 [d]))
2921 // cond:
2922 // result: (ConstBool [b2i(uint16(c) > uint16(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002923 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07002924 v_0 := v.Args[0]
2925 if v_0.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002926 break
Todd Nealcdc36252015-10-27 17:46:53 -05002927 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002928 c := v_0.AuxInt
2929 v_1 := v.Args[1]
2930 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002931 break
Todd Nealcdc36252015-10-27 17:46:53 -05002932 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002933 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002934 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002935 v.AuxInt = b2i(uint16(c) > uint16(d))
2936 return true
2937 }
Todd Nealcdc36252015-10-27 17:46:53 -05002938 return false
2939}
2940func rewriteValuegeneric_OpGreater32(v *Value, config *Config) bool {
2941 b := v.Block
2942 _ = b
2943 // match: (Greater32 (Const32 [c]) (Const32 [d]))
2944 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07002945 // result: (ConstBool [b2i(c > d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002946 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07002947 v_0 := v.Args[0]
2948 if v_0.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002949 break
Todd Nealcdc36252015-10-27 17:46:53 -05002950 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002951 c := v_0.AuxInt
2952 v_1 := v.Args[1]
2953 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002954 break
Todd Nealcdc36252015-10-27 17:46:53 -05002955 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002956 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002957 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07002958 v.AuxInt = b2i(c > d)
Todd Nealcdc36252015-10-27 17:46:53 -05002959 return true
2960 }
Todd Nealcdc36252015-10-27 17:46:53 -05002961 return false
2962}
2963func rewriteValuegeneric_OpGreater32U(v *Value, config *Config) bool {
2964 b := v.Block
2965 _ = b
2966 // match: (Greater32U (Const32 [c]) (Const32 [d]))
2967 // cond:
2968 // result: (ConstBool [b2i(uint32(c) > uint32(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002969 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07002970 v_0 := v.Args[0]
2971 if v_0.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002972 break
Todd Nealcdc36252015-10-27 17:46:53 -05002973 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002974 c := v_0.AuxInt
2975 v_1 := v.Args[1]
2976 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002977 break
Todd Nealcdc36252015-10-27 17:46:53 -05002978 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002979 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002980 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002981 v.AuxInt = b2i(uint32(c) > uint32(d))
2982 return true
2983 }
Todd Nealcdc36252015-10-27 17:46:53 -05002984 return false
2985}
2986func rewriteValuegeneric_OpGreater64(v *Value, config *Config) bool {
2987 b := v.Block
2988 _ = b
2989 // match: (Greater64 (Const64 [c]) (Const64 [d]))
2990 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07002991 // result: (ConstBool [b2i(c > d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002992 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07002993 v_0 := v.Args[0]
2994 if v_0.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002995 break
Todd Nealcdc36252015-10-27 17:46:53 -05002996 }
Keith Randall259b7ed2016-03-21 16:18:45 -07002997 c := v_0.AuxInt
2998 v_1 := v.Args[1]
2999 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003000 break
Todd Nealcdc36252015-10-27 17:46:53 -05003001 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003002 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003003 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07003004 v.AuxInt = b2i(c > d)
Todd Nealcdc36252015-10-27 17:46:53 -05003005 return true
3006 }
Todd Nealcdc36252015-10-27 17:46:53 -05003007 return false
3008}
3009func rewriteValuegeneric_OpGreater64U(v *Value, config *Config) bool {
3010 b := v.Block
3011 _ = b
3012 // match: (Greater64U (Const64 [c]) (Const64 [d]))
3013 // cond:
3014 // result: (ConstBool [b2i(uint64(c) > uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003015 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003016 v_0 := v.Args[0]
3017 if v_0.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003018 break
Todd Nealcdc36252015-10-27 17:46:53 -05003019 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003020 c := v_0.AuxInt
3021 v_1 := v.Args[1]
3022 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003023 break
Todd Nealcdc36252015-10-27 17:46:53 -05003024 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003025 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003026 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05003027 v.AuxInt = b2i(uint64(c) > uint64(d))
3028 return true
3029 }
Todd Nealcdc36252015-10-27 17:46:53 -05003030 return false
3031}
3032func rewriteValuegeneric_OpGreater8(v *Value, config *Config) bool {
3033 b := v.Block
3034 _ = b
3035 // match: (Greater8 (Const8 [c]) (Const8 [d]))
3036 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07003037 // result: (ConstBool [b2i(c > d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003038 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003039 v_0 := v.Args[0]
3040 if v_0.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003041 break
Todd Nealcdc36252015-10-27 17:46:53 -05003042 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003043 c := v_0.AuxInt
3044 v_1 := v.Args[1]
3045 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003046 break
Todd Nealcdc36252015-10-27 17:46:53 -05003047 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003048 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003049 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07003050 v.AuxInt = b2i(c > d)
Todd Nealcdc36252015-10-27 17:46:53 -05003051 return true
3052 }
Todd Nealcdc36252015-10-27 17:46:53 -05003053 return false
3054}
3055func rewriteValuegeneric_OpGreater8U(v *Value, config *Config) bool {
3056 b := v.Block
3057 _ = b
3058 // match: (Greater8U (Const8 [c]) (Const8 [d]))
3059 // cond:
3060 // result: (ConstBool [b2i(uint8(c) > uint8(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003061 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003062 v_0 := v.Args[0]
3063 if v_0.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003064 break
Todd Nealcdc36252015-10-27 17:46:53 -05003065 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003066 c := v_0.AuxInt
3067 v_1 := v.Args[1]
3068 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003069 break
Todd Nealcdc36252015-10-27 17:46:53 -05003070 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003071 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003072 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05003073 v.AuxInt = b2i(uint8(c) > uint8(d))
3074 return true
3075 }
Todd Nealcdc36252015-10-27 17:46:53 -05003076 return false
3077}
Keith Randalla347ab72015-10-26 21:49:31 -07003078func rewriteValuegeneric_OpIsInBounds(v *Value, config *Config) bool {
3079 b := v.Block
3080 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07003081 // match: (IsInBounds (ZeroExt8to32 _) (Const32 [c]))
3082 // cond: (1 << 8) <= c
Alexandru Moșoi9549c062016-03-20 22:15:27 +01003083 // result: (ConstBool [1])
3084 for {
Alexandru Moșoie61db312016-03-22 17:34:36 +01003085 v_0 := v.Args[0]
3086 if v_0.Op != OpZeroExt8to32 {
Alexandru Moșoi9549c062016-03-20 22:15:27 +01003087 break
3088 }
Alexandru Moșoie61db312016-03-22 17:34:36 +01003089 v_1 := v.Args[1]
3090 if v_1.Op != OpConst32 {
Alexandru Moșoi9549c062016-03-20 22:15:27 +01003091 break
3092 }
Alexandru Moșoie61db312016-03-22 17:34:36 +01003093 c := v_1.AuxInt
Keith Randall7fc56212016-03-29 16:39:53 -07003094 if !((1 << 8) <= c) {
Alexandru Moșoi9549c062016-03-20 22:15:27 +01003095 break
3096 }
3097 v.reset(OpConstBool)
3098 v.AuxInt = 1
3099 return true
3100 }
Keith Randallfa9435c2016-04-26 12:08:31 -07003101 // match: (IsInBounds (ZeroExt8to64 _) (Const64 [c]))
3102 // cond: (1 << 8) <= c
Alexandru Moșoi9549c062016-03-20 22:15:27 +01003103 // result: (ConstBool [1])
3104 for {
Alexandru Moșoie61db312016-03-22 17:34:36 +01003105 v_0 := v.Args[0]
3106 if v_0.Op != OpZeroExt8to64 {
Alexandru Moșoi9549c062016-03-20 22:15:27 +01003107 break
3108 }
Alexandru Moșoie61db312016-03-22 17:34:36 +01003109 v_1 := v.Args[1]
3110 if v_1.Op != OpConst64 {
Alexandru Moșoi9549c062016-03-20 22:15:27 +01003111 break
3112 }
Alexandru Moșoie61db312016-03-22 17:34:36 +01003113 c := v_1.AuxInt
Alexandru Moșoi9549c062016-03-20 22:15:27 +01003114 if !((1 << 8) <= c) {
3115 break
3116 }
3117 v.reset(OpConstBool)
3118 v.AuxInt = 1
3119 return true
3120 }
3121 // match: (IsInBounds (ZeroExt16to32 _) (Const32 [c]))
Keith Randall7fc56212016-03-29 16:39:53 -07003122 // cond: (1 << 16) <= c
Alexandru Moșoi9549c062016-03-20 22:15:27 +01003123 // result: (ConstBool [1])
3124 for {
Alexandru Moșoie61db312016-03-22 17:34:36 +01003125 v_0 := v.Args[0]
3126 if v_0.Op != OpZeroExt16to32 {
Alexandru Moșoi9549c062016-03-20 22:15:27 +01003127 break
3128 }
Alexandru Moșoie61db312016-03-22 17:34:36 +01003129 v_1 := v.Args[1]
3130 if v_1.Op != OpConst32 {
Alexandru Moșoi9549c062016-03-20 22:15:27 +01003131 break
3132 }
Alexandru Moșoie61db312016-03-22 17:34:36 +01003133 c := v_1.AuxInt
Keith Randall7fc56212016-03-29 16:39:53 -07003134 if !((1 << 16) <= c) {
Alexandru Moșoi9549c062016-03-20 22:15:27 +01003135 break
3136 }
3137 v.reset(OpConstBool)
3138 v.AuxInt = 1
3139 return true
3140 }
3141 // match: (IsInBounds (ZeroExt16to64 _) (Const64 [c]))
3142 // cond: (1 << 16) <= c
3143 // result: (ConstBool [1])
3144 for {
Alexandru Moșoie61db312016-03-22 17:34:36 +01003145 v_0 := v.Args[0]
3146 if v_0.Op != OpZeroExt16to64 {
Alexandru Moșoi9549c062016-03-20 22:15:27 +01003147 break
3148 }
Alexandru Moșoie61db312016-03-22 17:34:36 +01003149 v_1 := v.Args[1]
3150 if v_1.Op != OpConst64 {
Alexandru Moșoi9549c062016-03-20 22:15:27 +01003151 break
3152 }
Alexandru Moșoie61db312016-03-22 17:34:36 +01003153 c := v_1.AuxInt
Alexandru Moșoi9549c062016-03-20 22:15:27 +01003154 if !((1 << 16) <= c) {
3155 break
3156 }
3157 v.reset(OpConstBool)
3158 v.AuxInt = 1
3159 return true
3160 }
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01003161 // match: (IsInBounds x x)
3162 // cond:
3163 // result: (ConstBool [0])
3164 for {
3165 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07003166 if x != v.Args[1] {
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01003167 break
3168 }
3169 v.reset(OpConstBool)
3170 v.AuxInt = 0
3171 return true
3172 }
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01003173 // match: (IsInBounds (And32 (Const32 [c]) _) (Const32 [d]))
Keith Randall7fc56212016-03-29 16:39:53 -07003174 // cond: 0 <= c && c < d
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01003175 // result: (ConstBool [1])
3176 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003177 v_0 := v.Args[0]
3178 if v_0.Op != OpAnd32 {
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01003179 break
3180 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003181 v_0_0 := v_0.Args[0]
3182 if v_0_0.Op != OpConst32 {
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01003183 break
3184 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003185 c := v_0_0.AuxInt
3186 v_1 := v.Args[1]
3187 if v_1.Op != OpConst32 {
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01003188 break
3189 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003190 d := v_1.AuxInt
Keith Randall7fc56212016-03-29 16:39:53 -07003191 if !(0 <= c && c < d) {
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01003192 break
3193 }
3194 v.reset(OpConstBool)
3195 v.AuxInt = 1
3196 return true
3197 }
3198 // match: (IsInBounds (And64 (Const64 [c]) _) (Const64 [d]))
Keith Randall7fc56212016-03-29 16:39:53 -07003199 // cond: 0 <= c && c < d
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01003200 // result: (ConstBool [1])
3201 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003202 v_0 := v.Args[0]
3203 if v_0.Op != OpAnd64 {
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01003204 break
3205 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003206 v_0_0 := v_0.Args[0]
3207 if v_0_0.Op != OpConst64 {
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01003208 break
3209 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003210 c := v_0_0.AuxInt
3211 v_1 := v.Args[1]
3212 if v_1.Op != OpConst64 {
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01003213 break
3214 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003215 d := v_1.AuxInt
Keith Randall7fc56212016-03-29 16:39:53 -07003216 if !(0 <= c && c < d) {
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01003217 break
3218 }
3219 v.reset(OpConstBool)
3220 v.AuxInt = 1
3221 return true
3222 }
Keith Randalla347ab72015-10-26 21:49:31 -07003223 // match: (IsInBounds (Const32 [c]) (Const32 [d]))
3224 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07003225 // result: (ConstBool [b2i(0 <= c && c < d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003226 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003227 v_0 := v.Args[0]
3228 if v_0.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003229 break
Keith Randalla347ab72015-10-26 21:49:31 -07003230 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003231 c := v_0.AuxInt
3232 v_1 := v.Args[1]
3233 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003234 break
Keith Randalla347ab72015-10-26 21:49:31 -07003235 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003236 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003237 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07003238 v.AuxInt = b2i(0 <= c && c < d)
Keith Randalla347ab72015-10-26 21:49:31 -07003239 return true
3240 }
Keith Randalla347ab72015-10-26 21:49:31 -07003241 // match: (IsInBounds (Const64 [c]) (Const64 [d]))
3242 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07003243 // result: (ConstBool [b2i(0 <= c && c < d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003244 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003245 v_0 := v.Args[0]
3246 if v_0.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003247 break
Keith Randalla347ab72015-10-26 21:49:31 -07003248 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003249 c := v_0.AuxInt
3250 v_1 := v.Args[1]
3251 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003252 break
Keith Randalla347ab72015-10-26 21:49:31 -07003253 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003254 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003255 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07003256 v.AuxInt = b2i(0 <= c && c < d)
Keith Randalla347ab72015-10-26 21:49:31 -07003257 return true
3258 }
Alexandru Moșoi68325b52016-04-04 16:38:26 +02003259 // match: (IsInBounds (Mod32u _ y) y)
3260 // cond:
3261 // result: (ConstBool [1])
3262 for {
3263 v_0 := v.Args[0]
3264 if v_0.Op != OpMod32u {
3265 break
3266 }
3267 y := v_0.Args[1]
3268 if y != v.Args[1] {
3269 break
3270 }
3271 v.reset(OpConstBool)
3272 v.AuxInt = 1
3273 return true
3274 }
3275 // match: (IsInBounds (Mod64u _ y) y)
3276 // cond:
3277 // result: (ConstBool [1])
3278 for {
3279 v_0 := v.Args[0]
3280 if v_0.Op != OpMod64u {
3281 break
3282 }
3283 y := v_0.Args[1]
3284 if y != v.Args[1] {
3285 break
3286 }
3287 v.reset(OpConstBool)
3288 v.AuxInt = 1
3289 return true
3290 }
Keith Randall582baae2015-11-02 21:28:13 -08003291 return false
3292}
3293func rewriteValuegeneric_OpIsSliceInBounds(v *Value, config *Config) bool {
3294 b := v.Block
3295 _ = b
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01003296 // match: (IsSliceInBounds x x)
3297 // cond:
3298 // result: (ConstBool [1])
3299 for {
3300 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07003301 if x != v.Args[1] {
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01003302 break
3303 }
3304 v.reset(OpConstBool)
3305 v.AuxInt = 1
3306 return true
3307 }
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01003308 // match: (IsSliceInBounds (And32 (Const32 [c]) _) (Const32 [d]))
Keith Randall7fc56212016-03-29 16:39:53 -07003309 // cond: 0 <= c && c <= d
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01003310 // result: (ConstBool [1])
3311 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003312 v_0 := v.Args[0]
3313 if v_0.Op != OpAnd32 {
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01003314 break
3315 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003316 v_0_0 := v_0.Args[0]
3317 if v_0_0.Op != OpConst32 {
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01003318 break
3319 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003320 c := v_0_0.AuxInt
3321 v_1 := v.Args[1]
3322 if v_1.Op != OpConst32 {
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01003323 break
3324 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003325 d := v_1.AuxInt
Keith Randall7fc56212016-03-29 16:39:53 -07003326 if !(0 <= c && c <= d) {
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01003327 break
3328 }
3329 v.reset(OpConstBool)
3330 v.AuxInt = 1
3331 return true
3332 }
3333 // match: (IsSliceInBounds (And64 (Const64 [c]) _) (Const64 [d]))
Keith Randall7fc56212016-03-29 16:39:53 -07003334 // cond: 0 <= c && c <= d
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01003335 // result: (ConstBool [1])
3336 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003337 v_0 := v.Args[0]
3338 if v_0.Op != OpAnd64 {
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01003339 break
3340 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003341 v_0_0 := v_0.Args[0]
3342 if v_0_0.Op != OpConst64 {
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01003343 break
3344 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003345 c := v_0_0.AuxInt
3346 v_1 := v.Args[1]
3347 if v_1.Op != OpConst64 {
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01003348 break
3349 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003350 d := v_1.AuxInt
Keith Randall7fc56212016-03-29 16:39:53 -07003351 if !(0 <= c && c <= d) {
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01003352 break
3353 }
3354 v.reset(OpConstBool)
3355 v.AuxInt = 1
3356 return true
3357 }
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01003358 // match: (IsSliceInBounds (Const32 [0]) _)
3359 // cond:
3360 // result: (ConstBool [1])
3361 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003362 v_0 := v.Args[0]
3363 if v_0.Op != OpConst32 {
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01003364 break
3365 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003366 if v_0.AuxInt != 0 {
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01003367 break
3368 }
3369 v.reset(OpConstBool)
3370 v.AuxInt = 1
3371 return true
3372 }
3373 // match: (IsSliceInBounds (Const64 [0]) _)
3374 // cond:
3375 // result: (ConstBool [1])
3376 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003377 v_0 := v.Args[0]
3378 if v_0.Op != OpConst64 {
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01003379 break
3380 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003381 if v_0.AuxInt != 0 {
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01003382 break
3383 }
3384 v.reset(OpConstBool)
3385 v.AuxInt = 1
3386 return true
3387 }
Keith Randall582baae2015-11-02 21:28:13 -08003388 // match: (IsSliceInBounds (Const32 [c]) (Const32 [d]))
3389 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07003390 // result: (ConstBool [b2i(0 <= c && c <= d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003391 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003392 v_0 := v.Args[0]
3393 if v_0.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003394 break
Keith Randalla347ab72015-10-26 21:49:31 -07003395 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003396 c := v_0.AuxInt
3397 v_1 := v.Args[1]
3398 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003399 break
Keith Randalla347ab72015-10-26 21:49:31 -07003400 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003401 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003402 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07003403 v.AuxInt = b2i(0 <= c && c <= d)
Keith Randalla347ab72015-10-26 21:49:31 -07003404 return true
3405 }
Keith Randall582baae2015-11-02 21:28:13 -08003406 // match: (IsSliceInBounds (Const64 [c]) (Const64 [d]))
3407 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07003408 // result: (ConstBool [b2i(0 <= c && c <= d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003409 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003410 v_0 := v.Args[0]
3411 if v_0.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003412 break
Keith Randalla347ab72015-10-26 21:49:31 -07003413 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003414 c := v_0.AuxInt
3415 v_1 := v.Args[1]
3416 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003417 break
Keith Randalla347ab72015-10-26 21:49:31 -07003418 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003419 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003420 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07003421 v.AuxInt = b2i(0 <= c && c <= d)
Keith Randalla347ab72015-10-26 21:49:31 -07003422 return true
3423 }
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01003424 // match: (IsSliceInBounds (SliceLen x) (SliceCap x))
3425 // cond:
3426 // result: (ConstBool [1])
3427 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003428 v_0 := v.Args[0]
3429 if v_0.Op != OpSliceLen {
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01003430 break
3431 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003432 x := v_0.Args[0]
3433 v_1 := v.Args[1]
3434 if v_1.Op != OpSliceCap {
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01003435 break
3436 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003437 if x != v_1.Args[0] {
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01003438 break
3439 }
3440 v.reset(OpConstBool)
3441 v.AuxInt = 1
3442 return true
3443 }
Keith Randalla347ab72015-10-26 21:49:31 -07003444 return false
3445}
Todd Nealcdc36252015-10-27 17:46:53 -05003446func rewriteValuegeneric_OpLeq16(v *Value, config *Config) bool {
3447 b := v.Block
3448 _ = b
3449 // match: (Leq16 (Const16 [c]) (Const16 [d]))
3450 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07003451 // result: (ConstBool [b2i(c <= d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003452 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003453 v_0 := v.Args[0]
3454 if v_0.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003455 break
Todd Nealcdc36252015-10-27 17:46:53 -05003456 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003457 c := v_0.AuxInt
3458 v_1 := v.Args[1]
3459 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003460 break
Todd Nealcdc36252015-10-27 17:46:53 -05003461 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003462 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003463 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07003464 v.AuxInt = b2i(c <= d)
Todd Nealcdc36252015-10-27 17:46:53 -05003465 return true
3466 }
Todd Nealcdc36252015-10-27 17:46:53 -05003467 return false
3468}
3469func rewriteValuegeneric_OpLeq16U(v *Value, config *Config) bool {
3470 b := v.Block
3471 _ = b
3472 // match: (Leq16U (Const16 [c]) (Const16 [d]))
3473 // cond:
3474 // result: (ConstBool [b2i(uint16(c) <= uint16(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003475 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003476 v_0 := v.Args[0]
3477 if v_0.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003478 break
Todd Nealcdc36252015-10-27 17:46:53 -05003479 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003480 c := v_0.AuxInt
3481 v_1 := v.Args[1]
3482 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003483 break
Todd Nealcdc36252015-10-27 17:46:53 -05003484 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003485 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003486 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05003487 v.AuxInt = b2i(uint16(c) <= uint16(d))
3488 return true
3489 }
Todd Nealcdc36252015-10-27 17:46:53 -05003490 return false
3491}
3492func rewriteValuegeneric_OpLeq32(v *Value, config *Config) bool {
3493 b := v.Block
3494 _ = b
3495 // match: (Leq32 (Const32 [c]) (Const32 [d]))
3496 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07003497 // result: (ConstBool [b2i(c <= d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003498 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003499 v_0 := v.Args[0]
3500 if v_0.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003501 break
Todd Nealcdc36252015-10-27 17:46:53 -05003502 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003503 c := v_0.AuxInt
3504 v_1 := v.Args[1]
3505 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003506 break
Todd Nealcdc36252015-10-27 17:46:53 -05003507 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003508 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003509 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07003510 v.AuxInt = b2i(c <= d)
Todd Nealcdc36252015-10-27 17:46:53 -05003511 return true
3512 }
Todd Nealcdc36252015-10-27 17:46:53 -05003513 return false
3514}
3515func rewriteValuegeneric_OpLeq32U(v *Value, config *Config) bool {
3516 b := v.Block
3517 _ = b
3518 // match: (Leq32U (Const32 [c]) (Const32 [d]))
3519 // cond:
3520 // result: (ConstBool [b2i(uint32(c) <= uint32(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003521 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003522 v_0 := v.Args[0]
3523 if v_0.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003524 break
Todd Nealcdc36252015-10-27 17:46:53 -05003525 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003526 c := v_0.AuxInt
3527 v_1 := v.Args[1]
3528 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003529 break
Todd Nealcdc36252015-10-27 17:46:53 -05003530 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003531 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003532 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05003533 v.AuxInt = b2i(uint32(c) <= uint32(d))
3534 return true
3535 }
Todd Nealcdc36252015-10-27 17:46:53 -05003536 return false
3537}
3538func rewriteValuegeneric_OpLeq64(v *Value, config *Config) bool {
3539 b := v.Block
3540 _ = b
3541 // match: (Leq64 (Const64 [c]) (Const64 [d]))
3542 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07003543 // result: (ConstBool [b2i(c <= d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003544 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003545 v_0 := v.Args[0]
3546 if v_0.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003547 break
Todd Nealcdc36252015-10-27 17:46:53 -05003548 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003549 c := v_0.AuxInt
3550 v_1 := v.Args[1]
3551 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003552 break
Todd Nealcdc36252015-10-27 17:46:53 -05003553 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003554 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003555 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07003556 v.AuxInt = b2i(c <= d)
Todd Nealcdc36252015-10-27 17:46:53 -05003557 return true
3558 }
Todd Nealcdc36252015-10-27 17:46:53 -05003559 return false
3560}
3561func rewriteValuegeneric_OpLeq64U(v *Value, config *Config) bool {
3562 b := v.Block
3563 _ = b
3564 // match: (Leq64U (Const64 [c]) (Const64 [d]))
3565 // cond:
3566 // result: (ConstBool [b2i(uint64(c) <= uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003567 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003568 v_0 := v.Args[0]
3569 if v_0.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003570 break
Todd Nealcdc36252015-10-27 17:46:53 -05003571 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003572 c := v_0.AuxInt
3573 v_1 := v.Args[1]
3574 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003575 break
Todd Nealcdc36252015-10-27 17:46:53 -05003576 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003577 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003578 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05003579 v.AuxInt = b2i(uint64(c) <= uint64(d))
3580 return true
3581 }
Todd Nealcdc36252015-10-27 17:46:53 -05003582 return false
3583}
3584func rewriteValuegeneric_OpLeq8(v *Value, config *Config) bool {
3585 b := v.Block
3586 _ = b
3587 // match: (Leq8 (Const8 [c]) (Const8 [d]))
3588 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07003589 // result: (ConstBool [b2i(c <= d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003590 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003591 v_0 := v.Args[0]
3592 if v_0.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003593 break
Todd Nealcdc36252015-10-27 17:46:53 -05003594 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003595 c := v_0.AuxInt
3596 v_1 := v.Args[1]
3597 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003598 break
Todd Nealcdc36252015-10-27 17:46:53 -05003599 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003600 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003601 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07003602 v.AuxInt = b2i(c <= d)
Todd Nealcdc36252015-10-27 17:46:53 -05003603 return true
3604 }
Todd Nealcdc36252015-10-27 17:46:53 -05003605 return false
3606}
3607func rewriteValuegeneric_OpLeq8U(v *Value, config *Config) bool {
3608 b := v.Block
3609 _ = b
3610 // match: (Leq8U (Const8 [c]) (Const8 [d]))
3611 // cond:
3612 // result: (ConstBool [b2i(uint8(c) <= uint8(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003613 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003614 v_0 := v.Args[0]
3615 if v_0.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003616 break
Todd Nealcdc36252015-10-27 17:46:53 -05003617 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003618 c := v_0.AuxInt
3619 v_1 := v.Args[1]
3620 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003621 break
Todd Nealcdc36252015-10-27 17:46:53 -05003622 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003623 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003624 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05003625 v.AuxInt = b2i(uint8(c) <= uint8(d))
3626 return true
3627 }
Todd Nealcdc36252015-10-27 17:46:53 -05003628 return false
3629}
3630func rewriteValuegeneric_OpLess16(v *Value, config *Config) bool {
3631 b := v.Block
3632 _ = b
3633 // match: (Less16 (Const16 [c]) (Const16 [d]))
3634 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07003635 // result: (ConstBool [b2i(c < d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003636 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003637 v_0 := v.Args[0]
3638 if v_0.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003639 break
Todd Nealcdc36252015-10-27 17:46:53 -05003640 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003641 c := v_0.AuxInt
3642 v_1 := v.Args[1]
3643 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003644 break
Todd Nealcdc36252015-10-27 17:46:53 -05003645 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003646 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003647 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07003648 v.AuxInt = b2i(c < d)
Todd Nealcdc36252015-10-27 17:46:53 -05003649 return true
3650 }
Todd Nealcdc36252015-10-27 17:46:53 -05003651 return false
3652}
3653func rewriteValuegeneric_OpLess16U(v *Value, config *Config) bool {
3654 b := v.Block
3655 _ = b
3656 // match: (Less16U (Const16 [c]) (Const16 [d]))
3657 // cond:
3658 // result: (ConstBool [b2i(uint16(c) < uint16(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003659 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003660 v_0 := v.Args[0]
3661 if v_0.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003662 break
Todd Nealcdc36252015-10-27 17:46:53 -05003663 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003664 c := v_0.AuxInt
3665 v_1 := v.Args[1]
3666 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003667 break
Todd Nealcdc36252015-10-27 17:46:53 -05003668 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003669 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003670 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05003671 v.AuxInt = b2i(uint16(c) < uint16(d))
3672 return true
3673 }
Todd Nealcdc36252015-10-27 17:46:53 -05003674 return false
3675}
3676func rewriteValuegeneric_OpLess32(v *Value, config *Config) bool {
3677 b := v.Block
3678 _ = b
3679 // match: (Less32 (Const32 [c]) (Const32 [d]))
3680 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07003681 // result: (ConstBool [b2i(c < d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003682 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003683 v_0 := v.Args[0]
3684 if v_0.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003685 break
Todd Nealcdc36252015-10-27 17:46:53 -05003686 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003687 c := v_0.AuxInt
3688 v_1 := v.Args[1]
3689 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003690 break
Todd Nealcdc36252015-10-27 17:46:53 -05003691 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003692 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003693 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07003694 v.AuxInt = b2i(c < d)
Todd Nealcdc36252015-10-27 17:46:53 -05003695 return true
3696 }
Todd Nealcdc36252015-10-27 17:46:53 -05003697 return false
3698}
3699func rewriteValuegeneric_OpLess32U(v *Value, config *Config) bool {
3700 b := v.Block
3701 _ = b
3702 // match: (Less32U (Const32 [c]) (Const32 [d]))
3703 // cond:
3704 // result: (ConstBool [b2i(uint32(c) < uint32(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003705 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003706 v_0 := v.Args[0]
3707 if v_0.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003708 break
Todd Nealcdc36252015-10-27 17:46:53 -05003709 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003710 c := v_0.AuxInt
3711 v_1 := v.Args[1]
3712 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003713 break
Todd Nealcdc36252015-10-27 17:46:53 -05003714 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003715 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003716 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05003717 v.AuxInt = b2i(uint32(c) < uint32(d))
3718 return true
3719 }
Todd Nealcdc36252015-10-27 17:46:53 -05003720 return false
3721}
3722func rewriteValuegeneric_OpLess64(v *Value, config *Config) bool {
3723 b := v.Block
3724 _ = b
3725 // match: (Less64 (Const64 [c]) (Const64 [d]))
3726 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07003727 // result: (ConstBool [b2i(c < d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003728 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003729 v_0 := v.Args[0]
3730 if v_0.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003731 break
Todd Nealcdc36252015-10-27 17:46:53 -05003732 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003733 c := v_0.AuxInt
3734 v_1 := v.Args[1]
3735 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003736 break
Todd Nealcdc36252015-10-27 17:46:53 -05003737 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003738 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003739 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07003740 v.AuxInt = b2i(c < d)
Todd Nealcdc36252015-10-27 17:46:53 -05003741 return true
3742 }
Todd Nealcdc36252015-10-27 17:46:53 -05003743 return false
3744}
3745func rewriteValuegeneric_OpLess64U(v *Value, config *Config) bool {
3746 b := v.Block
3747 _ = b
3748 // match: (Less64U (Const64 [c]) (Const64 [d]))
3749 // cond:
3750 // result: (ConstBool [b2i(uint64(c) < uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003751 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003752 v_0 := v.Args[0]
3753 if v_0.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003754 break
Todd Nealcdc36252015-10-27 17:46:53 -05003755 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003756 c := v_0.AuxInt
3757 v_1 := v.Args[1]
3758 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003759 break
Todd Nealcdc36252015-10-27 17:46:53 -05003760 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003761 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003762 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05003763 v.AuxInt = b2i(uint64(c) < uint64(d))
3764 return true
3765 }
Todd Nealcdc36252015-10-27 17:46:53 -05003766 return false
3767}
3768func rewriteValuegeneric_OpLess8(v *Value, config *Config) bool {
3769 b := v.Block
3770 _ = b
3771 // match: (Less8 (Const8 [c]) (Const8 [d]))
3772 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07003773 // result: (ConstBool [b2i(c < d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003774 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003775 v_0 := v.Args[0]
3776 if v_0.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003777 break
Todd Nealcdc36252015-10-27 17:46:53 -05003778 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003779 c := v_0.AuxInt
3780 v_1 := v.Args[1]
3781 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003782 break
Todd Nealcdc36252015-10-27 17:46:53 -05003783 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003784 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003785 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07003786 v.AuxInt = b2i(c < d)
Todd Nealcdc36252015-10-27 17:46:53 -05003787 return true
3788 }
Todd Nealcdc36252015-10-27 17:46:53 -05003789 return false
3790}
3791func rewriteValuegeneric_OpLess8U(v *Value, config *Config) bool {
3792 b := v.Block
3793 _ = b
3794 // match: (Less8U (Const8 [c]) (Const8 [d]))
3795 // cond:
3796 // result: (ConstBool [b2i(uint8(c) < uint8(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003797 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07003798 v_0 := v.Args[0]
3799 if v_0.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003800 break
Todd Nealcdc36252015-10-27 17:46:53 -05003801 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003802 c := v_0.AuxInt
3803 v_1 := v.Args[1]
3804 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003805 break
Todd Nealcdc36252015-10-27 17:46:53 -05003806 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003807 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003808 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05003809 v.AuxInt = b2i(uint8(c) < uint8(d))
3810 return true
3811 }
Todd Nealcdc36252015-10-27 17:46:53 -05003812 return false
3813}
Keith Randalla347ab72015-10-26 21:49:31 -07003814func rewriteValuegeneric_OpLoad(v *Value, config *Config) bool {
3815 b := v.Block
3816 _ = b
Todd Neal9dc13342016-02-13 17:37:19 -06003817 // match: (Load <t1> p1 (Store [w] p2 x _))
3818 // cond: isSamePtr(p1,p2) && t1.Compare(x.Type)==CMPeq && w == t1.Size()
3819 // result: x
3820 for {
3821 t1 := v.Type
3822 p1 := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07003823 v_1 := v.Args[1]
3824 if v_1.Op != OpStore {
Todd Neal9dc13342016-02-13 17:37:19 -06003825 break
3826 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003827 w := v_1.AuxInt
3828 p2 := v_1.Args[0]
3829 x := v_1.Args[1]
Todd Neal9dc13342016-02-13 17:37:19 -06003830 if !(isSamePtr(p1, p2) && t1.Compare(x.Type) == CMPeq && w == t1.Size()) {
3831 break
3832 }
3833 v.reset(OpCopy)
3834 v.Type = x.Type
3835 v.AddArg(x)
3836 return true
3837 }
Keith Randalla734bbc2016-01-11 21:05:33 -08003838 // match: (Load <t> _ _)
3839 // cond: t.IsStruct() && t.NumFields() == 0 && config.fe.CanSSA(t)
3840 // result: (StructMake0)
Alexandru Moșoi05434472016-02-04 19:52:10 +01003841 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08003842 t := v.Type
3843 if !(t.IsStruct() && t.NumFields() == 0 && config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003844 break
Keith Randalla734bbc2016-01-11 21:05:33 -08003845 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003846 v.reset(OpStructMake0)
Keith Randalla734bbc2016-01-11 21:05:33 -08003847 return true
3848 }
Keith Randalla734bbc2016-01-11 21:05:33 -08003849 // match: (Load <t> ptr mem)
3850 // cond: t.IsStruct() && t.NumFields() == 1 && config.fe.CanSSA(t)
3851 // result: (StructMake1 (Load <t.FieldType(0)> ptr mem))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003852 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08003853 t := v.Type
3854 ptr := v.Args[0]
3855 mem := v.Args[1]
3856 if !(t.IsStruct() && t.NumFields() == 1 && config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003857 break
Keith Randalla734bbc2016-01-11 21:05:33 -08003858 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003859 v.reset(OpStructMake1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003860 v0 := b.NewValue0(v.Line, OpLoad, t.FieldType(0))
Keith Randalla734bbc2016-01-11 21:05:33 -08003861 v0.AddArg(ptr)
3862 v0.AddArg(mem)
3863 v.AddArg(v0)
3864 return true
3865 }
Keith Randalla734bbc2016-01-11 21:05:33 -08003866 // match: (Load <t> ptr mem)
3867 // cond: t.IsStruct() && t.NumFields() == 2 && config.fe.CanSSA(t)
3868 // result: (StructMake2 (Load <t.FieldType(0)> ptr mem) (Load <t.FieldType(1)> (OffPtr <t.FieldType(1).PtrTo()> [t.FieldOff(1)] ptr) mem))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003869 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08003870 t := v.Type
3871 ptr := v.Args[0]
3872 mem := v.Args[1]
3873 if !(t.IsStruct() && t.NumFields() == 2 && config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003874 break
Keith Randalla734bbc2016-01-11 21:05:33 -08003875 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003876 v.reset(OpStructMake2)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003877 v0 := b.NewValue0(v.Line, OpLoad, t.FieldType(0))
Keith Randalla734bbc2016-01-11 21:05:33 -08003878 v0.AddArg(ptr)
3879 v0.AddArg(mem)
3880 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003881 v1 := b.NewValue0(v.Line, OpLoad, t.FieldType(1))
3882 v2 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(1).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08003883 v2.AuxInt = t.FieldOff(1)
3884 v2.AddArg(ptr)
3885 v1.AddArg(v2)
3886 v1.AddArg(mem)
3887 v.AddArg(v1)
3888 return true
3889 }
Keith Randalla734bbc2016-01-11 21:05:33 -08003890 // match: (Load <t> ptr mem)
3891 // cond: t.IsStruct() && t.NumFields() == 3 && config.fe.CanSSA(t)
3892 // result: (StructMake3 (Load <t.FieldType(0)> ptr mem) (Load <t.FieldType(1)> (OffPtr <t.FieldType(1).PtrTo()> [t.FieldOff(1)] ptr) mem) (Load <t.FieldType(2)> (OffPtr <t.FieldType(2).PtrTo()> [t.FieldOff(2)] ptr) mem))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003893 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08003894 t := v.Type
3895 ptr := v.Args[0]
3896 mem := v.Args[1]
3897 if !(t.IsStruct() && t.NumFields() == 3 && config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003898 break
Keith Randalla734bbc2016-01-11 21:05:33 -08003899 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003900 v.reset(OpStructMake3)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003901 v0 := b.NewValue0(v.Line, OpLoad, t.FieldType(0))
Keith Randalla734bbc2016-01-11 21:05:33 -08003902 v0.AddArg(ptr)
3903 v0.AddArg(mem)
3904 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003905 v1 := b.NewValue0(v.Line, OpLoad, t.FieldType(1))
3906 v2 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(1).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08003907 v2.AuxInt = t.FieldOff(1)
3908 v2.AddArg(ptr)
3909 v1.AddArg(v2)
3910 v1.AddArg(mem)
3911 v.AddArg(v1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003912 v3 := b.NewValue0(v.Line, OpLoad, t.FieldType(2))
3913 v4 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(2).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08003914 v4.AuxInt = t.FieldOff(2)
3915 v4.AddArg(ptr)
3916 v3.AddArg(v4)
3917 v3.AddArg(mem)
3918 v.AddArg(v3)
3919 return true
3920 }
Keith Randalla734bbc2016-01-11 21:05:33 -08003921 // match: (Load <t> ptr mem)
3922 // cond: t.IsStruct() && t.NumFields() == 4 && config.fe.CanSSA(t)
3923 // result: (StructMake4 (Load <t.FieldType(0)> ptr mem) (Load <t.FieldType(1)> (OffPtr <t.FieldType(1).PtrTo()> [t.FieldOff(1)] ptr) mem) (Load <t.FieldType(2)> (OffPtr <t.FieldType(2).PtrTo()> [t.FieldOff(2)] ptr) mem) (Load <t.FieldType(3)> (OffPtr <t.FieldType(3).PtrTo()> [t.FieldOff(3)] ptr) mem))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003924 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08003925 t := v.Type
3926 ptr := v.Args[0]
3927 mem := v.Args[1]
3928 if !(t.IsStruct() && t.NumFields() == 4 && config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003929 break
Keith Randalla734bbc2016-01-11 21:05:33 -08003930 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003931 v.reset(OpStructMake4)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003932 v0 := b.NewValue0(v.Line, OpLoad, t.FieldType(0))
Keith Randalla734bbc2016-01-11 21:05:33 -08003933 v0.AddArg(ptr)
3934 v0.AddArg(mem)
3935 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003936 v1 := b.NewValue0(v.Line, OpLoad, t.FieldType(1))
3937 v2 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(1).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08003938 v2.AuxInt = t.FieldOff(1)
3939 v2.AddArg(ptr)
3940 v1.AddArg(v2)
3941 v1.AddArg(mem)
3942 v.AddArg(v1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003943 v3 := b.NewValue0(v.Line, OpLoad, t.FieldType(2))
3944 v4 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(2).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08003945 v4.AuxInt = t.FieldOff(2)
3946 v4.AddArg(ptr)
3947 v3.AddArg(v4)
3948 v3.AddArg(mem)
3949 v.AddArg(v3)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003950 v5 := b.NewValue0(v.Line, OpLoad, t.FieldType(3))
3951 v6 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(3).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08003952 v6.AuxInt = t.FieldOff(3)
3953 v6.AddArg(ptr)
3954 v5.AddArg(v6)
3955 v5.AddArg(mem)
3956 v.AddArg(v5)
3957 return true
3958 }
Keith Randalla347ab72015-10-26 21:49:31 -07003959 return false
3960}
Todd Neal93a0b0f2016-02-03 06:21:24 -05003961func rewriteValuegeneric_OpLsh16x16(v *Value, config *Config) bool {
3962 b := v.Block
3963 _ = b
3964 // match: (Lsh16x16 <t> x (Const16 [c]))
3965 // cond:
3966 // result: (Lsh16x64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003967 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003968 t := v.Type
3969 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07003970 v_1 := v.Args[1]
3971 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003972 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003973 }
Keith Randall259b7ed2016-03-21 16:18:45 -07003974 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003975 v.reset(OpLsh16x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003976 v.AddArg(x)
3977 v0 := b.NewValue0(v.Line, OpConst64, t)
3978 v0.AuxInt = int64(uint16(c))
3979 v.AddArg(v0)
3980 return true
3981 }
Keith Randall17396572016-05-28 21:15:24 -07003982 // match: (Lsh16x16 (Const16 [0]) _)
3983 // cond:
3984 // result: (Const16 [0])
3985 for {
3986 v_0 := v.Args[0]
3987 if v_0.Op != OpConst16 {
3988 break
3989 }
3990 if v_0.AuxInt != 0 {
3991 break
3992 }
3993 v.reset(OpConst16)
3994 v.AuxInt = 0
3995 return true
3996 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003997 return false
3998}
3999func rewriteValuegeneric_OpLsh16x32(v *Value, config *Config) bool {
4000 b := v.Block
4001 _ = b
4002 // match: (Lsh16x32 <t> x (Const32 [c]))
4003 // cond:
4004 // result: (Lsh16x64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01004005 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05004006 t := v.Type
4007 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07004008 v_1 := v.Args[1]
4009 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004010 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004011 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004012 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004013 v.reset(OpLsh16x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004014 v.AddArg(x)
4015 v0 := b.NewValue0(v.Line, OpConst64, t)
4016 v0.AuxInt = int64(uint32(c))
4017 v.AddArg(v0)
4018 return true
4019 }
Keith Randall17396572016-05-28 21:15:24 -07004020 // match: (Lsh16x32 (Const16 [0]) _)
4021 // cond:
4022 // result: (Const16 [0])
4023 for {
4024 v_0 := v.Args[0]
4025 if v_0.Op != OpConst16 {
4026 break
4027 }
4028 if v_0.AuxInt != 0 {
4029 break
4030 }
4031 v.reset(OpConst16)
4032 v.AuxInt = 0
4033 return true
4034 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004035 return false
4036}
4037func rewriteValuegeneric_OpLsh16x64(v *Value, config *Config) bool {
4038 b := v.Block
4039 _ = b
4040 // match: (Lsh16x64 (Const16 [c]) (Const64 [d]))
4041 // cond:
4042 // result: (Const16 [int64(int16(c) << uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01004043 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07004044 v_0 := v.Args[0]
4045 if v_0.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004046 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004047 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004048 c := v_0.AuxInt
4049 v_1 := v.Args[1]
4050 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004051 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004052 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004053 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004054 v.reset(OpConst16)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004055 v.AuxInt = int64(int16(c) << uint64(d))
4056 return true
4057 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004058 // match: (Lsh16x64 x (Const64 [0]))
4059 // cond:
4060 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01004061 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05004062 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07004063 v_1 := v.Args[1]
4064 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004065 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004066 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004067 if v_1.AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004068 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004069 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004070 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004071 v.Type = x.Type
4072 v.AddArg(x)
4073 return true
4074 }
Keith Randall17396572016-05-28 21:15:24 -07004075 // match: (Lsh16x64 (Const16 [0]) _)
Keith Randallfa9435c2016-04-26 12:08:31 -07004076 // cond:
4077 // result: (Const16 [0])
4078 for {
4079 v_0 := v.Args[0]
Keith Randall17396572016-05-28 21:15:24 -07004080 if v_0.Op != OpConst16 {
Keith Randallfa9435c2016-04-26 12:08:31 -07004081 break
4082 }
4083 if v_0.AuxInt != 0 {
4084 break
4085 }
4086 v.reset(OpConst16)
4087 v.AuxInt = 0
4088 return true
4089 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004090 // match: (Lsh16x64 _ (Const64 [c]))
4091 // cond: uint64(c) >= 16
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01004092 // result: (Const16 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01004093 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07004094 v_1 := v.Args[1]
4095 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004096 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004097 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004098 c := v_1.AuxInt
Todd Neal93a0b0f2016-02-03 06:21:24 -05004099 if !(uint64(c) >= 16) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004100 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004101 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01004102 v.reset(OpConst16)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004103 v.AuxInt = 0
4104 return true
4105 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004106 // match: (Lsh16x64 <t> (Lsh16x64 x (Const64 [c])) (Const64 [d]))
4107 // cond: !uaddOvf(c,d)
4108 // result: (Lsh16x64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01004109 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05004110 t := v.Type
Keith Randall259b7ed2016-03-21 16:18:45 -07004111 v_0 := v.Args[0]
4112 if v_0.Op != OpLsh16x64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004113 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004114 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004115 x := v_0.Args[0]
4116 v_0_1 := v_0.Args[1]
4117 if v_0_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004118 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004119 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004120 c := v_0_1.AuxInt
4121 v_1 := v.Args[1]
4122 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004123 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004124 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004125 d := v_1.AuxInt
Todd Neal93a0b0f2016-02-03 06:21:24 -05004126 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004127 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004128 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004129 v.reset(OpLsh16x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004130 v.AddArg(x)
4131 v0 := b.NewValue0(v.Line, OpConst64, t)
4132 v0.AuxInt = c + d
4133 v.AddArg(v0)
4134 return true
4135 }
Keith Randall17396572016-05-28 21:15:24 -07004136 // match: (Lsh16x64 (Rsh16Ux64 (Lsh16x64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
4137 // cond: uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
4138 // result: (Lsh16x64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
Keith Randallfa9435c2016-04-26 12:08:31 -07004139 for {
4140 v_0 := v.Args[0]
4141 if v_0.Op != OpRsh16Ux64 {
4142 break
4143 }
4144 v_0_0 := v_0.Args[0]
4145 if v_0_0.Op != OpLsh16x64 {
4146 break
4147 }
4148 x := v_0_0.Args[0]
4149 v_0_0_1 := v_0_0.Args[1]
Keith Randall17396572016-05-28 21:15:24 -07004150 if v_0_0_1.Op != OpConst64 {
Keith Randallfa9435c2016-04-26 12:08:31 -07004151 break
4152 }
4153 c1 := v_0_0_1.AuxInt
4154 v_0_1 := v_0.Args[1]
Keith Randall17396572016-05-28 21:15:24 -07004155 if v_0_1.Op != OpConst64 {
Keith Randallfa9435c2016-04-26 12:08:31 -07004156 break
4157 }
4158 c2 := v_0_1.AuxInt
4159 v_1 := v.Args[1]
Keith Randall17396572016-05-28 21:15:24 -07004160 if v_1.Op != OpConst64 {
Keith Randallfa9435c2016-04-26 12:08:31 -07004161 break
4162 }
4163 c3 := v_1.AuxInt
Keith Randall17396572016-05-28 21:15:24 -07004164 if !(uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)) {
Keith Randallfa9435c2016-04-26 12:08:31 -07004165 break
4166 }
4167 v.reset(OpLsh16x64)
4168 v.AddArg(x)
Keith Randall17396572016-05-28 21:15:24 -07004169 v0 := b.NewValue0(v.Line, OpConst64, config.fe.TypeUInt64())
4170 v0.AuxInt = c1 - c2 + c3
Keith Randallfa9435c2016-04-26 12:08:31 -07004171 v.AddArg(v0)
4172 return true
4173 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004174 return false
4175}
4176func rewriteValuegeneric_OpLsh16x8(v *Value, config *Config) bool {
4177 b := v.Block
4178 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07004179 // match: (Lsh16x8 <t> x (Const8 [c]))
Todd Neal93a0b0f2016-02-03 06:21:24 -05004180 // cond:
4181 // result: (Lsh16x64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01004182 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05004183 t := v.Type
4184 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07004185 v_1 := v.Args[1]
4186 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004187 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004188 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004189 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004190 v.reset(OpLsh16x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004191 v.AddArg(x)
4192 v0 := b.NewValue0(v.Line, OpConst64, t)
4193 v0.AuxInt = int64(uint8(c))
4194 v.AddArg(v0)
4195 return true
4196 }
Keith Randall17396572016-05-28 21:15:24 -07004197 // match: (Lsh16x8 (Const16 [0]) _)
4198 // cond:
4199 // result: (Const16 [0])
4200 for {
4201 v_0 := v.Args[0]
4202 if v_0.Op != OpConst16 {
4203 break
4204 }
4205 if v_0.AuxInt != 0 {
4206 break
4207 }
4208 v.reset(OpConst16)
4209 v.AuxInt = 0
4210 return true
4211 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004212 return false
4213}
4214func rewriteValuegeneric_OpLsh32x16(v *Value, config *Config) bool {
4215 b := v.Block
4216 _ = b
4217 // match: (Lsh32x16 <t> x (Const16 [c]))
4218 // cond:
4219 // result: (Lsh32x64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01004220 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05004221 t := v.Type
4222 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07004223 v_1 := v.Args[1]
4224 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004225 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004226 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004227 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004228 v.reset(OpLsh32x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004229 v.AddArg(x)
4230 v0 := b.NewValue0(v.Line, OpConst64, t)
4231 v0.AuxInt = int64(uint16(c))
4232 v.AddArg(v0)
4233 return true
4234 }
Keith Randall17396572016-05-28 21:15:24 -07004235 // match: (Lsh32x16 (Const32 [0]) _)
4236 // cond:
4237 // result: (Const32 [0])
4238 for {
4239 v_0 := v.Args[0]
4240 if v_0.Op != OpConst32 {
4241 break
4242 }
4243 if v_0.AuxInt != 0 {
4244 break
4245 }
4246 v.reset(OpConst32)
4247 v.AuxInt = 0
4248 return true
4249 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004250 return false
4251}
4252func rewriteValuegeneric_OpLsh32x32(v *Value, config *Config) bool {
4253 b := v.Block
4254 _ = b
4255 // match: (Lsh32x32 <t> x (Const32 [c]))
4256 // cond:
4257 // result: (Lsh32x64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01004258 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05004259 t := v.Type
4260 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07004261 v_1 := v.Args[1]
4262 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004263 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004264 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004265 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004266 v.reset(OpLsh32x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004267 v.AddArg(x)
4268 v0 := b.NewValue0(v.Line, OpConst64, t)
4269 v0.AuxInt = int64(uint32(c))
4270 v.AddArg(v0)
4271 return true
4272 }
Keith Randall17396572016-05-28 21:15:24 -07004273 // match: (Lsh32x32 (Const32 [0]) _)
4274 // cond:
4275 // result: (Const32 [0])
4276 for {
4277 v_0 := v.Args[0]
4278 if v_0.Op != OpConst32 {
4279 break
4280 }
4281 if v_0.AuxInt != 0 {
4282 break
4283 }
4284 v.reset(OpConst32)
4285 v.AuxInt = 0
4286 return true
4287 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004288 return false
4289}
4290func rewriteValuegeneric_OpLsh32x64(v *Value, config *Config) bool {
4291 b := v.Block
4292 _ = b
4293 // match: (Lsh32x64 (Const32 [c]) (Const64 [d]))
4294 // cond:
4295 // result: (Const32 [int64(int32(c) << uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01004296 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07004297 v_0 := v.Args[0]
4298 if v_0.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004299 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004300 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004301 c := v_0.AuxInt
4302 v_1 := v.Args[1]
4303 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004304 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004305 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004306 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004307 v.reset(OpConst32)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004308 v.AuxInt = int64(int32(c) << uint64(d))
4309 return true
4310 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004311 // match: (Lsh32x64 x (Const64 [0]))
4312 // cond:
4313 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01004314 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05004315 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07004316 v_1 := v.Args[1]
4317 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004318 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004319 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004320 if v_1.AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004321 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004322 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004323 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004324 v.Type = x.Type
4325 v.AddArg(x)
4326 return true
4327 }
Keith Randall17396572016-05-28 21:15:24 -07004328 // match: (Lsh32x64 (Const32 [0]) _)
Keith Randallfa9435c2016-04-26 12:08:31 -07004329 // cond:
4330 // result: (Const32 [0])
4331 for {
4332 v_0 := v.Args[0]
Keith Randall17396572016-05-28 21:15:24 -07004333 if v_0.Op != OpConst32 {
Keith Randallfa9435c2016-04-26 12:08:31 -07004334 break
4335 }
4336 if v_0.AuxInt != 0 {
4337 break
4338 }
4339 v.reset(OpConst32)
4340 v.AuxInt = 0
4341 return true
4342 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004343 // match: (Lsh32x64 _ (Const64 [c]))
4344 // cond: uint64(c) >= 32
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01004345 // result: (Const32 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01004346 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07004347 v_1 := v.Args[1]
4348 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004349 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004350 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004351 c := v_1.AuxInt
Todd Neal93a0b0f2016-02-03 06:21:24 -05004352 if !(uint64(c) >= 32) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004353 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004354 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01004355 v.reset(OpConst32)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004356 v.AuxInt = 0
4357 return true
4358 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004359 // match: (Lsh32x64 <t> (Lsh32x64 x (Const64 [c])) (Const64 [d]))
4360 // cond: !uaddOvf(c,d)
4361 // result: (Lsh32x64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01004362 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05004363 t := v.Type
Keith Randall259b7ed2016-03-21 16:18:45 -07004364 v_0 := v.Args[0]
4365 if v_0.Op != OpLsh32x64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004366 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004367 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004368 x := v_0.Args[0]
4369 v_0_1 := v_0.Args[1]
4370 if v_0_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004371 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004372 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004373 c := v_0_1.AuxInt
4374 v_1 := v.Args[1]
4375 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004376 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004377 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004378 d := v_1.AuxInt
Todd Neal93a0b0f2016-02-03 06:21:24 -05004379 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004380 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004381 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004382 v.reset(OpLsh32x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004383 v.AddArg(x)
4384 v0 := b.NewValue0(v.Line, OpConst64, t)
4385 v0.AuxInt = c + d
4386 v.AddArg(v0)
4387 return true
4388 }
Keith Randall17396572016-05-28 21:15:24 -07004389 // match: (Lsh32x64 (Rsh32Ux64 (Lsh32x64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
4390 // cond: uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
4391 // result: (Lsh32x64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
Keith Randallfa9435c2016-04-26 12:08:31 -07004392 for {
4393 v_0 := v.Args[0]
4394 if v_0.Op != OpRsh32Ux64 {
4395 break
4396 }
4397 v_0_0 := v_0.Args[0]
4398 if v_0_0.Op != OpLsh32x64 {
4399 break
4400 }
4401 x := v_0_0.Args[0]
4402 v_0_0_1 := v_0_0.Args[1]
Keith Randall17396572016-05-28 21:15:24 -07004403 if v_0_0_1.Op != OpConst64 {
Keith Randallfa9435c2016-04-26 12:08:31 -07004404 break
4405 }
4406 c1 := v_0_0_1.AuxInt
4407 v_0_1 := v_0.Args[1]
Keith Randall17396572016-05-28 21:15:24 -07004408 if v_0_1.Op != OpConst64 {
Keith Randallfa9435c2016-04-26 12:08:31 -07004409 break
4410 }
4411 c2 := v_0_1.AuxInt
4412 v_1 := v.Args[1]
Keith Randall17396572016-05-28 21:15:24 -07004413 if v_1.Op != OpConst64 {
Keith Randallfa9435c2016-04-26 12:08:31 -07004414 break
4415 }
4416 c3 := v_1.AuxInt
Keith Randall17396572016-05-28 21:15:24 -07004417 if !(uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)) {
Keith Randallfa9435c2016-04-26 12:08:31 -07004418 break
4419 }
4420 v.reset(OpLsh32x64)
4421 v.AddArg(x)
Keith Randall17396572016-05-28 21:15:24 -07004422 v0 := b.NewValue0(v.Line, OpConst64, config.fe.TypeUInt64())
4423 v0.AuxInt = c1 - c2 + c3
Keith Randallfa9435c2016-04-26 12:08:31 -07004424 v.AddArg(v0)
4425 return true
4426 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004427 return false
4428}
4429func rewriteValuegeneric_OpLsh32x8(v *Value, config *Config) bool {
4430 b := v.Block
4431 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07004432 // match: (Lsh32x8 <t> x (Const8 [c]))
Todd Neal93a0b0f2016-02-03 06:21:24 -05004433 // cond:
4434 // result: (Lsh32x64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01004435 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05004436 t := v.Type
4437 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07004438 v_1 := v.Args[1]
4439 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004440 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004441 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004442 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004443 v.reset(OpLsh32x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004444 v.AddArg(x)
4445 v0 := b.NewValue0(v.Line, OpConst64, t)
4446 v0.AuxInt = int64(uint8(c))
4447 v.AddArg(v0)
4448 return true
4449 }
Keith Randall17396572016-05-28 21:15:24 -07004450 // match: (Lsh32x8 (Const32 [0]) _)
4451 // cond:
4452 // result: (Const32 [0])
4453 for {
4454 v_0 := v.Args[0]
4455 if v_0.Op != OpConst32 {
4456 break
4457 }
4458 if v_0.AuxInt != 0 {
4459 break
4460 }
4461 v.reset(OpConst32)
4462 v.AuxInt = 0
4463 return true
4464 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004465 return false
4466}
4467func rewriteValuegeneric_OpLsh64x16(v *Value, config *Config) bool {
4468 b := v.Block
4469 _ = b
4470 // match: (Lsh64x16 <t> x (Const16 [c]))
4471 // cond:
4472 // result: (Lsh64x64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01004473 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05004474 t := v.Type
4475 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07004476 v_1 := v.Args[1]
4477 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004478 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004479 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004480 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004481 v.reset(OpLsh64x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004482 v.AddArg(x)
4483 v0 := b.NewValue0(v.Line, OpConst64, t)
4484 v0.AuxInt = int64(uint16(c))
4485 v.AddArg(v0)
4486 return true
4487 }
Keith Randall17396572016-05-28 21:15:24 -07004488 // match: (Lsh64x16 (Const64 [0]) _)
4489 // cond:
4490 // result: (Const64 [0])
4491 for {
4492 v_0 := v.Args[0]
4493 if v_0.Op != OpConst64 {
4494 break
4495 }
4496 if v_0.AuxInt != 0 {
4497 break
4498 }
4499 v.reset(OpConst64)
4500 v.AuxInt = 0
4501 return true
4502 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004503 return false
4504}
4505func rewriteValuegeneric_OpLsh64x32(v *Value, config *Config) bool {
4506 b := v.Block
4507 _ = b
4508 // match: (Lsh64x32 <t> x (Const32 [c]))
4509 // cond:
4510 // result: (Lsh64x64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01004511 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05004512 t := v.Type
4513 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07004514 v_1 := v.Args[1]
4515 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004516 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004517 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004518 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004519 v.reset(OpLsh64x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004520 v.AddArg(x)
4521 v0 := b.NewValue0(v.Line, OpConst64, t)
4522 v0.AuxInt = int64(uint32(c))
4523 v.AddArg(v0)
4524 return true
4525 }
Keith Randall17396572016-05-28 21:15:24 -07004526 // match: (Lsh64x32 (Const64 [0]) _)
4527 // cond:
4528 // result: (Const64 [0])
4529 for {
4530 v_0 := v.Args[0]
4531 if v_0.Op != OpConst64 {
4532 break
4533 }
4534 if v_0.AuxInt != 0 {
4535 break
4536 }
4537 v.reset(OpConst64)
4538 v.AuxInt = 0
4539 return true
4540 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004541 return false
4542}
4543func rewriteValuegeneric_OpLsh64x64(v *Value, config *Config) bool {
4544 b := v.Block
4545 _ = b
4546 // match: (Lsh64x64 (Const64 [c]) (Const64 [d]))
4547 // cond:
4548 // result: (Const64 [c << uint64(d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01004549 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07004550 v_0 := v.Args[0]
4551 if v_0.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004552 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004553 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004554 c := v_0.AuxInt
4555 v_1 := v.Args[1]
4556 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004557 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004558 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004559 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004560 v.reset(OpConst64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004561 v.AuxInt = c << uint64(d)
4562 return true
4563 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004564 // match: (Lsh64x64 x (Const64 [0]))
4565 // cond:
4566 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01004567 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05004568 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07004569 v_1 := v.Args[1]
4570 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004571 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004572 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004573 if v_1.AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004574 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004575 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004576 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004577 v.Type = x.Type
4578 v.AddArg(x)
4579 return true
4580 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01004581 // match: (Lsh64x64 (Const64 [0]) _)
4582 // cond:
4583 // result: (Const64 [0])
4584 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07004585 v_0 := v.Args[0]
4586 if v_0.Op != OpConst64 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01004587 break
4588 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004589 if v_0.AuxInt != 0 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01004590 break
4591 }
4592 v.reset(OpConst64)
4593 v.AuxInt = 0
4594 return true
4595 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004596 // match: (Lsh64x64 _ (Const64 [c]))
4597 // cond: uint64(c) >= 64
4598 // result: (Const64 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01004599 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07004600 v_1 := v.Args[1]
4601 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004602 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004603 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004604 c := v_1.AuxInt
Todd Neal93a0b0f2016-02-03 06:21:24 -05004605 if !(uint64(c) >= 64) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004606 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004607 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004608 v.reset(OpConst64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004609 v.AuxInt = 0
4610 return true
4611 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004612 // match: (Lsh64x64 <t> (Lsh64x64 x (Const64 [c])) (Const64 [d]))
4613 // cond: !uaddOvf(c,d)
4614 // result: (Lsh64x64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01004615 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05004616 t := v.Type
Keith Randall259b7ed2016-03-21 16:18:45 -07004617 v_0 := v.Args[0]
4618 if v_0.Op != OpLsh64x64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004619 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004620 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004621 x := v_0.Args[0]
4622 v_0_1 := v_0.Args[1]
4623 if v_0_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004624 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004625 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004626 c := v_0_1.AuxInt
4627 v_1 := v.Args[1]
4628 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004629 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004630 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004631 d := v_1.AuxInt
Todd Neal93a0b0f2016-02-03 06:21:24 -05004632 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004633 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004634 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004635 v.reset(OpLsh64x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004636 v.AddArg(x)
4637 v0 := b.NewValue0(v.Line, OpConst64, t)
4638 v0.AuxInt = c + d
4639 v.AddArg(v0)
4640 return true
4641 }
Keith Randallfa9435c2016-04-26 12:08:31 -07004642 // match: (Lsh64x64 (Rsh64Ux64 (Lsh64x64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
Keith Randall17396572016-05-28 21:15:24 -07004643 // cond: uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
Keith Randallfa9435c2016-04-26 12:08:31 -07004644 // result: (Lsh64x64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
4645 for {
4646 v_0 := v.Args[0]
4647 if v_0.Op != OpRsh64Ux64 {
4648 break
4649 }
4650 v_0_0 := v_0.Args[0]
4651 if v_0_0.Op != OpLsh64x64 {
4652 break
4653 }
4654 x := v_0_0.Args[0]
4655 v_0_0_1 := v_0_0.Args[1]
4656 if v_0_0_1.Op != OpConst64 {
4657 break
4658 }
4659 c1 := v_0_0_1.AuxInt
4660 v_0_1 := v_0.Args[1]
4661 if v_0_1.Op != OpConst64 {
4662 break
4663 }
4664 c2 := v_0_1.AuxInt
4665 v_1 := v.Args[1]
4666 if v_1.Op != OpConst64 {
4667 break
4668 }
4669 c3 := v_1.AuxInt
Keith Randall17396572016-05-28 21:15:24 -07004670 if !(uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)) {
Keith Randallfa9435c2016-04-26 12:08:31 -07004671 break
4672 }
4673 v.reset(OpLsh64x64)
4674 v.AddArg(x)
4675 v0 := b.NewValue0(v.Line, OpConst64, config.fe.TypeUInt64())
4676 v0.AuxInt = c1 - c2 + c3
4677 v.AddArg(v0)
4678 return true
4679 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004680 return false
4681}
4682func rewriteValuegeneric_OpLsh64x8(v *Value, config *Config) bool {
4683 b := v.Block
4684 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07004685 // match: (Lsh64x8 <t> x (Const8 [c]))
Todd Neal93a0b0f2016-02-03 06:21:24 -05004686 // cond:
4687 // result: (Lsh64x64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01004688 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05004689 t := v.Type
4690 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07004691 v_1 := v.Args[1]
4692 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004693 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004694 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004695 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004696 v.reset(OpLsh64x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004697 v.AddArg(x)
4698 v0 := b.NewValue0(v.Line, OpConst64, t)
4699 v0.AuxInt = int64(uint8(c))
4700 v.AddArg(v0)
4701 return true
4702 }
Keith Randall17396572016-05-28 21:15:24 -07004703 // match: (Lsh64x8 (Const64 [0]) _)
4704 // cond:
4705 // result: (Const64 [0])
4706 for {
4707 v_0 := v.Args[0]
4708 if v_0.Op != OpConst64 {
4709 break
4710 }
4711 if v_0.AuxInt != 0 {
4712 break
4713 }
4714 v.reset(OpConst64)
4715 v.AuxInt = 0
4716 return true
4717 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004718 return false
4719}
4720func rewriteValuegeneric_OpLsh8x16(v *Value, config *Config) bool {
4721 b := v.Block
4722 _ = b
4723 // match: (Lsh8x16 <t> x (Const16 [c]))
4724 // cond:
4725 // result: (Lsh8x64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01004726 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05004727 t := v.Type
4728 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07004729 v_1 := v.Args[1]
4730 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004731 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004732 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004733 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004734 v.reset(OpLsh8x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004735 v.AddArg(x)
4736 v0 := b.NewValue0(v.Line, OpConst64, t)
4737 v0.AuxInt = int64(uint16(c))
4738 v.AddArg(v0)
4739 return true
4740 }
Keith Randall17396572016-05-28 21:15:24 -07004741 // match: (Lsh8x16 (Const8 [0]) _)
4742 // cond:
4743 // result: (Const8 [0])
4744 for {
4745 v_0 := v.Args[0]
4746 if v_0.Op != OpConst8 {
4747 break
4748 }
4749 if v_0.AuxInt != 0 {
4750 break
4751 }
4752 v.reset(OpConst8)
4753 v.AuxInt = 0
4754 return true
4755 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004756 return false
4757}
4758func rewriteValuegeneric_OpLsh8x32(v *Value, config *Config) bool {
4759 b := v.Block
4760 _ = b
4761 // match: (Lsh8x32 <t> x (Const32 [c]))
4762 // cond:
4763 // result: (Lsh8x64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01004764 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05004765 t := v.Type
4766 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07004767 v_1 := v.Args[1]
4768 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004769 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004770 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004771 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004772 v.reset(OpLsh8x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004773 v.AddArg(x)
4774 v0 := b.NewValue0(v.Line, OpConst64, t)
4775 v0.AuxInt = int64(uint32(c))
4776 v.AddArg(v0)
4777 return true
4778 }
Keith Randall17396572016-05-28 21:15:24 -07004779 // match: (Lsh8x32 (Const8 [0]) _)
4780 // cond:
4781 // result: (Const8 [0])
4782 for {
4783 v_0 := v.Args[0]
4784 if v_0.Op != OpConst8 {
4785 break
4786 }
4787 if v_0.AuxInt != 0 {
4788 break
4789 }
4790 v.reset(OpConst8)
4791 v.AuxInt = 0
4792 return true
4793 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004794 return false
4795}
4796func rewriteValuegeneric_OpLsh8x64(v *Value, config *Config) bool {
4797 b := v.Block
4798 _ = b
4799 // match: (Lsh8x64 (Const8 [c]) (Const64 [d]))
4800 // cond:
4801 // result: (Const8 [int64(int8(c) << uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01004802 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07004803 v_0 := v.Args[0]
4804 if v_0.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004805 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004806 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004807 c := v_0.AuxInt
4808 v_1 := v.Args[1]
4809 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004810 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004811 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004812 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004813 v.reset(OpConst8)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004814 v.AuxInt = int64(int8(c) << uint64(d))
4815 return true
4816 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004817 // match: (Lsh8x64 x (Const64 [0]))
4818 // cond:
4819 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01004820 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05004821 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07004822 v_1 := v.Args[1]
4823 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004824 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004825 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004826 if v_1.AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004827 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004828 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004829 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004830 v.Type = x.Type
4831 v.AddArg(x)
4832 return true
4833 }
Keith Randall17396572016-05-28 21:15:24 -07004834 // match: (Lsh8x64 (Const8 [0]) _)
Keith Randallfa9435c2016-04-26 12:08:31 -07004835 // cond:
4836 // result: (Const8 [0])
4837 for {
4838 v_0 := v.Args[0]
Keith Randall17396572016-05-28 21:15:24 -07004839 if v_0.Op != OpConst8 {
Keith Randallfa9435c2016-04-26 12:08:31 -07004840 break
4841 }
4842 if v_0.AuxInt != 0 {
4843 break
4844 }
4845 v.reset(OpConst8)
4846 v.AuxInt = 0
4847 return true
4848 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004849 // match: (Lsh8x64 _ (Const64 [c]))
4850 // cond: uint64(c) >= 8
Keith Randallfa9435c2016-04-26 12:08:31 -07004851 // result: (Const8 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01004852 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07004853 v_1 := v.Args[1]
4854 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004855 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004856 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004857 c := v_1.AuxInt
Todd Neal93a0b0f2016-02-03 06:21:24 -05004858 if !(uint64(c) >= 8) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004859 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004860 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01004861 v.reset(OpConst8)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004862 v.AuxInt = 0
4863 return true
4864 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004865 // match: (Lsh8x64 <t> (Lsh8x64 x (Const64 [c])) (Const64 [d]))
4866 // cond: !uaddOvf(c,d)
4867 // result: (Lsh8x64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01004868 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05004869 t := v.Type
Keith Randall259b7ed2016-03-21 16:18:45 -07004870 v_0 := v.Args[0]
4871 if v_0.Op != OpLsh8x64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004872 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004873 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004874 x := v_0.Args[0]
4875 v_0_1 := v_0.Args[1]
4876 if v_0_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004877 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004878 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004879 c := v_0_1.AuxInt
4880 v_1 := v.Args[1]
4881 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004882 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004883 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004884 d := v_1.AuxInt
Todd Neal93a0b0f2016-02-03 06:21:24 -05004885 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004886 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004887 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004888 v.reset(OpLsh8x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004889 v.AddArg(x)
4890 v0 := b.NewValue0(v.Line, OpConst64, t)
4891 v0.AuxInt = c + d
4892 v.AddArg(v0)
4893 return true
4894 }
Keith Randall17396572016-05-28 21:15:24 -07004895 // match: (Lsh8x64 (Rsh8Ux64 (Lsh8x64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
4896 // cond: uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
4897 // result: (Lsh8x64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
Todd Nealc8b148e2016-03-15 19:26:21 -05004898 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07004899 v_0 := v.Args[0]
Keith Randallfa9435c2016-04-26 12:08:31 -07004900 if v_0.Op != OpRsh8Ux64 {
Todd Nealc8b148e2016-03-15 19:26:21 -05004901 break
4902 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004903 v_0_0 := v_0.Args[0]
Keith Randallfa9435c2016-04-26 12:08:31 -07004904 if v_0_0.Op != OpLsh8x64 {
Todd Nealc8b148e2016-03-15 19:26:21 -05004905 break
4906 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004907 x := v_0_0.Args[0]
4908 v_0_0_1 := v_0_0.Args[1]
Keith Randall17396572016-05-28 21:15:24 -07004909 if v_0_0_1.Op != OpConst64 {
Todd Nealc8b148e2016-03-15 19:26:21 -05004910 break
4911 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004912 c1 := v_0_0_1.AuxInt
4913 v_0_1 := v_0.Args[1]
Keith Randall17396572016-05-28 21:15:24 -07004914 if v_0_1.Op != OpConst64 {
Todd Nealc8b148e2016-03-15 19:26:21 -05004915 break
4916 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004917 c2 := v_0_1.AuxInt
4918 v_1 := v.Args[1]
Keith Randall17396572016-05-28 21:15:24 -07004919 if v_1.Op != OpConst64 {
Todd Nealc8b148e2016-03-15 19:26:21 -05004920 break
4921 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004922 c3 := v_1.AuxInt
Keith Randall17396572016-05-28 21:15:24 -07004923 if !(uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)) {
Todd Nealc8b148e2016-03-15 19:26:21 -05004924 break
4925 }
Keith Randallfa9435c2016-04-26 12:08:31 -07004926 v.reset(OpLsh8x64)
Todd Nealc8b148e2016-03-15 19:26:21 -05004927 v.AddArg(x)
Keith Randall17396572016-05-28 21:15:24 -07004928 v0 := b.NewValue0(v.Line, OpConst64, config.fe.TypeUInt64())
4929 v0.AuxInt = c1 - c2 + c3
Todd Nealc8b148e2016-03-15 19:26:21 -05004930 v.AddArg(v0)
4931 return true
4932 }
Keith Randallfa9435c2016-04-26 12:08:31 -07004933 return false
4934}
4935func rewriteValuegeneric_OpLsh8x8(v *Value, config *Config) bool {
4936 b := v.Block
4937 _ = b
4938 // match: (Lsh8x8 <t> x (Const8 [c]))
Todd Neal93a0b0f2016-02-03 06:21:24 -05004939 // cond:
4940 // result: (Lsh8x64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01004941 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05004942 t := v.Type
4943 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07004944 v_1 := v.Args[1]
4945 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004946 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05004947 }
Keith Randall259b7ed2016-03-21 16:18:45 -07004948 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004949 v.reset(OpLsh8x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004950 v.AddArg(x)
4951 v0 := b.NewValue0(v.Line, OpConst64, t)
4952 v0.AuxInt = int64(uint8(c))
4953 v.AddArg(v0)
4954 return true
4955 }
Keith Randall17396572016-05-28 21:15:24 -07004956 // match: (Lsh8x8 (Const8 [0]) _)
4957 // cond:
4958 // result: (Const8 [0])
4959 for {
4960 v_0 := v.Args[0]
4961 if v_0.Op != OpConst8 {
4962 break
4963 }
4964 if v_0.AuxInt != 0 {
4965 break
4966 }
4967 v.reset(OpConst8)
4968 v.AuxInt = 0
4969 return true
4970 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05004971 return false
4972}
Alexandru Moșoi060501d2016-04-04 16:13:35 +02004973func rewriteValuegeneric_OpMod16(v *Value, config *Config) bool {
4974 b := v.Block
4975 _ = b
4976 // match: (Mod16 (Const16 [c]) (Const16 [d]))
4977 // cond: d != 0
4978 // result: (Const16 [int64(int16(c % d))])
4979 for {
4980 v_0 := v.Args[0]
4981 if v_0.Op != OpConst16 {
4982 break
4983 }
4984 c := v_0.AuxInt
4985 v_1 := v.Args[1]
4986 if v_1.Op != OpConst16 {
4987 break
4988 }
4989 d := v_1.AuxInt
4990 if !(d != 0) {
4991 break
4992 }
4993 v.reset(OpConst16)
4994 v.AuxInt = int64(int16(c % d))
4995 return true
4996 }
4997 return false
4998}
4999func rewriteValuegeneric_OpMod16u(v *Value, config *Config) bool {
5000 b := v.Block
5001 _ = b
5002 // match: (Mod16u (Const16 [c]) (Const16 [d]))
5003 // cond: d != 0
5004 // result: (Const16 [int64(uint16(c) % uint16(d))])
5005 for {
5006 v_0 := v.Args[0]
5007 if v_0.Op != OpConst16 {
5008 break
5009 }
5010 c := v_0.AuxInt
5011 v_1 := v.Args[1]
5012 if v_1.Op != OpConst16 {
5013 break
5014 }
5015 d := v_1.AuxInt
5016 if !(d != 0) {
5017 break
5018 }
5019 v.reset(OpConst16)
5020 v.AuxInt = int64(uint16(c) % uint16(d))
5021 return true
5022 }
5023 return false
5024}
5025func rewriteValuegeneric_OpMod32(v *Value, config *Config) bool {
5026 b := v.Block
5027 _ = b
5028 // match: (Mod32 (Const32 [c]) (Const32 [d]))
5029 // cond: d != 0
5030 // result: (Const32 [int64(int32(c % d))])
5031 for {
5032 v_0 := v.Args[0]
5033 if v_0.Op != OpConst32 {
5034 break
5035 }
5036 c := v_0.AuxInt
5037 v_1 := v.Args[1]
5038 if v_1.Op != OpConst32 {
5039 break
5040 }
5041 d := v_1.AuxInt
5042 if !(d != 0) {
5043 break
5044 }
5045 v.reset(OpConst32)
5046 v.AuxInt = int64(int32(c % d))
5047 return true
5048 }
5049 return false
5050}
5051func rewriteValuegeneric_OpMod32u(v *Value, config *Config) bool {
5052 b := v.Block
5053 _ = b
5054 // match: (Mod32u (Const32 [c]) (Const32 [d]))
5055 // cond: d != 0
5056 // result: (Const32 [int64(uint32(c) % uint32(d))])
5057 for {
5058 v_0 := v.Args[0]
5059 if v_0.Op != OpConst32 {
5060 break
5061 }
5062 c := v_0.AuxInt
5063 v_1 := v.Args[1]
5064 if v_1.Op != OpConst32 {
5065 break
5066 }
5067 d := v_1.AuxInt
5068 if !(d != 0) {
5069 break
5070 }
5071 v.reset(OpConst32)
5072 v.AuxInt = int64(uint32(c) % uint32(d))
5073 return true
5074 }
5075 return false
5076}
Keith Randalla3055af2016-02-05 20:26:18 -08005077func rewriteValuegeneric_OpMod64(v *Value, config *Config) bool {
5078 b := v.Block
5079 _ = b
Alexandru Moșoi060501d2016-04-04 16:13:35 +02005080 // match: (Mod64 (Const64 [c]) (Const64 [d]))
5081 // cond: d != 0
5082 // result: (Const64 [c % d])
5083 for {
5084 v_0 := v.Args[0]
5085 if v_0.Op != OpConst64 {
5086 break
5087 }
5088 c := v_0.AuxInt
5089 v_1 := v.Args[1]
5090 if v_1.Op != OpConst64 {
5091 break
5092 }
5093 d := v_1.AuxInt
5094 if !(d != 0) {
5095 break
5096 }
5097 v.reset(OpConst64)
5098 v.AuxInt = c % d
5099 return true
5100 }
Keith Randalla3055af2016-02-05 20:26:18 -08005101 // match: (Mod64 <t> x (Const64 [c]))
Alexandru Moșoi060501d2016-04-04 16:13:35 +02005102 // cond: x.Op != OpConst64 && smagic64ok(c)
Keith Randalla3055af2016-02-05 20:26:18 -08005103 // result: (Sub64 x (Mul64 <t> (Div64 <t> x (Const64 <t> [c])) (Const64 <t> [c])))
5104 for {
5105 t := v.Type
5106 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07005107 v_1 := v.Args[1]
5108 if v_1.Op != OpConst64 {
Keith Randalla3055af2016-02-05 20:26:18 -08005109 break
5110 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005111 c := v_1.AuxInt
Alexandru Moșoi060501d2016-04-04 16:13:35 +02005112 if !(x.Op != OpConst64 && smagic64ok(c)) {
Keith Randalla3055af2016-02-05 20:26:18 -08005113 break
5114 }
5115 v.reset(OpSub64)
5116 v.AddArg(x)
5117 v0 := b.NewValue0(v.Line, OpMul64, t)
5118 v1 := b.NewValue0(v.Line, OpDiv64, t)
5119 v1.AddArg(x)
5120 v2 := b.NewValue0(v.Line, OpConst64, t)
5121 v2.AuxInt = c
5122 v1.AddArg(v2)
5123 v0.AddArg(v1)
5124 v3 := b.NewValue0(v.Line, OpConst64, t)
5125 v3.AuxInt = c
5126 v0.AddArg(v3)
5127 v.AddArg(v0)
5128 return true
5129 }
5130 return false
5131}
5132func rewriteValuegeneric_OpMod64u(v *Value, config *Config) bool {
5133 b := v.Block
5134 _ = b
Alexandru Moșoi060501d2016-04-04 16:13:35 +02005135 // match: (Mod64u (Const64 [c]) (Const64 [d]))
5136 // cond: d != 0
5137 // result: (Const64 [int64(uint64(c) % uint64(d))])
5138 for {
5139 v_0 := v.Args[0]
5140 if v_0.Op != OpConst64 {
5141 break
5142 }
5143 c := v_0.AuxInt
5144 v_1 := v.Args[1]
5145 if v_1.Op != OpConst64 {
5146 break
5147 }
5148 d := v_1.AuxInt
5149 if !(d != 0) {
5150 break
5151 }
5152 v.reset(OpConst64)
5153 v.AuxInt = int64(uint64(c) % uint64(d))
5154 return true
5155 }
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01005156 // match: (Mod64u <t> n (Const64 [c]))
5157 // cond: isPowerOfTwo(c)
5158 // result: (And64 n (Const64 <t> [c-1]))
5159 for {
5160 t := v.Type
5161 n := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07005162 v_1 := v.Args[1]
5163 if v_1.Op != OpConst64 {
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01005164 break
5165 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005166 c := v_1.AuxInt
Alexandru Moșoibbd3ffb2016-03-09 11:00:58 +01005167 if !(isPowerOfTwo(c)) {
5168 break
5169 }
5170 v.reset(OpAnd64)
5171 v.AddArg(n)
5172 v0 := b.NewValue0(v.Line, OpConst64, t)
5173 v0.AuxInt = c - 1
5174 v.AddArg(v0)
5175 return true
5176 }
Keith Randalla3055af2016-02-05 20:26:18 -08005177 // match: (Mod64u <t> x (Const64 [c]))
Alexandru Moșoi060501d2016-04-04 16:13:35 +02005178 // cond: x.Op != OpConst64 && umagic64ok(c)
Keith Randalla3055af2016-02-05 20:26:18 -08005179 // result: (Sub64 x (Mul64 <t> (Div64u <t> x (Const64 <t> [c])) (Const64 <t> [c])))
5180 for {
5181 t := v.Type
5182 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07005183 v_1 := v.Args[1]
5184 if v_1.Op != OpConst64 {
Keith Randalla3055af2016-02-05 20:26:18 -08005185 break
5186 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005187 c := v_1.AuxInt
Alexandru Moșoi060501d2016-04-04 16:13:35 +02005188 if !(x.Op != OpConst64 && umagic64ok(c)) {
Keith Randalla3055af2016-02-05 20:26:18 -08005189 break
5190 }
5191 v.reset(OpSub64)
5192 v.AddArg(x)
5193 v0 := b.NewValue0(v.Line, OpMul64, t)
5194 v1 := b.NewValue0(v.Line, OpDiv64u, t)
5195 v1.AddArg(x)
5196 v2 := b.NewValue0(v.Line, OpConst64, t)
5197 v2.AuxInt = c
5198 v1.AddArg(v2)
5199 v0.AddArg(v1)
5200 v3 := b.NewValue0(v.Line, OpConst64, t)
5201 v3.AuxInt = c
5202 v0.AddArg(v3)
5203 v.AddArg(v0)
5204 return true
5205 }
5206 return false
5207}
Alexandru Moșoi060501d2016-04-04 16:13:35 +02005208func rewriteValuegeneric_OpMod8(v *Value, config *Config) bool {
5209 b := v.Block
5210 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07005211 // match: (Mod8 (Const8 [c]) (Const8 [d]))
Alexandru Moșoi060501d2016-04-04 16:13:35 +02005212 // cond: d != 0
Keith Randallfa9435c2016-04-26 12:08:31 -07005213 // result: (Const8 [int64(int8(c % d))])
Alexandru Moșoi060501d2016-04-04 16:13:35 +02005214 for {
5215 v_0 := v.Args[0]
5216 if v_0.Op != OpConst8 {
5217 break
5218 }
5219 c := v_0.AuxInt
5220 v_1 := v.Args[1]
5221 if v_1.Op != OpConst8 {
5222 break
5223 }
5224 d := v_1.AuxInt
5225 if !(d != 0) {
5226 break
5227 }
5228 v.reset(OpConst8)
5229 v.AuxInt = int64(int8(c % d))
5230 return true
5231 }
5232 return false
5233}
5234func rewriteValuegeneric_OpMod8u(v *Value, config *Config) bool {
5235 b := v.Block
5236 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07005237 // match: (Mod8u (Const8 [c]) (Const8 [d]))
Alexandru Moșoi060501d2016-04-04 16:13:35 +02005238 // cond: d != 0
Keith Randallfa9435c2016-04-26 12:08:31 -07005239 // result: (Const8 [int64(uint8(c) % uint8(d))])
Alexandru Moșoi060501d2016-04-04 16:13:35 +02005240 for {
5241 v_0 := v.Args[0]
5242 if v_0.Op != OpConst8 {
5243 break
5244 }
5245 c := v_0.AuxInt
5246 v_1 := v.Args[1]
5247 if v_1.Op != OpConst8 {
5248 break
5249 }
5250 d := v_1.AuxInt
5251 if !(d != 0) {
5252 break
5253 }
5254 v.reset(OpConst8)
5255 v.AuxInt = int64(uint8(c) % uint8(d))
5256 return true
5257 }
5258 return false
5259}
Keith Randall582baae2015-11-02 21:28:13 -08005260func rewriteValuegeneric_OpMul16(v *Value, config *Config) bool {
5261 b := v.Block
5262 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07005263 // match: (Mul16 (Const16 [c]) (Const16 [d]))
Keith Randall582baae2015-11-02 21:28:13 -08005264 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07005265 // result: (Const16 [int64(int16(c*d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01005266 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07005267 v_0 := v.Args[0]
5268 if v_0.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005269 break
Keith Randall582baae2015-11-02 21:28:13 -08005270 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005271 c := v_0.AuxInt
5272 v_1 := v.Args[1]
5273 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005274 break
Keith Randall582baae2015-11-02 21:28:13 -08005275 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005276 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005277 v.reset(OpConst16)
Keith Randall7fc56212016-03-29 16:39:53 -07005278 v.AuxInt = int64(int16(c * d))
Keith Randall582baae2015-11-02 21:28:13 -08005279 return true
5280 }
Josh Bleecher Snyderf0bab312016-07-05 10:03:02 -07005281 // match: (Mul16 (Const16 [-1]) x)
5282 // cond:
5283 // result: (Neg16 x)
5284 for {
5285 v_0 := v.Args[0]
5286 if v_0.Op != OpConst16 {
5287 break
5288 }
5289 if v_0.AuxInt != -1 {
5290 break
5291 }
5292 x := v.Args[1]
5293 v.reset(OpNeg16)
5294 v.AddArg(x)
5295 return true
5296 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005297 // match: (Mul16 x (Const16 <t> [c]))
5298 // cond: x.Op != OpConst16
5299 // result: (Mul16 (Const16 <t> [c]) x)
5300 for {
5301 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07005302 v_1 := v.Args[1]
5303 if v_1.Op != OpConst16 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005304 break
5305 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005306 t := v_1.Type
5307 c := v_1.AuxInt
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005308 if !(x.Op != OpConst16) {
5309 break
5310 }
5311 v.reset(OpMul16)
5312 v0 := b.NewValue0(v.Line, OpConst16, t)
5313 v0.AuxInt = c
5314 v.AddArg(v0)
5315 v.AddArg(x)
5316 return true
5317 }
5318 // match: (Mul16 (Const16 [0]) _)
5319 // cond:
5320 // result: (Const16 [0])
5321 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07005322 v_0 := v.Args[0]
5323 if v_0.Op != OpConst16 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005324 break
5325 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005326 if v_0.AuxInt != 0 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005327 break
5328 }
5329 v.reset(OpConst16)
5330 v.AuxInt = 0
5331 return true
5332 }
Keith Randall582baae2015-11-02 21:28:13 -08005333 return false
5334}
5335func rewriteValuegeneric_OpMul32(v *Value, config *Config) bool {
5336 b := v.Block
5337 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07005338 // match: (Mul32 (Const32 [c]) (Const32 [d]))
Keith Randall582baae2015-11-02 21:28:13 -08005339 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07005340 // result: (Const32 [int64(int32(c*d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01005341 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07005342 v_0 := v.Args[0]
5343 if v_0.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005344 break
Keith Randall582baae2015-11-02 21:28:13 -08005345 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005346 c := v_0.AuxInt
5347 v_1 := v.Args[1]
5348 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005349 break
Keith Randall582baae2015-11-02 21:28:13 -08005350 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005351 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005352 v.reset(OpConst32)
Keith Randall7fc56212016-03-29 16:39:53 -07005353 v.AuxInt = int64(int32(c * d))
Keith Randall582baae2015-11-02 21:28:13 -08005354 return true
5355 }
Josh Bleecher Snyderf0bab312016-07-05 10:03:02 -07005356 // match: (Mul32 (Const32 [-1]) x)
5357 // cond:
5358 // result: (Neg32 x)
5359 for {
5360 v_0 := v.Args[0]
5361 if v_0.Op != OpConst32 {
5362 break
5363 }
5364 if v_0.AuxInt != -1 {
5365 break
5366 }
5367 x := v.Args[1]
5368 v.reset(OpNeg32)
5369 v.AddArg(x)
5370 return true
5371 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005372 // match: (Mul32 x (Const32 <t> [c]))
5373 // cond: x.Op != OpConst32
5374 // result: (Mul32 (Const32 <t> [c]) x)
5375 for {
5376 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07005377 v_1 := v.Args[1]
5378 if v_1.Op != OpConst32 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005379 break
5380 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005381 t := v_1.Type
5382 c := v_1.AuxInt
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005383 if !(x.Op != OpConst32) {
5384 break
5385 }
5386 v.reset(OpMul32)
5387 v0 := b.NewValue0(v.Line, OpConst32, t)
5388 v0.AuxInt = c
5389 v.AddArg(v0)
5390 v.AddArg(x)
5391 return true
5392 }
Alexandru Moșoi1f6e9e32016-03-01 13:39:47 +01005393 // match: (Mul32 (Const32 <t> [c]) (Add32 <t> (Const32 <t> [d]) x))
5394 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07005395 // result: (Add32 (Const32 <t> [int64(int32(c*d))]) (Mul32 <t> (Const32 <t> [c]) x))
Alexandru Moșoi1f6e9e32016-03-01 13:39:47 +01005396 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07005397 v_0 := v.Args[0]
5398 if v_0.Op != OpConst32 {
Alexandru Moșoi1f6e9e32016-03-01 13:39:47 +01005399 break
5400 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005401 t := v_0.Type
5402 c := v_0.AuxInt
5403 v_1 := v.Args[1]
5404 if v_1.Op != OpAdd32 {
Alexandru Moșoi1f6e9e32016-03-01 13:39:47 +01005405 break
5406 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005407 if v_1.Type != t {
Alexandru Moșoi1f6e9e32016-03-01 13:39:47 +01005408 break
5409 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005410 v_1_0 := v_1.Args[0]
5411 if v_1_0.Op != OpConst32 {
Alexandru Moșoi1f6e9e32016-03-01 13:39:47 +01005412 break
5413 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005414 if v_1_0.Type != t {
Alexandru Moșoi1f6e9e32016-03-01 13:39:47 +01005415 break
5416 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005417 d := v_1_0.AuxInt
5418 x := v_1.Args[1]
Alexandru Moșoi1f6e9e32016-03-01 13:39:47 +01005419 v.reset(OpAdd32)
5420 v0 := b.NewValue0(v.Line, OpConst32, t)
Keith Randall7fc56212016-03-29 16:39:53 -07005421 v0.AuxInt = int64(int32(c * d))
Alexandru Moșoi1f6e9e32016-03-01 13:39:47 +01005422 v.AddArg(v0)
5423 v1 := b.NewValue0(v.Line, OpMul32, t)
5424 v2 := b.NewValue0(v.Line, OpConst32, t)
5425 v2.AuxInt = c
5426 v1.AddArg(v2)
5427 v1.AddArg(x)
5428 v.AddArg(v1)
5429 return true
5430 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005431 // match: (Mul32 (Const32 [0]) _)
5432 // cond:
5433 // result: (Const32 [0])
5434 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07005435 v_0 := v.Args[0]
5436 if v_0.Op != OpConst32 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005437 break
5438 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005439 if v_0.AuxInt != 0 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005440 break
5441 }
5442 v.reset(OpConst32)
5443 v.AuxInt = 0
5444 return true
5445 }
Keith Randall582baae2015-11-02 21:28:13 -08005446 return false
5447}
Todd Nealf6ceed22016-03-11 19:36:54 -06005448func rewriteValuegeneric_OpMul32F(v *Value, config *Config) bool {
5449 b := v.Block
5450 _ = b
5451 // match: (Mul32F (Const32F [c]) (Const32F [d]))
5452 // cond:
5453 // result: (Const32F [f2i(float64(i2f32(c) * i2f32(d)))])
5454 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07005455 v_0 := v.Args[0]
5456 if v_0.Op != OpConst32F {
Todd Nealf6ceed22016-03-11 19:36:54 -06005457 break
5458 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005459 c := v_0.AuxInt
5460 v_1 := v.Args[1]
5461 if v_1.Op != OpConst32F {
Todd Nealf6ceed22016-03-11 19:36:54 -06005462 break
5463 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005464 d := v_1.AuxInt
Todd Nealf6ceed22016-03-11 19:36:54 -06005465 v.reset(OpConst32F)
5466 v.AuxInt = f2i(float64(i2f32(c) * i2f32(d)))
5467 return true
5468 }
Cherry Zhang7d70f842016-07-06 10:04:45 -04005469 // match: (Mul32F x (Const32F [f2i(1)]))
5470 // cond:
5471 // result: x
5472 for {
5473 x := v.Args[0]
5474 v_1 := v.Args[1]
5475 if v_1.Op != OpConst32F {
5476 break
5477 }
5478 if v_1.AuxInt != f2i(1) {
5479 break
5480 }
5481 v.reset(OpCopy)
5482 v.Type = x.Type
5483 v.AddArg(x)
5484 return true
5485 }
5486 // match: (Mul32F (Const32F [f2i(1)]) x)
5487 // cond:
5488 // result: x
5489 for {
5490 v_0 := v.Args[0]
5491 if v_0.Op != OpConst32F {
5492 break
5493 }
5494 if v_0.AuxInt != f2i(1) {
5495 break
5496 }
5497 x := v.Args[1]
5498 v.reset(OpCopy)
5499 v.Type = x.Type
5500 v.AddArg(x)
5501 return true
5502 }
5503 // match: (Mul32F x (Const32F [f2i(-1)]))
5504 // cond:
5505 // result: (Neg32F x)
5506 for {
5507 x := v.Args[0]
5508 v_1 := v.Args[1]
5509 if v_1.Op != OpConst32F {
5510 break
5511 }
5512 if v_1.AuxInt != f2i(-1) {
5513 break
5514 }
5515 v.reset(OpNeg32F)
5516 v.AddArg(x)
5517 return true
5518 }
5519 // match: (Mul32F (Const32F [f2i(-1)]) x)
5520 // cond:
5521 // result: (Neg32F x)
5522 for {
5523 v_0 := v.Args[0]
5524 if v_0.Op != OpConst32F {
5525 break
5526 }
5527 if v_0.AuxInt != f2i(-1) {
5528 break
5529 }
5530 x := v.Args[1]
5531 v.reset(OpNeg32F)
5532 v.AddArg(x)
5533 return true
5534 }
Todd Nealf6ceed22016-03-11 19:36:54 -06005535 return false
5536}
Keith Randalla347ab72015-10-26 21:49:31 -07005537func rewriteValuegeneric_OpMul64(v *Value, config *Config) bool {
5538 b := v.Block
5539 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07005540 // match: (Mul64 (Const64 [c]) (Const64 [d]))
Keith Randalla347ab72015-10-26 21:49:31 -07005541 // cond:
5542 // result: (Const64 [c*d])
Alexandru Moșoi05434472016-02-04 19:52:10 +01005543 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07005544 v_0 := v.Args[0]
5545 if v_0.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005546 break
Keith Randalla347ab72015-10-26 21:49:31 -07005547 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005548 c := v_0.AuxInt
5549 v_1 := v.Args[1]
5550 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005551 break
Keith Randalla347ab72015-10-26 21:49:31 -07005552 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005553 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005554 v.reset(OpConst64)
Keith Randalla347ab72015-10-26 21:49:31 -07005555 v.AuxInt = c * d
5556 return true
5557 }
Josh Bleecher Snyderf0bab312016-07-05 10:03:02 -07005558 // match: (Mul64 (Const64 [-1]) x)
5559 // cond:
5560 // result: (Neg64 x)
5561 for {
5562 v_0 := v.Args[0]
5563 if v_0.Op != OpConst64 {
5564 break
5565 }
5566 if v_0.AuxInt != -1 {
5567 break
5568 }
5569 x := v.Args[1]
5570 v.reset(OpNeg64)
5571 v.AddArg(x)
5572 return true
5573 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005574 // match: (Mul64 x (Const64 <t> [c]))
5575 // cond: x.Op != OpConst64
5576 // result: (Mul64 (Const64 <t> [c]) x)
5577 for {
5578 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07005579 v_1 := v.Args[1]
5580 if v_1.Op != OpConst64 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005581 break
5582 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005583 t := v_1.Type
5584 c := v_1.AuxInt
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005585 if !(x.Op != OpConst64) {
5586 break
5587 }
5588 v.reset(OpMul64)
5589 v0 := b.NewValue0(v.Line, OpConst64, t)
5590 v0.AuxInt = c
5591 v.AddArg(v0)
5592 v.AddArg(x)
5593 return true
5594 }
Alexandru Moșoi1f6e9e32016-03-01 13:39:47 +01005595 // match: (Mul64 (Const64 <t> [c]) (Add64 <t> (Const64 <t> [d]) x))
5596 // cond:
5597 // result: (Add64 (Const64 <t> [c*d]) (Mul64 <t> (Const64 <t> [c]) x))
5598 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07005599 v_0 := v.Args[0]
5600 if v_0.Op != OpConst64 {
Alexandru Moșoi1f6e9e32016-03-01 13:39:47 +01005601 break
5602 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005603 t := v_0.Type
5604 c := v_0.AuxInt
5605 v_1 := v.Args[1]
5606 if v_1.Op != OpAdd64 {
Alexandru Moșoi1f6e9e32016-03-01 13:39:47 +01005607 break
5608 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005609 if v_1.Type != t {
Alexandru Moșoi1f6e9e32016-03-01 13:39:47 +01005610 break
5611 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005612 v_1_0 := v_1.Args[0]
5613 if v_1_0.Op != OpConst64 {
Alexandru Moșoi1f6e9e32016-03-01 13:39:47 +01005614 break
5615 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005616 if v_1_0.Type != t {
Alexandru Moșoi1f6e9e32016-03-01 13:39:47 +01005617 break
5618 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005619 d := v_1_0.AuxInt
5620 x := v_1.Args[1]
Alexandru Moșoi1f6e9e32016-03-01 13:39:47 +01005621 v.reset(OpAdd64)
5622 v0 := b.NewValue0(v.Line, OpConst64, t)
5623 v0.AuxInt = c * d
5624 v.AddArg(v0)
5625 v1 := b.NewValue0(v.Line, OpMul64, t)
5626 v2 := b.NewValue0(v.Line, OpConst64, t)
5627 v2.AuxInt = c
5628 v1.AddArg(v2)
5629 v1.AddArg(x)
5630 v.AddArg(v1)
5631 return true
5632 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005633 // match: (Mul64 (Const64 [0]) _)
5634 // cond:
5635 // result: (Const64 [0])
5636 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07005637 v_0 := v.Args[0]
5638 if v_0.Op != OpConst64 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005639 break
5640 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005641 if v_0.AuxInt != 0 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005642 break
5643 }
5644 v.reset(OpConst64)
5645 v.AuxInt = 0
5646 return true
5647 }
Keith Randalla347ab72015-10-26 21:49:31 -07005648 return false
5649}
Todd Nealf6ceed22016-03-11 19:36:54 -06005650func rewriteValuegeneric_OpMul64F(v *Value, config *Config) bool {
5651 b := v.Block
5652 _ = b
5653 // match: (Mul64F (Const64F [c]) (Const64F [d]))
5654 // cond:
5655 // result: (Const64F [f2i(i2f(c) * i2f(d))])
5656 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07005657 v_0 := v.Args[0]
5658 if v_0.Op != OpConst64F {
Todd Nealf6ceed22016-03-11 19:36:54 -06005659 break
5660 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005661 c := v_0.AuxInt
5662 v_1 := v.Args[1]
5663 if v_1.Op != OpConst64F {
Todd Nealf6ceed22016-03-11 19:36:54 -06005664 break
5665 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005666 d := v_1.AuxInt
Todd Nealf6ceed22016-03-11 19:36:54 -06005667 v.reset(OpConst64F)
5668 v.AuxInt = f2i(i2f(c) * i2f(d))
5669 return true
5670 }
Cherry Zhang7d70f842016-07-06 10:04:45 -04005671 // match: (Mul64F x (Const64F [f2i(1)]))
5672 // cond:
5673 // result: x
5674 for {
5675 x := v.Args[0]
5676 v_1 := v.Args[1]
5677 if v_1.Op != OpConst64F {
5678 break
5679 }
5680 if v_1.AuxInt != f2i(1) {
5681 break
5682 }
5683 v.reset(OpCopy)
5684 v.Type = x.Type
5685 v.AddArg(x)
5686 return true
5687 }
5688 // match: (Mul64F (Const64F [f2i(1)]) x)
5689 // cond:
5690 // result: x
5691 for {
5692 v_0 := v.Args[0]
5693 if v_0.Op != OpConst64F {
5694 break
5695 }
5696 if v_0.AuxInt != f2i(1) {
5697 break
5698 }
5699 x := v.Args[1]
5700 v.reset(OpCopy)
5701 v.Type = x.Type
5702 v.AddArg(x)
5703 return true
5704 }
5705 // match: (Mul64F x (Const64F [f2i(-1)]))
5706 // cond:
5707 // result: (Neg64F x)
5708 for {
5709 x := v.Args[0]
5710 v_1 := v.Args[1]
5711 if v_1.Op != OpConst64F {
5712 break
5713 }
5714 if v_1.AuxInt != f2i(-1) {
5715 break
5716 }
5717 v.reset(OpNeg64F)
5718 v.AddArg(x)
5719 return true
5720 }
5721 // match: (Mul64F (Const64F [f2i(-1)]) x)
5722 // cond:
5723 // result: (Neg64F x)
5724 for {
5725 v_0 := v.Args[0]
5726 if v_0.Op != OpConst64F {
5727 break
5728 }
5729 if v_0.AuxInt != f2i(-1) {
5730 break
5731 }
5732 x := v.Args[1]
5733 v.reset(OpNeg64F)
5734 v.AddArg(x)
5735 return true
5736 }
Todd Nealf6ceed22016-03-11 19:36:54 -06005737 return false
5738}
Keith Randall582baae2015-11-02 21:28:13 -08005739func rewriteValuegeneric_OpMul8(v *Value, config *Config) bool {
Keith Randalla347ab72015-10-26 21:49:31 -07005740 b := v.Block
5741 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07005742 // match: (Mul8 (Const8 [c]) (Const8 [d]))
Keith Randalla347ab72015-10-26 21:49:31 -07005743 // cond:
Keith Randallfa9435c2016-04-26 12:08:31 -07005744 // result: (Const8 [int64(int8(c*d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01005745 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07005746 v_0 := v.Args[0]
5747 if v_0.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005748 break
Keith Randalla347ab72015-10-26 21:49:31 -07005749 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005750 c := v_0.AuxInt
5751 v_1 := v.Args[1]
5752 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005753 break
Keith Randalla347ab72015-10-26 21:49:31 -07005754 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005755 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005756 v.reset(OpConst8)
Keith Randall7fc56212016-03-29 16:39:53 -07005757 v.AuxInt = int64(int8(c * d))
Keith Randalla347ab72015-10-26 21:49:31 -07005758 return true
5759 }
Josh Bleecher Snyderf0bab312016-07-05 10:03:02 -07005760 // match: (Mul8 (Const8 [-1]) x)
5761 // cond:
5762 // result: (Neg8 x)
5763 for {
5764 v_0 := v.Args[0]
5765 if v_0.Op != OpConst8 {
5766 break
5767 }
5768 if v_0.AuxInt != -1 {
5769 break
5770 }
5771 x := v.Args[1]
5772 v.reset(OpNeg8)
5773 v.AddArg(x)
5774 return true
5775 }
Keith Randallfa9435c2016-04-26 12:08:31 -07005776 // match: (Mul8 x (Const8 <t> [c]))
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005777 // cond: x.Op != OpConst8
Keith Randallfa9435c2016-04-26 12:08:31 -07005778 // result: (Mul8 (Const8 <t> [c]) x)
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005779 for {
5780 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07005781 v_1 := v.Args[1]
5782 if v_1.Op != OpConst8 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005783 break
5784 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005785 t := v_1.Type
5786 c := v_1.AuxInt
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005787 if !(x.Op != OpConst8) {
5788 break
5789 }
5790 v.reset(OpMul8)
5791 v0 := b.NewValue0(v.Line, OpConst8, t)
5792 v0.AuxInt = c
5793 v.AddArg(v0)
5794 v.AddArg(x)
5795 return true
5796 }
Keith Randallfa9435c2016-04-26 12:08:31 -07005797 // match: (Mul8 (Const8 [0]) _)
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005798 // cond:
Keith Randallfa9435c2016-04-26 12:08:31 -07005799 // result: (Const8 [0])
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005800 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07005801 v_0 := v.Args[0]
5802 if v_0.Op != OpConst8 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005803 break
5804 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005805 if v_0.AuxInt != 0 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005806 break
5807 }
5808 v.reset(OpConst8)
5809 v.AuxInt = 0
5810 return true
5811 }
Keith Randalla347ab72015-10-26 21:49:31 -07005812 return false
5813}
Alexandru Moșoi964dda92016-02-08 18:55:56 +01005814func rewriteValuegeneric_OpNeg16(v *Value, config *Config) bool {
5815 b := v.Block
5816 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005817 // match: (Neg16 (Sub16 x y))
5818 // cond:
5819 // result: (Sub16 y x)
5820 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07005821 v_0 := v.Args[0]
5822 if v_0.Op != OpSub16 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005823 break
5824 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005825 x := v_0.Args[0]
5826 y := v_0.Args[1]
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005827 v.reset(OpSub16)
5828 v.AddArg(y)
5829 v.AddArg(x)
5830 return true
5831 }
Alexandru Moșoi964dda92016-02-08 18:55:56 +01005832 return false
5833}
5834func rewriteValuegeneric_OpNeg32(v *Value, config *Config) bool {
5835 b := v.Block
5836 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005837 // match: (Neg32 (Sub32 x y))
5838 // cond:
5839 // result: (Sub32 y x)
5840 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07005841 v_0 := v.Args[0]
5842 if v_0.Op != OpSub32 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005843 break
5844 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005845 x := v_0.Args[0]
5846 y := v_0.Args[1]
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005847 v.reset(OpSub32)
5848 v.AddArg(y)
5849 v.AddArg(x)
5850 return true
5851 }
Alexandru Moșoi964dda92016-02-08 18:55:56 +01005852 return false
5853}
5854func rewriteValuegeneric_OpNeg64(v *Value, config *Config) bool {
5855 b := v.Block
5856 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005857 // match: (Neg64 (Sub64 x y))
5858 // cond:
5859 // result: (Sub64 y x)
5860 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07005861 v_0 := v.Args[0]
5862 if v_0.Op != OpSub64 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005863 break
5864 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005865 x := v_0.Args[0]
5866 y := v_0.Args[1]
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005867 v.reset(OpSub64)
5868 v.AddArg(y)
5869 v.AddArg(x)
5870 return true
5871 }
Alexandru Moșoi964dda92016-02-08 18:55:56 +01005872 return false
5873}
5874func rewriteValuegeneric_OpNeg8(v *Value, config *Config) bool {
5875 b := v.Block
5876 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07005877 // match: (Neg8 (Sub8 x y))
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005878 // cond:
Keith Randallfa9435c2016-04-26 12:08:31 -07005879 // result: (Sub8 y x)
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005880 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07005881 v_0 := v.Args[0]
5882 if v_0.Op != OpSub8 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005883 break
5884 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005885 x := v_0.Args[0]
5886 y := v_0.Args[1]
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005887 v.reset(OpSub8)
5888 v.AddArg(y)
5889 v.AddArg(x)
5890 return true
5891 }
Alexandru Moșoi964dda92016-02-08 18:55:56 +01005892 return false
5893}
Keith Randalla347ab72015-10-26 21:49:31 -07005894func rewriteValuegeneric_OpNeq16(v *Value, config *Config) bool {
5895 b := v.Block
5896 _ = b
5897 // match: (Neq16 x x)
5898 // cond:
5899 // result: (ConstBool [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01005900 for {
Keith Randalla347ab72015-10-26 21:49:31 -07005901 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07005902 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005903 break
Keith Randalla347ab72015-10-26 21:49:31 -07005904 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005905 v.reset(OpConstBool)
Keith Randalla347ab72015-10-26 21:49:31 -07005906 v.AuxInt = 0
5907 return true
5908 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01005909 // match: (Neq16 (Const16 <t> [c]) (Add16 (Const16 <t> [d]) x))
5910 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07005911 // result: (Neq16 (Const16 <t> [int64(int16(c-d))]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01005912 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07005913 v_0 := v.Args[0]
5914 if v_0.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005915 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01005916 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005917 t := v_0.Type
5918 c := v_0.AuxInt
5919 v_1 := v.Args[1]
5920 if v_1.Op != OpAdd16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005921 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01005922 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005923 v_1_0 := v_1.Args[0]
5924 if v_1_0.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005925 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01005926 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005927 if v_1_0.Type != t {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005928 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01005929 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005930 d := v_1_0.AuxInt
5931 x := v_1.Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005932 v.reset(OpNeq16)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005933 v0 := b.NewValue0(v.Line, OpConst16, t)
Keith Randall7fc56212016-03-29 16:39:53 -07005934 v0.AuxInt = int64(int16(c - d))
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01005935 v.AddArg(v0)
5936 v.AddArg(x)
5937 return true
5938 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01005939 // match: (Neq16 x (Const16 <t> [c]))
5940 // cond: x.Op != OpConst16
5941 // result: (Neq16 (Const16 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01005942 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01005943 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07005944 v_1 := v.Args[1]
5945 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005946 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01005947 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005948 t := v_1.Type
5949 c := v_1.AuxInt
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01005950 if !(x.Op != OpConst16) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005951 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01005952 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005953 v.reset(OpNeq16)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005954 v0 := b.NewValue0(v.Line, OpConst16, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01005955 v0.AuxInt = c
5956 v.AddArg(v0)
5957 v.AddArg(x)
5958 return true
5959 }
Todd Nealcdc36252015-10-27 17:46:53 -05005960 // match: (Neq16 (Const16 [c]) (Const16 [d]))
5961 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07005962 // result: (ConstBool [b2i(c != d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01005963 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07005964 v_0 := v.Args[0]
5965 if v_0.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005966 break
Todd Nealcdc36252015-10-27 17:46:53 -05005967 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005968 c := v_0.AuxInt
5969 v_1 := v.Args[1]
5970 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005971 break
Todd Nealcdc36252015-10-27 17:46:53 -05005972 }
Keith Randall259b7ed2016-03-21 16:18:45 -07005973 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005974 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07005975 v.AuxInt = b2i(c != d)
Todd Nealcdc36252015-10-27 17:46:53 -05005976 return true
5977 }
Keith Randalla347ab72015-10-26 21:49:31 -07005978 return false
5979}
5980func rewriteValuegeneric_OpNeq32(v *Value, config *Config) bool {
5981 b := v.Block
5982 _ = b
5983 // match: (Neq32 x x)
5984 // cond:
5985 // result: (ConstBool [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01005986 for {
Keith Randalla347ab72015-10-26 21:49:31 -07005987 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07005988 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005989 break
Keith Randalla347ab72015-10-26 21:49:31 -07005990 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005991 v.reset(OpConstBool)
Keith Randalla347ab72015-10-26 21:49:31 -07005992 v.AuxInt = 0
5993 return true
5994 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01005995 // match: (Neq32 (Const32 <t> [c]) (Add32 (Const32 <t> [d]) x))
5996 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07005997 // result: (Neq32 (Const32 <t> [int64(int32(c-d))]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01005998 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07005999 v_0 := v.Args[0]
6000 if v_0.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006001 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006002 }
Keith Randall259b7ed2016-03-21 16:18:45 -07006003 t := v_0.Type
6004 c := v_0.AuxInt
6005 v_1 := v.Args[1]
6006 if v_1.Op != OpAdd32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006007 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006008 }
Keith Randall259b7ed2016-03-21 16:18:45 -07006009 v_1_0 := v_1.Args[0]
6010 if v_1_0.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006011 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006012 }
Keith Randall259b7ed2016-03-21 16:18:45 -07006013 if v_1_0.Type != t {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006014 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006015 }
Keith Randall259b7ed2016-03-21 16:18:45 -07006016 d := v_1_0.AuxInt
6017 x := v_1.Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006018 v.reset(OpNeq32)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006019 v0 := b.NewValue0(v.Line, OpConst32, t)
Keith Randall7fc56212016-03-29 16:39:53 -07006020 v0.AuxInt = int64(int32(c - d))
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006021 v.AddArg(v0)
6022 v.AddArg(x)
6023 return true
6024 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006025 // match: (Neq32 x (Const32 <t> [c]))
6026 // cond: x.Op != OpConst32
6027 // result: (Neq32 (Const32 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01006028 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006029 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07006030 v_1 := v.Args[1]
6031 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006032 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006033 }
Keith Randall259b7ed2016-03-21 16:18:45 -07006034 t := v_1.Type
6035 c := v_1.AuxInt
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006036 if !(x.Op != OpConst32) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006037 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006038 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006039 v.reset(OpNeq32)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006040 v0 := b.NewValue0(v.Line, OpConst32, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006041 v0.AuxInt = c
6042 v.AddArg(v0)
6043 v.AddArg(x)
6044 return true
6045 }
Todd Nealcdc36252015-10-27 17:46:53 -05006046 // match: (Neq32 (Const32 [c]) (Const32 [d]))
6047 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07006048 // result: (ConstBool [b2i(c != d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01006049 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07006050 v_0 := v.Args[0]
6051 if v_0.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006052 break
Todd Nealcdc36252015-10-27 17:46:53 -05006053 }
Keith Randall259b7ed2016-03-21 16:18:45 -07006054 c := v_0.AuxInt
6055 v_1 := v.Args[1]
6056 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006057 break
Todd Nealcdc36252015-10-27 17:46:53 -05006058 }
Keith Randall259b7ed2016-03-21 16:18:45 -07006059 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006060 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07006061 v.AuxInt = b2i(c != d)
Todd Nealcdc36252015-10-27 17:46:53 -05006062 return true
6063 }
Keith Randalla347ab72015-10-26 21:49:31 -07006064 return false
6065}
6066func rewriteValuegeneric_OpNeq64(v *Value, config *Config) bool {
6067 b := v.Block
6068 _ = b
6069 // match: (Neq64 x x)
6070 // cond:
6071 // result: (ConstBool [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01006072 for {
Keith Randalla347ab72015-10-26 21:49:31 -07006073 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07006074 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006075 break
Keith Randalla347ab72015-10-26 21:49:31 -07006076 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006077 v.reset(OpConstBool)
Keith Randalla347ab72015-10-26 21:49:31 -07006078 v.AuxInt = 0
6079 return true
6080 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006081 // match: (Neq64 (Const64 <t> [c]) (Add64 (Const64 <t> [d]) x))
6082 // cond:
6083 // result: (Neq64 (Const64 <t> [c-d]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01006084 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07006085 v_0 := v.Args[0]
6086 if v_0.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006087 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006088 }
Keith Randall259b7ed2016-03-21 16:18:45 -07006089 t := v_0.Type
6090 c := v_0.AuxInt
6091 v_1 := v.Args[1]
6092 if v_1.Op != OpAdd64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006093 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006094 }
Keith Randall259b7ed2016-03-21 16:18:45 -07006095 v_1_0 := v_1.Args[0]
6096 if v_1_0.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006097 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006098 }
Keith Randall259b7ed2016-03-21 16:18:45 -07006099 if v_1_0.Type != t {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006100 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006101 }
Keith Randall259b7ed2016-03-21 16:18:45 -07006102 d := v_1_0.AuxInt
6103 x := v_1.Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006104 v.reset(OpNeq64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006105 v0 := b.NewValue0(v.Line, OpConst64, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006106 v0.AuxInt = c - d
6107 v.AddArg(v0)
6108 v.AddArg(x)
6109 return true
6110 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006111 // match: (Neq64 x (Const64 <t> [c]))
6112 // cond: x.Op != OpConst64
6113 // result: (Neq64 (Const64 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01006114 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006115 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07006116 v_1 := v.Args[1]
6117 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006118 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006119 }
Keith Randall259b7ed2016-03-21 16:18:45 -07006120 t := v_1.Type
6121 c := v_1.AuxInt
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006122 if !(x.Op != OpConst64) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006123 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006124 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006125 v.reset(OpNeq64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006126 v0 := b.NewValue0(v.Line, OpConst64, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006127 v0.AuxInt = c
6128 v.AddArg(v0)
6129 v.AddArg(x)
6130 return true
6131 }
Todd Nealcdc36252015-10-27 17:46:53 -05006132 // match: (Neq64 (Const64 [c]) (Const64 [d]))
6133 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07006134 // result: (ConstBool [b2i(c != d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01006135 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07006136 v_0 := v.Args[0]
6137 if v_0.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006138 break
Todd Nealcdc36252015-10-27 17:46:53 -05006139 }
Keith Randall259b7ed2016-03-21 16:18:45 -07006140 c := v_0.AuxInt
6141 v_1 := v.Args[1]
6142 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006143 break
Todd Nealcdc36252015-10-27 17:46:53 -05006144 }
Keith Randall259b7ed2016-03-21 16:18:45 -07006145 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006146 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07006147 v.AuxInt = b2i(c != d)
Todd Nealcdc36252015-10-27 17:46:53 -05006148 return true
6149 }
Keith Randalla347ab72015-10-26 21:49:31 -07006150 return false
6151}
6152func rewriteValuegeneric_OpNeq8(v *Value, config *Config) bool {
6153 b := v.Block
6154 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07006155 // match: (Neq8 x x)
Keith Randalla347ab72015-10-26 21:49:31 -07006156 // cond:
6157 // result: (ConstBool [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01006158 for {
Keith Randalla347ab72015-10-26 21:49:31 -07006159 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07006160 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006161 break
Keith Randalla347ab72015-10-26 21:49:31 -07006162 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006163 v.reset(OpConstBool)
Keith Randalla347ab72015-10-26 21:49:31 -07006164 v.AuxInt = 0
6165 return true
6166 }
Keith Randallfa9435c2016-04-26 12:08:31 -07006167 // match: (Neq8 (Const8 <t> [c]) (Add8 (Const8 <t> [d]) x))
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006168 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07006169 // result: (Neq8 (Const8 <t> [int64(int8(c-d))]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01006170 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07006171 v_0 := v.Args[0]
6172 if v_0.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006173 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006174 }
Keith Randall259b7ed2016-03-21 16:18:45 -07006175 t := v_0.Type
6176 c := v_0.AuxInt
6177 v_1 := v.Args[1]
6178 if v_1.Op != OpAdd8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006179 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006180 }
Keith Randall259b7ed2016-03-21 16:18:45 -07006181 v_1_0 := v_1.Args[0]
6182 if v_1_0.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006183 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006184 }
Keith Randall259b7ed2016-03-21 16:18:45 -07006185 if v_1_0.Type != t {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006186 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006187 }
Keith Randall259b7ed2016-03-21 16:18:45 -07006188 d := v_1_0.AuxInt
6189 x := v_1.Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006190 v.reset(OpNeq8)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006191 v0 := b.NewValue0(v.Line, OpConst8, t)
Keith Randall7fc56212016-03-29 16:39:53 -07006192 v0.AuxInt = int64(int8(c - d))
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006193 v.AddArg(v0)
6194 v.AddArg(x)
6195 return true
6196 }
Keith Randallfa9435c2016-04-26 12:08:31 -07006197 // match: (Neq8 x (Const8 <t> [c]))
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006198 // cond: x.Op != OpConst8
Keith Randallfa9435c2016-04-26 12:08:31 -07006199 // result: (Neq8 (Const8 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01006200 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006201 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07006202 v_1 := v.Args[1]
6203 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006204 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006205 }
Keith Randall259b7ed2016-03-21 16:18:45 -07006206 t := v_1.Type
6207 c := v_1.AuxInt
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006208 if !(x.Op != OpConst8) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006209 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006210 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006211 v.reset(OpNeq8)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006212 v0 := b.NewValue0(v.Line, OpConst8, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01006213 v0.AuxInt = c
6214 v.AddArg(v0)
6215 v.AddArg(x)
6216 return true
6217 }
Todd Nealcdc36252015-10-27 17:46:53 -05006218 // match: (Neq8 (Const8 [c]) (Const8 [d]))
6219 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -07006220 // result: (ConstBool [b2i(c != d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01006221 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07006222 v_0 := v.Args[0]
6223 if v_0.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006224 break
Todd Nealcdc36252015-10-27 17:46:53 -05006225 }
Keith Randall259b7ed2016-03-21 16:18:45 -07006226 c := v_0.AuxInt
6227 v_1 := v.Args[1]
6228 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006229 break
Todd Nealcdc36252015-10-27 17:46:53 -05006230 }
Keith Randall259b7ed2016-03-21 16:18:45 -07006231 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006232 v.reset(OpConstBool)
Keith Randall7fc56212016-03-29 16:39:53 -07006233 v.AuxInt = b2i(c != d)
Todd Nealcdc36252015-10-27 17:46:53 -05006234 return true
6235 }
Keith Randalla347ab72015-10-26 21:49:31 -07006236 return false
6237}
Alexandru Moșoi8b923972016-04-24 21:21:07 +02006238func rewriteValuegeneric_OpNeqB(v *Value, config *Config) bool {
6239 b := v.Block
6240 _ = b
6241 // match: (NeqB (ConstBool [c]) (ConstBool [d]))
6242 // cond:
6243 // result: (ConstBool [b2i(c != d)])
6244 for {
6245 v_0 := v.Args[0]
6246 if v_0.Op != OpConstBool {
6247 break
6248 }
6249 c := v_0.AuxInt
6250 v_1 := v.Args[1]
6251 if v_1.Op != OpConstBool {
6252 break
6253 }
6254 d := v_1.AuxInt
6255 v.reset(OpConstBool)
6256 v.AuxInt = b2i(c != d)
6257 return true
6258 }
6259 // match: (NeqB (ConstBool [0]) x)
6260 // cond:
6261 // result: x
6262 for {
6263 v_0 := v.Args[0]
6264 if v_0.Op != OpConstBool {
6265 break
6266 }
6267 if v_0.AuxInt != 0 {
6268 break
6269 }
6270 x := v.Args[1]
6271 v.reset(OpCopy)
6272 v.Type = x.Type
6273 v.AddArg(x)
6274 return true
6275 }
6276 // match: (NeqB (ConstBool [1]) x)
6277 // cond:
6278 // result: (Not x)
6279 for {
6280 v_0 := v.Args[0]
6281 if v_0.Op != OpConstBool {
6282 break
6283 }
6284 if v_0.AuxInt != 1 {
6285 break
6286 }
6287 x := v.Args[1]
6288 v.reset(OpNot)
6289 v.AddArg(x)
6290 return true
6291 }
6292 return false
6293}
Keith Randalla347ab72015-10-26 21:49:31 -07006294func rewriteValuegeneric_OpNeqInter(v *Value, config *Config) bool {
6295 b := v.Block
6296 _ = b
6297 // match: (NeqInter x y)
6298 // cond:
6299 // result: (NeqPtr (ITab x) (ITab y))
Alexandru Moșoi05434472016-02-04 19:52:10 +01006300 for {
Keith Randalla347ab72015-10-26 21:49:31 -07006301 x := v.Args[0]
6302 y := v.Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006303 v.reset(OpNeqPtr)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006304 v0 := b.NewValue0(v.Line, OpITab, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07006305 v0.AddArg(x)
Keith Randalla347ab72015-10-26 21:49:31 -07006306 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006307 v1 := b.NewValue0(v.Line, OpITab, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07006308 v1.AddArg(y)
Keith Randalla347ab72015-10-26 21:49:31 -07006309 v.AddArg(v1)
6310 return true
6311 }
Keith Randalla347ab72015-10-26 21:49:31 -07006312}
6313func rewriteValuegeneric_OpNeqPtr(v *Value, config *Config) bool {
6314 b := v.Block
6315 _ = b
6316 // match: (NeqPtr p (ConstNil))
6317 // cond:
6318 // result: (IsNonNil p)
Alexandru Moșoi05434472016-02-04 19:52:10 +01006319 for {
Keith Randalla347ab72015-10-26 21:49:31 -07006320 p := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07006321 v_1 := v.Args[1]
6322 if v_1.Op != OpConstNil {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006323 break
Keith Randalla347ab72015-10-26 21:49:31 -07006324 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006325 v.reset(OpIsNonNil)
Keith Randalla347ab72015-10-26 21:49:31 -07006326 v.AddArg(p)
6327 return true
6328 }
Keith Randalla347ab72015-10-26 21:49:31 -07006329 // match: (NeqPtr (ConstNil) p)
6330 // cond:
6331 // result: (IsNonNil p)
Alexandru Moșoi05434472016-02-04 19:52:10 +01006332 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07006333 v_0 := v.Args[0]
6334 if v_0.Op != OpConstNil {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006335 break
Keith Randalla347ab72015-10-26 21:49:31 -07006336 }
6337 p := v.Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006338 v.reset(OpIsNonNil)
Keith Randalla347ab72015-10-26 21:49:31 -07006339 v.AddArg(p)
6340 return true
6341 }
Keith Randalla347ab72015-10-26 21:49:31 -07006342 return false
6343}
6344func rewriteValuegeneric_OpNeqSlice(v *Value, config *Config) bool {
6345 b := v.Block
6346 _ = b
6347 // match: (NeqSlice x y)
6348 // cond:
6349 // result: (NeqPtr (SlicePtr x) (SlicePtr y))
Alexandru Moșoi05434472016-02-04 19:52:10 +01006350 for {
Keith Randalla347ab72015-10-26 21:49:31 -07006351 x := v.Args[0]
6352 y := v.Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006353 v.reset(OpNeqPtr)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006354 v0 := b.NewValue0(v.Line, OpSlicePtr, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07006355 v0.AddArg(x)
Keith Randalla347ab72015-10-26 21:49:31 -07006356 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006357 v1 := b.NewValue0(v.Line, OpSlicePtr, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07006358 v1.AddArg(y)
Keith Randalla347ab72015-10-26 21:49:31 -07006359 v.AddArg(v1)
6360 return true
6361 }
Keith Randalla347ab72015-10-26 21:49:31 -07006362}
Keith Randall3134ab32016-09-13 17:01:01 -07006363func rewriteValuegeneric_OpNilCheck(v *Value, config *Config) bool {
6364 b := v.Block
6365 _ = b
6366 // match: (NilCheck (GetG mem) mem)
6367 // cond:
6368 // result: mem
6369 for {
6370 v_0 := v.Args[0]
6371 if v_0.Op != OpGetG {
6372 break
6373 }
6374 mem := v_0.Args[0]
6375 if mem != v.Args[1] {
6376 break
6377 }
6378 v.reset(OpCopy)
6379 v.Type = mem.Type
6380 v.AddArg(mem)
6381 return true
6382 }
Cherry Zhang4d07d3e2016-09-28 10:20:24 -04006383 // match: (NilCheck (Load (OffPtr [c] (SP)) mem) mem)
6384 // cond: mem.Op == OpStaticCall && isSameSym(mem.Aux, "runtime.newobject") && c == config.ctxt.FixedFrameSize() + config.RegSize && warnRule(config.Debug_checknil() && int(v.Line) > 1, v, "removed nil check")
6385 // result: (Invalid)
6386 for {
6387 v_0 := v.Args[0]
6388 if v_0.Op != OpLoad {
6389 break
6390 }
6391 v_0_0 := v_0.Args[0]
6392 if v_0_0.Op != OpOffPtr {
6393 break
6394 }
6395 c := v_0_0.AuxInt
6396 v_0_0_0 := v_0_0.Args[0]
6397 if v_0_0_0.Op != OpSP {
6398 break
6399 }
6400 mem := v_0.Args[1]
6401 if mem != v.Args[1] {
6402 break
6403 }
6404 if !(mem.Op == OpStaticCall && isSameSym(mem.Aux, "runtime.newobject") && c == config.ctxt.FixedFrameSize()+config.RegSize && warnRule(config.Debug_checknil() && int(v.Line) > 1, v, "removed nil check")) {
6405 break
6406 }
6407 v.reset(OpInvalid)
6408 return true
6409 }
6410 // match: (NilCheck (OffPtr (Load (OffPtr [c] (SP)) mem)) mem)
6411 // cond: mem.Op == OpStaticCall && isSameSym(mem.Aux, "runtime.newobject") && c == config.ctxt.FixedFrameSize() + config.RegSize && warnRule(config.Debug_checknil() && int(v.Line) > 1, v, "removed nil check")
6412 // result: (Invalid)
6413 for {
6414 v_0 := v.Args[0]
6415 if v_0.Op != OpOffPtr {
6416 break
6417 }
6418 v_0_0 := v_0.Args[0]
6419 if v_0_0.Op != OpLoad {
6420 break
6421 }
6422 v_0_0_0 := v_0_0.Args[0]
6423 if v_0_0_0.Op != OpOffPtr {
6424 break
6425 }
6426 c := v_0_0_0.AuxInt
6427 v_0_0_0_0 := v_0_0_0.Args[0]
6428 if v_0_0_0_0.Op != OpSP {
6429 break
6430 }
6431 mem := v_0_0.Args[1]
6432 if mem != v.Args[1] {
6433 break
6434 }
6435 if !(mem.Op == OpStaticCall && isSameSym(mem.Aux, "runtime.newobject") && c == config.ctxt.FixedFrameSize()+config.RegSize && warnRule(config.Debug_checknil() && int(v.Line) > 1, v, "removed nil check")) {
6436 break
6437 }
6438 v.reset(OpInvalid)
6439 return true
6440 }
Keith Randall3134ab32016-09-13 17:01:01 -07006441 return false
6442}
Martin Möhrmann00459f052016-08-31 12:37:19 +02006443func rewriteValuegeneric_OpNot(v *Value, config *Config) bool {
6444 b := v.Block
6445 _ = b
6446 // match: (Not (Eq64 x y))
6447 // cond:
6448 // result: (Neq64 x y)
6449 for {
6450 v_0 := v.Args[0]
6451 if v_0.Op != OpEq64 {
6452 break
6453 }
6454 x := v_0.Args[0]
6455 y := v_0.Args[1]
6456 v.reset(OpNeq64)
6457 v.AddArg(x)
6458 v.AddArg(y)
6459 return true
6460 }
6461 // match: (Not (Eq32 x y))
6462 // cond:
6463 // result: (Neq32 x y)
6464 for {
6465 v_0 := v.Args[0]
6466 if v_0.Op != OpEq32 {
6467 break
6468 }
6469 x := v_0.Args[0]
6470 y := v_0.Args[1]
6471 v.reset(OpNeq32)
6472 v.AddArg(x)
6473 v.AddArg(y)
6474 return true
6475 }
6476 // match: (Not (Eq16 x y))
6477 // cond:
6478 // result: (Neq16 x y)
6479 for {
6480 v_0 := v.Args[0]
6481 if v_0.Op != OpEq16 {
6482 break
6483 }
6484 x := v_0.Args[0]
6485 y := v_0.Args[1]
6486 v.reset(OpNeq16)
6487 v.AddArg(x)
6488 v.AddArg(y)
6489 return true
6490 }
6491 // match: (Not (Eq8 x y))
6492 // cond:
6493 // result: (Neq8 x y)
6494 for {
6495 v_0 := v.Args[0]
6496 if v_0.Op != OpEq8 {
6497 break
6498 }
6499 x := v_0.Args[0]
6500 y := v_0.Args[1]
6501 v.reset(OpNeq8)
6502 v.AddArg(x)
6503 v.AddArg(y)
6504 return true
6505 }
6506 // match: (Not (EqB x y))
6507 // cond:
6508 // result: (NeqB x y)
6509 for {
6510 v_0 := v.Args[0]
6511 if v_0.Op != OpEqB {
6512 break
6513 }
6514 x := v_0.Args[0]
6515 y := v_0.Args[1]
6516 v.reset(OpNeqB)
6517 v.AddArg(x)
6518 v.AddArg(y)
6519 return true
6520 }
6521 // match: (Not (Neq64 x y))
6522 // cond:
6523 // result: (Eq64 x y)
6524 for {
6525 v_0 := v.Args[0]
6526 if v_0.Op != OpNeq64 {
6527 break
6528 }
6529 x := v_0.Args[0]
6530 y := v_0.Args[1]
6531 v.reset(OpEq64)
6532 v.AddArg(x)
6533 v.AddArg(y)
6534 return true
6535 }
6536 // match: (Not (Neq32 x y))
6537 // cond:
6538 // result: (Eq32 x y)
6539 for {
6540 v_0 := v.Args[0]
6541 if v_0.Op != OpNeq32 {
6542 break
6543 }
6544 x := v_0.Args[0]
6545 y := v_0.Args[1]
6546 v.reset(OpEq32)
6547 v.AddArg(x)
6548 v.AddArg(y)
6549 return true
6550 }
6551 // match: (Not (Neq16 x y))
6552 // cond:
6553 // result: (Eq16 x y)
6554 for {
6555 v_0 := v.Args[0]
6556 if v_0.Op != OpNeq16 {
6557 break
6558 }
6559 x := v_0.Args[0]
6560 y := v_0.Args[1]
6561 v.reset(OpEq16)
6562 v.AddArg(x)
6563 v.AddArg(y)
6564 return true
6565 }
6566 // match: (Not (Neq8 x y))
6567 // cond:
6568 // result: (Eq8 x y)
6569 for {
6570 v_0 := v.Args[0]
6571 if v_0.Op != OpNeq8 {
6572 break
6573 }
6574 x := v_0.Args[0]
6575 y := v_0.Args[1]
6576 v.reset(OpEq8)
6577 v.AddArg(x)
6578 v.AddArg(y)
6579 return true
6580 }
6581 // match: (Not (NeqB x y))
6582 // cond:
6583 // result: (EqB x y)
6584 for {
6585 v_0 := v.Args[0]
6586 if v_0.Op != OpNeqB {
6587 break
6588 }
6589 x := v_0.Args[0]
6590 y := v_0.Args[1]
6591 v.reset(OpEqB)
6592 v.AddArg(x)
6593 v.AddArg(y)
6594 return true
6595 }
6596 // match: (Not (Greater64 x y))
6597 // cond:
6598 // result: (Leq64 x y)
6599 for {
6600 v_0 := v.Args[0]
6601 if v_0.Op != OpGreater64 {
6602 break
6603 }
6604 x := v_0.Args[0]
6605 y := v_0.Args[1]
6606 v.reset(OpLeq64)
6607 v.AddArg(x)
6608 v.AddArg(y)
6609 return true
6610 }
6611 // match: (Not (Greater32 x y))
6612 // cond:
6613 // result: (Leq32 x y)
6614 for {
6615 v_0 := v.Args[0]
6616 if v_0.Op != OpGreater32 {
6617 break
6618 }
6619 x := v_0.Args[0]
6620 y := v_0.Args[1]
6621 v.reset(OpLeq32)
6622 v.AddArg(x)
6623 v.AddArg(y)
6624 return true
6625 }
6626 // match: (Not (Greater16 x y))
6627 // cond:
6628 // result: (Leq16 x y)
6629 for {
6630 v_0 := v.Args[0]
6631 if v_0.Op != OpGreater16 {
6632 break
6633 }
6634 x := v_0.Args[0]
6635 y := v_0.Args[1]
6636 v.reset(OpLeq16)
6637 v.AddArg(x)
6638 v.AddArg(y)
6639 return true
6640 }
6641 // match: (Not (Greater8 x y))
6642 // cond:
6643 // result: (Leq8 x y)
6644 for {
6645 v_0 := v.Args[0]
6646 if v_0.Op != OpGreater8 {
6647 break
6648 }
6649 x := v_0.Args[0]
6650 y := v_0.Args[1]
6651 v.reset(OpLeq8)
6652 v.AddArg(x)
6653 v.AddArg(y)
6654 return true
6655 }
6656 // match: (Not (Greater64U x y))
6657 // cond:
6658 // result: (Leq64U x y)
6659 for {
6660 v_0 := v.Args[0]
6661 if v_0.Op != OpGreater64U {
6662 break
6663 }
6664 x := v_0.Args[0]
6665 y := v_0.Args[1]
6666 v.reset(OpLeq64U)
6667 v.AddArg(x)
6668 v.AddArg(y)
6669 return true
6670 }
6671 // match: (Not (Greater32U x y))
6672 // cond:
6673 // result: (Leq32U x y)
6674 for {
6675 v_0 := v.Args[0]
6676 if v_0.Op != OpGreater32U {
6677 break
6678 }
6679 x := v_0.Args[0]
6680 y := v_0.Args[1]
6681 v.reset(OpLeq32U)
6682 v.AddArg(x)
6683 v.AddArg(y)
6684 return true
6685 }
6686 // match: (Not (Greater16U x y))
6687 // cond:
6688 // result: (Leq16U x y)
6689 for {
6690 v_0 := v.Args[0]
6691 if v_0.Op != OpGreater16U {
6692 break
6693 }
6694 x := v_0.Args[0]
6695 y := v_0.Args[1]
6696 v.reset(OpLeq16U)
6697 v.AddArg(x)
6698 v.AddArg(y)
6699 return true
6700 }
6701 // match: (Not (Greater8U x y))
6702 // cond:
6703 // result: (Leq8U x y)
6704 for {
6705 v_0 := v.Args[0]
6706 if v_0.Op != OpGreater8U {
6707 break
6708 }
6709 x := v_0.Args[0]
6710 y := v_0.Args[1]
6711 v.reset(OpLeq8U)
6712 v.AddArg(x)
6713 v.AddArg(y)
6714 return true
6715 }
6716 // match: (Not (Geq64 x y))
6717 // cond:
6718 // result: (Less64 x y)
6719 for {
6720 v_0 := v.Args[0]
6721 if v_0.Op != OpGeq64 {
6722 break
6723 }
6724 x := v_0.Args[0]
6725 y := v_0.Args[1]
6726 v.reset(OpLess64)
6727 v.AddArg(x)
6728 v.AddArg(y)
6729 return true
6730 }
6731 // match: (Not (Geq32 x y))
6732 // cond:
6733 // result: (Less32 x y)
6734 for {
6735 v_0 := v.Args[0]
6736 if v_0.Op != OpGeq32 {
6737 break
6738 }
6739 x := v_0.Args[0]
6740 y := v_0.Args[1]
6741 v.reset(OpLess32)
6742 v.AddArg(x)
6743 v.AddArg(y)
6744 return true
6745 }
6746 // match: (Not (Geq16 x y))
6747 // cond:
6748 // result: (Less16 x y)
6749 for {
6750 v_0 := v.Args[0]
6751 if v_0.Op != OpGeq16 {
6752 break
6753 }
6754 x := v_0.Args[0]
6755 y := v_0.Args[1]
6756 v.reset(OpLess16)
6757 v.AddArg(x)
6758 v.AddArg(y)
6759 return true
6760 }
6761 // match: (Not (Geq8 x y))
6762 // cond:
6763 // result: (Less8 x y)
6764 for {
6765 v_0 := v.Args[0]
6766 if v_0.Op != OpGeq8 {
6767 break
6768 }
6769 x := v_0.Args[0]
6770 y := v_0.Args[1]
6771 v.reset(OpLess8)
6772 v.AddArg(x)
6773 v.AddArg(y)
6774 return true
6775 }
6776 // match: (Not (Geq64U x y))
6777 // cond:
6778 // result: (Less64U x y)
6779 for {
6780 v_0 := v.Args[0]
6781 if v_0.Op != OpGeq64U {
6782 break
6783 }
6784 x := v_0.Args[0]
6785 y := v_0.Args[1]
6786 v.reset(OpLess64U)
6787 v.AddArg(x)
6788 v.AddArg(y)
6789 return true
6790 }
6791 // match: (Not (Geq32U x y))
6792 // cond:
6793 // result: (Less32U x y)
6794 for {
6795 v_0 := v.Args[0]
6796 if v_0.Op != OpGeq32U {
6797 break
6798 }
6799 x := v_0.Args[0]
6800 y := v_0.Args[1]
6801 v.reset(OpLess32U)
6802 v.AddArg(x)
6803 v.AddArg(y)
6804 return true
6805 }
6806 // match: (Not (Geq16U x y))
6807 // cond:
6808 // result: (Less16U x y)
6809 for {
6810 v_0 := v.Args[0]
6811 if v_0.Op != OpGeq16U {
6812 break
6813 }
6814 x := v_0.Args[0]
6815 y := v_0.Args[1]
6816 v.reset(OpLess16U)
6817 v.AddArg(x)
6818 v.AddArg(y)
6819 return true
6820 }
6821 // match: (Not (Geq8U x y))
6822 // cond:
6823 // result: (Less8U x y)
6824 for {
6825 v_0 := v.Args[0]
6826 if v_0.Op != OpGeq8U {
6827 break
6828 }
6829 x := v_0.Args[0]
6830 y := v_0.Args[1]
6831 v.reset(OpLess8U)
6832 v.AddArg(x)
6833 v.AddArg(y)
6834 return true
6835 }
6836 // match: (Not (Less64 x y))
6837 // cond:
6838 // result: (Geq64 x y)
6839 for {
6840 v_0 := v.Args[0]
6841 if v_0.Op != OpLess64 {
6842 break
6843 }
6844 x := v_0.Args[0]
6845 y := v_0.Args[1]
6846 v.reset(OpGeq64)
6847 v.AddArg(x)
6848 v.AddArg(y)
6849 return true
6850 }
6851 // match: (Not (Less32 x y))
6852 // cond:
6853 // result: (Geq32 x y)
6854 for {
6855 v_0 := v.Args[0]
6856 if v_0.Op != OpLess32 {
6857 break
6858 }
6859 x := v_0.Args[0]
6860 y := v_0.Args[1]
6861 v.reset(OpGeq32)
6862 v.AddArg(x)
6863 v.AddArg(y)
6864 return true
6865 }
6866 // match: (Not (Less16 x y))
6867 // cond:
6868 // result: (Geq16 x y)
6869 for {
6870 v_0 := v.Args[0]
6871 if v_0.Op != OpLess16 {
6872 break
6873 }
6874 x := v_0.Args[0]
6875 y := v_0.Args[1]
6876 v.reset(OpGeq16)
6877 v.AddArg(x)
6878 v.AddArg(y)
6879 return true
6880 }
6881 // match: (Not (Less8 x y))
6882 // cond:
6883 // result: (Geq8 x y)
6884 for {
6885 v_0 := v.Args[0]
6886 if v_0.Op != OpLess8 {
6887 break
6888 }
6889 x := v_0.Args[0]
6890 y := v_0.Args[1]
6891 v.reset(OpGeq8)
6892 v.AddArg(x)
6893 v.AddArg(y)
6894 return true
6895 }
6896 // match: (Not (Less64U x y))
6897 // cond:
6898 // result: (Geq64U x y)
6899 for {
6900 v_0 := v.Args[0]
6901 if v_0.Op != OpLess64U {
6902 break
6903 }
6904 x := v_0.Args[0]
6905 y := v_0.Args[1]
6906 v.reset(OpGeq64U)
6907 v.AddArg(x)
6908 v.AddArg(y)
6909 return true
6910 }
6911 // match: (Not (Less32U x y))
6912 // cond:
6913 // result: (Geq32U x y)
6914 for {
6915 v_0 := v.Args[0]
6916 if v_0.Op != OpLess32U {
6917 break
6918 }
6919 x := v_0.Args[0]
6920 y := v_0.Args[1]
6921 v.reset(OpGeq32U)
6922 v.AddArg(x)
6923 v.AddArg(y)
6924 return true
6925 }
6926 // match: (Not (Less16U x y))
6927 // cond:
6928 // result: (Geq16U x y)
6929 for {
6930 v_0 := v.Args[0]
6931 if v_0.Op != OpLess16U {
6932 break
6933 }
6934 x := v_0.Args[0]
6935 y := v_0.Args[1]
6936 v.reset(OpGeq16U)
6937 v.AddArg(x)
6938 v.AddArg(y)
6939 return true
6940 }
6941 // match: (Not (Less8U x y))
6942 // cond:
6943 // result: (Geq8U x y)
6944 for {
6945 v_0 := v.Args[0]
6946 if v_0.Op != OpLess8U {
6947 break
6948 }
6949 x := v_0.Args[0]
6950 y := v_0.Args[1]
6951 v.reset(OpGeq8U)
6952 v.AddArg(x)
6953 v.AddArg(y)
6954 return true
6955 }
6956 // match: (Not (Leq64 x y))
6957 // cond:
6958 // result: (Greater64 x y)
6959 for {
6960 v_0 := v.Args[0]
6961 if v_0.Op != OpLeq64 {
6962 break
6963 }
6964 x := v_0.Args[0]
6965 y := v_0.Args[1]
6966 v.reset(OpGreater64)
6967 v.AddArg(x)
6968 v.AddArg(y)
6969 return true
6970 }
6971 // match: (Not (Leq32 x y))
6972 // cond:
6973 // result: (Greater32 x y)
6974 for {
6975 v_0 := v.Args[0]
6976 if v_0.Op != OpLeq32 {
6977 break
6978 }
6979 x := v_0.Args[0]
6980 y := v_0.Args[1]
6981 v.reset(OpGreater32)
6982 v.AddArg(x)
6983 v.AddArg(y)
6984 return true
6985 }
6986 // match: (Not (Leq16 x y))
6987 // cond:
6988 // result: (Greater16 x y)
6989 for {
6990 v_0 := v.Args[0]
6991 if v_0.Op != OpLeq16 {
6992 break
6993 }
6994 x := v_0.Args[0]
6995 y := v_0.Args[1]
6996 v.reset(OpGreater16)
6997 v.AddArg(x)
6998 v.AddArg(y)
6999 return true
7000 }
7001 // match: (Not (Leq8 x y))
7002 // cond:
7003 // result: (Greater8 x y)
7004 for {
7005 v_0 := v.Args[0]
7006 if v_0.Op != OpLeq8 {
7007 break
7008 }
7009 x := v_0.Args[0]
7010 y := v_0.Args[1]
7011 v.reset(OpGreater8)
7012 v.AddArg(x)
7013 v.AddArg(y)
7014 return true
7015 }
7016 // match: (Not (Leq64U x y))
7017 // cond:
7018 // result: (Greater64U x y)
7019 for {
7020 v_0 := v.Args[0]
7021 if v_0.Op != OpLeq64U {
7022 break
7023 }
7024 x := v_0.Args[0]
7025 y := v_0.Args[1]
7026 v.reset(OpGreater64U)
7027 v.AddArg(x)
7028 v.AddArg(y)
7029 return true
7030 }
7031 // match: (Not (Leq32U x y))
7032 // cond:
7033 // result: (Greater32U x y)
7034 for {
7035 v_0 := v.Args[0]
7036 if v_0.Op != OpLeq32U {
7037 break
7038 }
7039 x := v_0.Args[0]
7040 y := v_0.Args[1]
7041 v.reset(OpGreater32U)
7042 v.AddArg(x)
7043 v.AddArg(y)
7044 return true
7045 }
7046 // match: (Not (Leq16U x y))
7047 // cond:
7048 // result: (Greater16U x y)
7049 for {
7050 v_0 := v.Args[0]
7051 if v_0.Op != OpLeq16U {
7052 break
7053 }
7054 x := v_0.Args[0]
7055 y := v_0.Args[1]
7056 v.reset(OpGreater16U)
7057 v.AddArg(x)
7058 v.AddArg(y)
7059 return true
7060 }
7061 // match: (Not (Leq8U x y))
7062 // cond:
7063 // result: (Greater8U x y)
7064 for {
7065 v_0 := v.Args[0]
7066 if v_0.Op != OpLeq8U {
7067 break
7068 }
7069 x := v_0.Args[0]
7070 y := v_0.Args[1]
7071 v.reset(OpGreater8U)
7072 v.AddArg(x)
7073 v.AddArg(y)
7074 return true
7075 }
7076 return false
7077}
Josh Bleecher Snyder32940142016-03-04 14:12:44 -08007078func rewriteValuegeneric_OpOffPtr(v *Value, config *Config) bool {
7079 b := v.Block
7080 _ = b
7081 // match: (OffPtr (OffPtr p [b]) [a])
7082 // cond:
7083 // result: (OffPtr p [a+b])
7084 for {
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07007085 a := v.AuxInt
Keith Randall259b7ed2016-03-21 16:18:45 -07007086 v_0 := v.Args[0]
7087 if v_0.Op != OpOffPtr {
Josh Bleecher Snyder32940142016-03-04 14:12:44 -08007088 break
7089 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007090 b := v_0.AuxInt
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07007091 p := v_0.Args[0]
Josh Bleecher Snyder32940142016-03-04 14:12:44 -08007092 v.reset(OpOffPtr)
Josh Bleecher Snyder32940142016-03-04 14:12:44 -08007093 v.AuxInt = a + b
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07007094 v.AddArg(p)
Josh Bleecher Snyder32940142016-03-04 14:12:44 -08007095 return true
7096 }
Alexandru Moșoia7a19992016-03-18 10:50:00 +01007097 // match: (OffPtr p [0])
7098 // cond: v.Type.Compare(p.Type) == CMPeq
7099 // result: p
7100 for {
Alexandru Moșoia7a19992016-03-18 10:50:00 +01007101 if v.AuxInt != 0 {
7102 break
7103 }
Josh Bleecher Snyder6a1153a2016-07-01 11:05:29 -07007104 p := v.Args[0]
Alexandru Moșoia7a19992016-03-18 10:50:00 +01007105 if !(v.Type.Compare(p.Type) == CMPeq) {
7106 break
7107 }
7108 v.reset(OpCopy)
7109 v.Type = p.Type
7110 v.AddArg(p)
7111 return true
7112 }
Josh Bleecher Snyder32940142016-03-04 14:12:44 -08007113 return false
7114}
Keith Randalla347ab72015-10-26 21:49:31 -07007115func rewriteValuegeneric_OpOr16(v *Value, config *Config) bool {
7116 b := v.Block
7117 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007118 // match: (Or16 x (Const16 <t> [c]))
7119 // cond: x.Op != OpConst16
7120 // result: (Or16 (Const16 <t> [c]) x)
7121 for {
7122 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07007123 v_1 := v.Args[1]
7124 if v_1.Op != OpConst16 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007125 break
7126 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007127 t := v_1.Type
7128 c := v_1.AuxInt
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007129 if !(x.Op != OpConst16) {
7130 break
7131 }
7132 v.reset(OpOr16)
7133 v0 := b.NewValue0(v.Line, OpConst16, t)
7134 v0.AuxInt = c
7135 v.AddArg(v0)
7136 v.AddArg(x)
7137 return true
7138 }
Keith Randalla347ab72015-10-26 21:49:31 -07007139 // match: (Or16 x x)
7140 // cond:
7141 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01007142 for {
Keith Randalla347ab72015-10-26 21:49:31 -07007143 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07007144 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007145 break
Keith Randalla347ab72015-10-26 21:49:31 -07007146 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007147 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07007148 v.Type = x.Type
7149 v.AddArg(x)
7150 return true
7151 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007152 // match: (Or16 (Const16 [0]) x)
7153 // cond:
7154 // result: x
7155 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07007156 v_0 := v.Args[0]
7157 if v_0.Op != OpConst16 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007158 break
7159 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007160 if v_0.AuxInt != 0 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007161 break
7162 }
7163 x := v.Args[1]
7164 v.reset(OpCopy)
7165 v.Type = x.Type
7166 v.AddArg(x)
7167 return true
7168 }
7169 // match: (Or16 (Const16 [-1]) _)
7170 // cond:
7171 // result: (Const16 [-1])
7172 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07007173 v_0 := v.Args[0]
7174 if v_0.Op != OpConst16 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007175 break
7176 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007177 if v_0.AuxInt != -1 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007178 break
7179 }
7180 v.reset(OpConst16)
7181 v.AuxInt = -1
7182 return true
7183 }
Keith Randall4d5adf12016-04-18 09:28:50 -07007184 // match: (Or16 x (Or16 x y))
7185 // cond:
7186 // result: (Or16 x y)
7187 for {
7188 x := v.Args[0]
7189 v_1 := v.Args[1]
7190 if v_1.Op != OpOr16 {
7191 break
7192 }
7193 if x != v_1.Args[0] {
7194 break
7195 }
7196 y := v_1.Args[1]
7197 v.reset(OpOr16)
7198 v.AddArg(x)
7199 v.AddArg(y)
7200 return true
7201 }
7202 // match: (Or16 x (Or16 y x))
7203 // cond:
7204 // result: (Or16 x y)
7205 for {
7206 x := v.Args[0]
7207 v_1 := v.Args[1]
7208 if v_1.Op != OpOr16 {
7209 break
7210 }
7211 y := v_1.Args[0]
7212 if x != v_1.Args[1] {
7213 break
7214 }
7215 v.reset(OpOr16)
7216 v.AddArg(x)
7217 v.AddArg(y)
7218 return true
7219 }
7220 // match: (Or16 (Or16 x y) x)
7221 // cond:
7222 // result: (Or16 x y)
7223 for {
7224 v_0 := v.Args[0]
7225 if v_0.Op != OpOr16 {
7226 break
7227 }
7228 x := v_0.Args[0]
7229 y := v_0.Args[1]
7230 if x != v.Args[1] {
7231 break
7232 }
7233 v.reset(OpOr16)
7234 v.AddArg(x)
7235 v.AddArg(y)
7236 return true
7237 }
7238 // match: (Or16 (Or16 x y) y)
7239 // cond:
7240 // result: (Or16 x y)
7241 for {
7242 v_0 := v.Args[0]
7243 if v_0.Op != OpOr16 {
7244 break
7245 }
7246 x := v_0.Args[0]
7247 y := v_0.Args[1]
7248 if y != v.Args[1] {
7249 break
7250 }
7251 v.reset(OpOr16)
7252 v.AddArg(x)
7253 v.AddArg(y)
7254 return true
7255 }
Keith Randalla347ab72015-10-26 21:49:31 -07007256 return false
7257}
7258func rewriteValuegeneric_OpOr32(v *Value, config *Config) bool {
7259 b := v.Block
7260 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007261 // match: (Or32 x (Const32 <t> [c]))
7262 // cond: x.Op != OpConst32
7263 // result: (Or32 (Const32 <t> [c]) x)
7264 for {
7265 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07007266 v_1 := v.Args[1]
7267 if v_1.Op != OpConst32 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007268 break
7269 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007270 t := v_1.Type
7271 c := v_1.AuxInt
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007272 if !(x.Op != OpConst32) {
7273 break
7274 }
7275 v.reset(OpOr32)
7276 v0 := b.NewValue0(v.Line, OpConst32, t)
7277 v0.AuxInt = c
7278 v.AddArg(v0)
7279 v.AddArg(x)
7280 return true
7281 }
Keith Randalla347ab72015-10-26 21:49:31 -07007282 // match: (Or32 x x)
7283 // cond:
7284 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01007285 for {
Keith Randalla347ab72015-10-26 21:49:31 -07007286 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07007287 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007288 break
Keith Randalla347ab72015-10-26 21:49:31 -07007289 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007290 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07007291 v.Type = x.Type
7292 v.AddArg(x)
7293 return true
7294 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007295 // match: (Or32 (Const32 [0]) x)
7296 // cond:
7297 // result: x
7298 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07007299 v_0 := v.Args[0]
7300 if v_0.Op != OpConst32 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007301 break
7302 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007303 if v_0.AuxInt != 0 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007304 break
7305 }
7306 x := v.Args[1]
7307 v.reset(OpCopy)
7308 v.Type = x.Type
7309 v.AddArg(x)
7310 return true
7311 }
7312 // match: (Or32 (Const32 [-1]) _)
7313 // cond:
7314 // result: (Const32 [-1])
7315 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07007316 v_0 := v.Args[0]
7317 if v_0.Op != OpConst32 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007318 break
7319 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007320 if v_0.AuxInt != -1 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007321 break
7322 }
7323 v.reset(OpConst32)
7324 v.AuxInt = -1
7325 return true
7326 }
Keith Randall4d5adf12016-04-18 09:28:50 -07007327 // match: (Or32 x (Or32 x y))
7328 // cond:
7329 // result: (Or32 x y)
7330 for {
7331 x := v.Args[0]
7332 v_1 := v.Args[1]
7333 if v_1.Op != OpOr32 {
7334 break
7335 }
7336 if x != v_1.Args[0] {
7337 break
7338 }
7339 y := v_1.Args[1]
7340 v.reset(OpOr32)
7341 v.AddArg(x)
7342 v.AddArg(y)
7343 return true
7344 }
7345 // match: (Or32 x (Or32 y x))
7346 // cond:
7347 // result: (Or32 x y)
7348 for {
7349 x := v.Args[0]
7350 v_1 := v.Args[1]
7351 if v_1.Op != OpOr32 {
7352 break
7353 }
7354 y := v_1.Args[0]
7355 if x != v_1.Args[1] {
7356 break
7357 }
7358 v.reset(OpOr32)
7359 v.AddArg(x)
7360 v.AddArg(y)
7361 return true
7362 }
7363 // match: (Or32 (Or32 x y) x)
7364 // cond:
7365 // result: (Or32 x y)
7366 for {
7367 v_0 := v.Args[0]
7368 if v_0.Op != OpOr32 {
7369 break
7370 }
7371 x := v_0.Args[0]
7372 y := v_0.Args[1]
7373 if x != v.Args[1] {
7374 break
7375 }
7376 v.reset(OpOr32)
7377 v.AddArg(x)
7378 v.AddArg(y)
7379 return true
7380 }
7381 // match: (Or32 (Or32 x y) y)
7382 // cond:
7383 // result: (Or32 x y)
7384 for {
7385 v_0 := v.Args[0]
7386 if v_0.Op != OpOr32 {
7387 break
7388 }
7389 x := v_0.Args[0]
7390 y := v_0.Args[1]
7391 if y != v.Args[1] {
7392 break
7393 }
7394 v.reset(OpOr32)
7395 v.AddArg(x)
7396 v.AddArg(y)
7397 return true
7398 }
Keith Randalla347ab72015-10-26 21:49:31 -07007399 return false
7400}
7401func rewriteValuegeneric_OpOr64(v *Value, config *Config) bool {
7402 b := v.Block
7403 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007404 // match: (Or64 x (Const64 <t> [c]))
7405 // cond: x.Op != OpConst64
7406 // result: (Or64 (Const64 <t> [c]) x)
7407 for {
7408 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07007409 v_1 := v.Args[1]
7410 if v_1.Op != OpConst64 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007411 break
7412 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007413 t := v_1.Type
7414 c := v_1.AuxInt
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007415 if !(x.Op != OpConst64) {
7416 break
7417 }
7418 v.reset(OpOr64)
7419 v0 := b.NewValue0(v.Line, OpConst64, t)
7420 v0.AuxInt = c
7421 v.AddArg(v0)
7422 v.AddArg(x)
7423 return true
7424 }
Keith Randalla347ab72015-10-26 21:49:31 -07007425 // match: (Or64 x x)
7426 // cond:
7427 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01007428 for {
Keith Randalla347ab72015-10-26 21:49:31 -07007429 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07007430 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007431 break
Keith Randalla347ab72015-10-26 21:49:31 -07007432 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007433 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07007434 v.Type = x.Type
7435 v.AddArg(x)
7436 return true
7437 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007438 // match: (Or64 (Const64 [0]) x)
7439 // cond:
7440 // result: x
7441 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07007442 v_0 := v.Args[0]
7443 if v_0.Op != OpConst64 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007444 break
7445 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007446 if v_0.AuxInt != 0 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007447 break
7448 }
7449 x := v.Args[1]
7450 v.reset(OpCopy)
7451 v.Type = x.Type
7452 v.AddArg(x)
7453 return true
7454 }
7455 // match: (Or64 (Const64 [-1]) _)
7456 // cond:
7457 // result: (Const64 [-1])
7458 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07007459 v_0 := v.Args[0]
7460 if v_0.Op != OpConst64 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007461 break
7462 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007463 if v_0.AuxInt != -1 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007464 break
7465 }
7466 v.reset(OpConst64)
7467 v.AuxInt = -1
7468 return true
7469 }
Keith Randall4d5adf12016-04-18 09:28:50 -07007470 // match: (Or64 x (Or64 x y))
7471 // cond:
7472 // result: (Or64 x y)
7473 for {
7474 x := v.Args[0]
7475 v_1 := v.Args[1]
7476 if v_1.Op != OpOr64 {
7477 break
7478 }
7479 if x != v_1.Args[0] {
7480 break
7481 }
7482 y := v_1.Args[1]
7483 v.reset(OpOr64)
7484 v.AddArg(x)
7485 v.AddArg(y)
7486 return true
7487 }
7488 // match: (Or64 x (Or64 y x))
7489 // cond:
7490 // result: (Or64 x y)
7491 for {
7492 x := v.Args[0]
7493 v_1 := v.Args[1]
7494 if v_1.Op != OpOr64 {
7495 break
7496 }
7497 y := v_1.Args[0]
7498 if x != v_1.Args[1] {
7499 break
7500 }
7501 v.reset(OpOr64)
7502 v.AddArg(x)
7503 v.AddArg(y)
7504 return true
7505 }
7506 // match: (Or64 (Or64 x y) x)
7507 // cond:
7508 // result: (Or64 x y)
7509 for {
7510 v_0 := v.Args[0]
7511 if v_0.Op != OpOr64 {
7512 break
7513 }
7514 x := v_0.Args[0]
7515 y := v_0.Args[1]
7516 if x != v.Args[1] {
7517 break
7518 }
7519 v.reset(OpOr64)
7520 v.AddArg(x)
7521 v.AddArg(y)
7522 return true
7523 }
7524 // match: (Or64 (Or64 x y) y)
7525 // cond:
7526 // result: (Or64 x y)
7527 for {
7528 v_0 := v.Args[0]
7529 if v_0.Op != OpOr64 {
7530 break
7531 }
7532 x := v_0.Args[0]
7533 y := v_0.Args[1]
7534 if y != v.Args[1] {
7535 break
7536 }
7537 v.reset(OpOr64)
7538 v.AddArg(x)
7539 v.AddArg(y)
7540 return true
7541 }
Keith Randalla347ab72015-10-26 21:49:31 -07007542 return false
7543}
7544func rewriteValuegeneric_OpOr8(v *Value, config *Config) bool {
7545 b := v.Block
7546 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07007547 // match: (Or8 x (Const8 <t> [c]))
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007548 // cond: x.Op != OpConst8
Keith Randallfa9435c2016-04-26 12:08:31 -07007549 // result: (Or8 (Const8 <t> [c]) x)
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007550 for {
7551 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07007552 v_1 := v.Args[1]
7553 if v_1.Op != OpConst8 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007554 break
7555 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007556 t := v_1.Type
7557 c := v_1.AuxInt
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007558 if !(x.Op != OpConst8) {
7559 break
7560 }
7561 v.reset(OpOr8)
7562 v0 := b.NewValue0(v.Line, OpConst8, t)
7563 v0.AuxInt = c
7564 v.AddArg(v0)
7565 v.AddArg(x)
7566 return true
7567 }
Keith Randallfa9435c2016-04-26 12:08:31 -07007568 // match: (Or8 x x)
Keith Randalla347ab72015-10-26 21:49:31 -07007569 // cond:
7570 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01007571 for {
Keith Randalla347ab72015-10-26 21:49:31 -07007572 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07007573 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007574 break
Keith Randalla347ab72015-10-26 21:49:31 -07007575 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007576 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07007577 v.Type = x.Type
7578 v.AddArg(x)
7579 return true
7580 }
Keith Randallfa9435c2016-04-26 12:08:31 -07007581 // match: (Or8 (Const8 [0]) x)
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007582 // cond:
7583 // result: x
7584 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07007585 v_0 := v.Args[0]
7586 if v_0.Op != OpConst8 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007587 break
7588 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007589 if v_0.AuxInt != 0 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007590 break
7591 }
7592 x := v.Args[1]
7593 v.reset(OpCopy)
7594 v.Type = x.Type
7595 v.AddArg(x)
7596 return true
7597 }
Keith Randallfa9435c2016-04-26 12:08:31 -07007598 // match: (Or8 (Const8 [-1]) _)
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007599 // cond:
Keith Randallfa9435c2016-04-26 12:08:31 -07007600 // result: (Const8 [-1])
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007601 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07007602 v_0 := v.Args[0]
7603 if v_0.Op != OpConst8 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007604 break
7605 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007606 if v_0.AuxInt != -1 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007607 break
7608 }
7609 v.reset(OpConst8)
7610 v.AuxInt = -1
7611 return true
7612 }
Keith Randall4d5adf12016-04-18 09:28:50 -07007613 // match: (Or8 x (Or8 x y))
7614 // cond:
7615 // result: (Or8 x y)
7616 for {
7617 x := v.Args[0]
7618 v_1 := v.Args[1]
7619 if v_1.Op != OpOr8 {
7620 break
7621 }
7622 if x != v_1.Args[0] {
7623 break
7624 }
7625 y := v_1.Args[1]
7626 v.reset(OpOr8)
7627 v.AddArg(x)
7628 v.AddArg(y)
7629 return true
7630 }
7631 // match: (Or8 x (Or8 y x))
7632 // cond:
7633 // result: (Or8 x y)
7634 for {
7635 x := v.Args[0]
7636 v_1 := v.Args[1]
7637 if v_1.Op != OpOr8 {
7638 break
7639 }
7640 y := v_1.Args[0]
7641 if x != v_1.Args[1] {
7642 break
7643 }
7644 v.reset(OpOr8)
7645 v.AddArg(x)
7646 v.AddArg(y)
7647 return true
7648 }
7649 // match: (Or8 (Or8 x y) x)
7650 // cond:
7651 // result: (Or8 x y)
7652 for {
7653 v_0 := v.Args[0]
7654 if v_0.Op != OpOr8 {
7655 break
7656 }
7657 x := v_0.Args[0]
7658 y := v_0.Args[1]
7659 if x != v.Args[1] {
7660 break
7661 }
7662 v.reset(OpOr8)
7663 v.AddArg(x)
7664 v.AddArg(y)
7665 return true
7666 }
7667 // match: (Or8 (Or8 x y) y)
7668 // cond:
7669 // result: (Or8 x y)
7670 for {
7671 v_0 := v.Args[0]
7672 if v_0.Op != OpOr8 {
7673 break
7674 }
7675 x := v_0.Args[0]
7676 y := v_0.Args[1]
7677 if y != v.Args[1] {
7678 break
7679 }
7680 v.reset(OpOr8)
7681 v.AddArg(x)
7682 v.AddArg(y)
7683 return true
7684 }
Keith Randalla347ab72015-10-26 21:49:31 -07007685 return false
7686}
Alexandru Moșoid0d04d22016-02-09 19:46:26 +01007687func rewriteValuegeneric_OpPhi(v *Value, config *Config) bool {
7688 b := v.Block
7689 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07007690 // match: (Phi (Const8 [c]) (Const8 [c]))
Keith Randall7fc56212016-03-29 16:39:53 -07007691 // cond:
Keith Randallfa9435c2016-04-26 12:08:31 -07007692 // result: (Const8 [c])
Alexandru Moșoid0d04d22016-02-09 19:46:26 +01007693 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07007694 v_0 := v.Args[0]
7695 if v_0.Op != OpConst8 {
Alexandru Moșoid0d04d22016-02-09 19:46:26 +01007696 break
7697 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007698 c := v_0.AuxInt
7699 v_1 := v.Args[1]
7700 if v_1.Op != OpConst8 {
Alexandru Moșoid0d04d22016-02-09 19:46:26 +01007701 break
7702 }
Keith Randall7fc56212016-03-29 16:39:53 -07007703 if v_1.AuxInt != c {
Alexandru Moșoid0d04d22016-02-09 19:46:26 +01007704 break
7705 }
Keith Randall7fc56212016-03-29 16:39:53 -07007706 if len(v.Args) != 2 {
Alexandru Moșoid0d04d22016-02-09 19:46:26 +01007707 break
7708 }
7709 v.reset(OpConst8)
7710 v.AuxInt = c
7711 return true
7712 }
Keith Randall7fc56212016-03-29 16:39:53 -07007713 // match: (Phi (Const16 [c]) (Const16 [c]))
7714 // cond:
Alexandru Moșoid0d04d22016-02-09 19:46:26 +01007715 // result: (Const16 [c])
7716 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07007717 v_0 := v.Args[0]
7718 if v_0.Op != OpConst16 {
Alexandru Moșoid0d04d22016-02-09 19:46:26 +01007719 break
7720 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007721 c := v_0.AuxInt
7722 v_1 := v.Args[1]
7723 if v_1.Op != OpConst16 {
Alexandru Moșoid0d04d22016-02-09 19:46:26 +01007724 break
7725 }
Keith Randall7fc56212016-03-29 16:39:53 -07007726 if v_1.AuxInt != c {
Alexandru Moșoid0d04d22016-02-09 19:46:26 +01007727 break
7728 }
Keith Randall7fc56212016-03-29 16:39:53 -07007729 if len(v.Args) != 2 {
Alexandru Moșoid0d04d22016-02-09 19:46:26 +01007730 break
7731 }
7732 v.reset(OpConst16)
7733 v.AuxInt = c
7734 return true
7735 }
Keith Randall7fc56212016-03-29 16:39:53 -07007736 // match: (Phi (Const32 [c]) (Const32 [c]))
7737 // cond:
Alexandru Moșoid0d04d22016-02-09 19:46:26 +01007738 // result: (Const32 [c])
7739 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07007740 v_0 := v.Args[0]
7741 if v_0.Op != OpConst32 {
Alexandru Moșoid0d04d22016-02-09 19:46:26 +01007742 break
7743 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007744 c := v_0.AuxInt
7745 v_1 := v.Args[1]
7746 if v_1.Op != OpConst32 {
Alexandru Moșoid0d04d22016-02-09 19:46:26 +01007747 break
7748 }
Keith Randall7fc56212016-03-29 16:39:53 -07007749 if v_1.AuxInt != c {
Alexandru Moșoid0d04d22016-02-09 19:46:26 +01007750 break
7751 }
Keith Randall7fc56212016-03-29 16:39:53 -07007752 if len(v.Args) != 2 {
Alexandru Moșoid0d04d22016-02-09 19:46:26 +01007753 break
7754 }
7755 v.reset(OpConst32)
7756 v.AuxInt = c
7757 return true
7758 }
7759 // match: (Phi (Const64 [c]) (Const64 [c]))
7760 // cond:
7761 // result: (Const64 [c])
7762 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07007763 v_0 := v.Args[0]
7764 if v_0.Op != OpConst64 {
Alexandru Moșoid0d04d22016-02-09 19:46:26 +01007765 break
7766 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007767 c := v_0.AuxInt
7768 v_1 := v.Args[1]
7769 if v_1.Op != OpConst64 {
Alexandru Moșoid0d04d22016-02-09 19:46:26 +01007770 break
7771 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007772 if v_1.AuxInt != c {
Alexandru Moșoid0d04d22016-02-09 19:46:26 +01007773 break
7774 }
7775 if len(v.Args) != 2 {
7776 break
7777 }
7778 v.reset(OpConst64)
7779 v.AuxInt = c
7780 return true
7781 }
7782 return false
7783}
Keith Randalla347ab72015-10-26 21:49:31 -07007784func rewriteValuegeneric_OpPtrIndex(v *Value, config *Config) bool {
7785 b := v.Block
7786 _ = b
7787 // match: (PtrIndex <t> ptr idx)
Keith Randall582baae2015-11-02 21:28:13 -08007788 // cond: config.PtrSize == 4
Matthew Dempsky0b281872016-03-10 14:35:39 -08007789 // result: (AddPtr ptr (Mul32 <config.fe.TypeInt()> idx (Const32 <config.fe.TypeInt()> [t.ElemType().Size()])))
Alexandru Moșoi05434472016-02-04 19:52:10 +01007790 for {
Keith Randalla347ab72015-10-26 21:49:31 -07007791 t := v.Type
7792 ptr := v.Args[0]
7793 idx := v.Args[1]
Keith Randall582baae2015-11-02 21:28:13 -08007794 if !(config.PtrSize == 4) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007795 break
Keith Randall582baae2015-11-02 21:28:13 -08007796 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007797 v.reset(OpAddPtr)
Keith Randalla347ab72015-10-26 21:49:31 -07007798 v.AddArg(ptr)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01007799 v0 := b.NewValue0(v.Line, OpMul32, config.fe.TypeInt())
Keith Randalla347ab72015-10-26 21:49:31 -07007800 v0.AddArg(idx)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01007801 v1 := b.NewValue0(v.Line, OpConst32, config.fe.TypeInt())
Matthew Dempsky0b281872016-03-10 14:35:39 -08007802 v1.AuxInt = t.ElemType().Size()
Keith Randalla347ab72015-10-26 21:49:31 -07007803 v0.AddArg(v1)
Keith Randalla347ab72015-10-26 21:49:31 -07007804 v.AddArg(v0)
7805 return true
7806 }
Keith Randall582baae2015-11-02 21:28:13 -08007807 // match: (PtrIndex <t> ptr idx)
7808 // cond: config.PtrSize == 8
Matthew Dempsky0b281872016-03-10 14:35:39 -08007809 // result: (AddPtr ptr (Mul64 <config.fe.TypeInt()> idx (Const64 <config.fe.TypeInt()> [t.ElemType().Size()])))
Alexandru Moșoi05434472016-02-04 19:52:10 +01007810 for {
Keith Randall582baae2015-11-02 21:28:13 -08007811 t := v.Type
7812 ptr := v.Args[0]
7813 idx := v.Args[1]
7814 if !(config.PtrSize == 8) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007815 break
Keith Randall582baae2015-11-02 21:28:13 -08007816 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007817 v.reset(OpAddPtr)
Keith Randall582baae2015-11-02 21:28:13 -08007818 v.AddArg(ptr)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01007819 v0 := b.NewValue0(v.Line, OpMul64, config.fe.TypeInt())
Keith Randall582baae2015-11-02 21:28:13 -08007820 v0.AddArg(idx)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01007821 v1 := b.NewValue0(v.Line, OpConst64, config.fe.TypeInt())
Matthew Dempsky0b281872016-03-10 14:35:39 -08007822 v1.AuxInt = t.ElemType().Size()
Keith Randall582baae2015-11-02 21:28:13 -08007823 v0.AddArg(v1)
7824 v.AddArg(v0)
7825 return true
7826 }
Keith Randalla347ab72015-10-26 21:49:31 -07007827 return false
7828}
Todd Neal93a0b0f2016-02-03 06:21:24 -05007829func rewriteValuegeneric_OpRsh16Ux16(v *Value, config *Config) bool {
7830 b := v.Block
7831 _ = b
7832 // match: (Rsh16Ux16 <t> x (Const16 [c]))
7833 // cond:
7834 // result: (Rsh16Ux64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01007835 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05007836 t := v.Type
7837 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07007838 v_1 := v.Args[1]
7839 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007840 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05007841 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007842 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007843 v.reset(OpRsh16Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05007844 v.AddArg(x)
7845 v0 := b.NewValue0(v.Line, OpConst64, t)
7846 v0.AuxInt = int64(uint16(c))
7847 v.AddArg(v0)
7848 return true
7849 }
Keith Randall17396572016-05-28 21:15:24 -07007850 // match: (Rsh16Ux16 (Const16 [0]) _)
7851 // cond:
7852 // result: (Const16 [0])
7853 for {
7854 v_0 := v.Args[0]
7855 if v_0.Op != OpConst16 {
7856 break
7857 }
7858 if v_0.AuxInt != 0 {
7859 break
7860 }
7861 v.reset(OpConst16)
7862 v.AuxInt = 0
7863 return true
7864 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05007865 return false
7866}
7867func rewriteValuegeneric_OpRsh16Ux32(v *Value, config *Config) bool {
7868 b := v.Block
7869 _ = b
7870 // match: (Rsh16Ux32 <t> x (Const32 [c]))
7871 // cond:
7872 // result: (Rsh16Ux64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01007873 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05007874 t := v.Type
7875 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07007876 v_1 := v.Args[1]
7877 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007878 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05007879 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007880 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007881 v.reset(OpRsh16Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05007882 v.AddArg(x)
7883 v0 := b.NewValue0(v.Line, OpConst64, t)
7884 v0.AuxInt = int64(uint32(c))
7885 v.AddArg(v0)
7886 return true
7887 }
Keith Randall17396572016-05-28 21:15:24 -07007888 // match: (Rsh16Ux32 (Const16 [0]) _)
7889 // cond:
7890 // result: (Const16 [0])
7891 for {
7892 v_0 := v.Args[0]
7893 if v_0.Op != OpConst16 {
7894 break
7895 }
7896 if v_0.AuxInt != 0 {
7897 break
7898 }
7899 v.reset(OpConst16)
7900 v.AuxInt = 0
7901 return true
7902 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05007903 return false
7904}
7905func rewriteValuegeneric_OpRsh16Ux64(v *Value, config *Config) bool {
7906 b := v.Block
7907 _ = b
7908 // match: (Rsh16Ux64 (Const16 [c]) (Const64 [d]))
7909 // cond:
Keith Randall68ac1f72016-04-07 10:21:35 -07007910 // result: (Const16 [int64(int16(uint16(c) >> uint64(d)))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01007911 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07007912 v_0 := v.Args[0]
7913 if v_0.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007914 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05007915 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007916 c := v_0.AuxInt
7917 v_1 := v.Args[1]
7918 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007919 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05007920 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007921 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007922 v.reset(OpConst16)
Keith Randall68ac1f72016-04-07 10:21:35 -07007923 v.AuxInt = int64(int16(uint16(c) >> uint64(d)))
Todd Neal93a0b0f2016-02-03 06:21:24 -05007924 return true
7925 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05007926 // match: (Rsh16Ux64 x (Const64 [0]))
7927 // cond:
7928 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01007929 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05007930 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07007931 v_1 := v.Args[1]
7932 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007933 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05007934 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007935 if v_1.AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007936 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05007937 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007938 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05007939 v.Type = x.Type
7940 v.AddArg(x)
7941 return true
7942 }
Keith Randall17396572016-05-28 21:15:24 -07007943 // match: (Rsh16Ux64 (Const16 [0]) _)
Keith Randallfa9435c2016-04-26 12:08:31 -07007944 // cond:
7945 // result: (Const16 [0])
7946 for {
7947 v_0 := v.Args[0]
Keith Randall17396572016-05-28 21:15:24 -07007948 if v_0.Op != OpConst16 {
Keith Randallfa9435c2016-04-26 12:08:31 -07007949 break
7950 }
7951 if v_0.AuxInt != 0 {
7952 break
7953 }
7954 v.reset(OpConst16)
7955 v.AuxInt = 0
7956 return true
7957 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05007958 // match: (Rsh16Ux64 _ (Const64 [c]))
7959 // cond: uint64(c) >= 16
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01007960 // result: (Const16 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01007961 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07007962 v_1 := v.Args[1]
7963 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007964 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05007965 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007966 c := v_1.AuxInt
Todd Neal93a0b0f2016-02-03 06:21:24 -05007967 if !(uint64(c) >= 16) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007968 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05007969 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01007970 v.reset(OpConst16)
Todd Neal93a0b0f2016-02-03 06:21:24 -05007971 v.AuxInt = 0
7972 return true
7973 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05007974 // match: (Rsh16Ux64 <t> (Rsh16Ux64 x (Const64 [c])) (Const64 [d]))
7975 // cond: !uaddOvf(c,d)
7976 // result: (Rsh16Ux64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01007977 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05007978 t := v.Type
Keith Randall259b7ed2016-03-21 16:18:45 -07007979 v_0 := v.Args[0]
7980 if v_0.Op != OpRsh16Ux64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007981 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05007982 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007983 x := v_0.Args[0]
7984 v_0_1 := v_0.Args[1]
7985 if v_0_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007986 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05007987 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007988 c := v_0_1.AuxInt
7989 v_1 := v.Args[1]
7990 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007991 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05007992 }
Keith Randall259b7ed2016-03-21 16:18:45 -07007993 d := v_1.AuxInt
Todd Neal93a0b0f2016-02-03 06:21:24 -05007994 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007995 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05007996 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007997 v.reset(OpRsh16Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05007998 v.AddArg(x)
7999 v0 := b.NewValue0(v.Line, OpConst64, t)
8000 v0.AuxInt = c + d
8001 v.AddArg(v0)
8002 return true
8003 }
Keith Randall17396572016-05-28 21:15:24 -07008004 // match: (Rsh16Ux64 (Lsh16x64 (Rsh16Ux64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
8005 // cond: uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
8006 // result: (Rsh16Ux64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
Keith Randallfa9435c2016-04-26 12:08:31 -07008007 for {
8008 v_0 := v.Args[0]
8009 if v_0.Op != OpLsh16x64 {
8010 break
8011 }
8012 v_0_0 := v_0.Args[0]
8013 if v_0_0.Op != OpRsh16Ux64 {
8014 break
8015 }
8016 x := v_0_0.Args[0]
8017 v_0_0_1 := v_0_0.Args[1]
Keith Randall17396572016-05-28 21:15:24 -07008018 if v_0_0_1.Op != OpConst64 {
Keith Randallfa9435c2016-04-26 12:08:31 -07008019 break
8020 }
8021 c1 := v_0_0_1.AuxInt
8022 v_0_1 := v_0.Args[1]
Keith Randall17396572016-05-28 21:15:24 -07008023 if v_0_1.Op != OpConst64 {
Keith Randallfa9435c2016-04-26 12:08:31 -07008024 break
8025 }
8026 c2 := v_0_1.AuxInt
8027 v_1 := v.Args[1]
Keith Randall17396572016-05-28 21:15:24 -07008028 if v_1.Op != OpConst64 {
Keith Randallfa9435c2016-04-26 12:08:31 -07008029 break
8030 }
8031 c3 := v_1.AuxInt
Keith Randall17396572016-05-28 21:15:24 -07008032 if !(uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)) {
Keith Randallfa9435c2016-04-26 12:08:31 -07008033 break
8034 }
8035 v.reset(OpRsh16Ux64)
8036 v.AddArg(x)
Keith Randall17396572016-05-28 21:15:24 -07008037 v0 := b.NewValue0(v.Line, OpConst64, config.fe.TypeUInt64())
8038 v0.AuxInt = c1 - c2 + c3
Keith Randallfa9435c2016-04-26 12:08:31 -07008039 v.AddArg(v0)
8040 return true
8041 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008042 return false
8043}
8044func rewriteValuegeneric_OpRsh16Ux8(v *Value, config *Config) bool {
8045 b := v.Block
8046 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07008047 // match: (Rsh16Ux8 <t> x (Const8 [c]))
Todd Neal93a0b0f2016-02-03 06:21:24 -05008048 // cond:
8049 // result: (Rsh16Ux64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01008050 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05008051 t := v.Type
8052 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07008053 v_1 := v.Args[1]
8054 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008055 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008056 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008057 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008058 v.reset(OpRsh16Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008059 v.AddArg(x)
8060 v0 := b.NewValue0(v.Line, OpConst64, t)
8061 v0.AuxInt = int64(uint8(c))
8062 v.AddArg(v0)
8063 return true
8064 }
Keith Randall17396572016-05-28 21:15:24 -07008065 // match: (Rsh16Ux8 (Const16 [0]) _)
8066 // cond:
8067 // result: (Const16 [0])
8068 for {
8069 v_0 := v.Args[0]
8070 if v_0.Op != OpConst16 {
8071 break
8072 }
8073 if v_0.AuxInt != 0 {
8074 break
8075 }
8076 v.reset(OpConst16)
8077 v.AuxInt = 0
8078 return true
8079 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008080 return false
8081}
8082func rewriteValuegeneric_OpRsh16x16(v *Value, config *Config) bool {
8083 b := v.Block
8084 _ = b
8085 // match: (Rsh16x16 <t> x (Const16 [c]))
8086 // cond:
8087 // result: (Rsh16x64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01008088 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05008089 t := v.Type
8090 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07008091 v_1 := v.Args[1]
8092 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008093 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008094 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008095 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008096 v.reset(OpRsh16x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008097 v.AddArg(x)
8098 v0 := b.NewValue0(v.Line, OpConst64, t)
8099 v0.AuxInt = int64(uint16(c))
8100 v.AddArg(v0)
8101 return true
8102 }
Keith Randall17396572016-05-28 21:15:24 -07008103 // match: (Rsh16x16 (Const16 [0]) _)
8104 // cond:
8105 // result: (Const16 [0])
8106 for {
8107 v_0 := v.Args[0]
8108 if v_0.Op != OpConst16 {
8109 break
8110 }
8111 if v_0.AuxInt != 0 {
8112 break
8113 }
8114 v.reset(OpConst16)
8115 v.AuxInt = 0
8116 return true
8117 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008118 return false
8119}
8120func rewriteValuegeneric_OpRsh16x32(v *Value, config *Config) bool {
8121 b := v.Block
8122 _ = b
8123 // match: (Rsh16x32 <t> x (Const32 [c]))
8124 // cond:
8125 // result: (Rsh16x64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01008126 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05008127 t := v.Type
8128 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07008129 v_1 := v.Args[1]
8130 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008131 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008132 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008133 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008134 v.reset(OpRsh16x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008135 v.AddArg(x)
8136 v0 := b.NewValue0(v.Line, OpConst64, t)
8137 v0.AuxInt = int64(uint32(c))
8138 v.AddArg(v0)
8139 return true
8140 }
Keith Randall17396572016-05-28 21:15:24 -07008141 // match: (Rsh16x32 (Const16 [0]) _)
8142 // cond:
8143 // result: (Const16 [0])
8144 for {
8145 v_0 := v.Args[0]
8146 if v_0.Op != OpConst16 {
8147 break
8148 }
8149 if v_0.AuxInt != 0 {
8150 break
8151 }
8152 v.reset(OpConst16)
8153 v.AuxInt = 0
8154 return true
8155 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008156 return false
8157}
8158func rewriteValuegeneric_OpRsh16x64(v *Value, config *Config) bool {
8159 b := v.Block
8160 _ = b
8161 // match: (Rsh16x64 (Const16 [c]) (Const64 [d]))
8162 // cond:
8163 // result: (Const16 [int64(int16(c) >> uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01008164 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07008165 v_0 := v.Args[0]
8166 if v_0.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008167 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008168 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008169 c := v_0.AuxInt
8170 v_1 := v.Args[1]
8171 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008172 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008173 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008174 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008175 v.reset(OpConst16)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008176 v.AuxInt = int64(int16(c) >> uint64(d))
8177 return true
8178 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008179 // match: (Rsh16x64 x (Const64 [0]))
8180 // cond:
8181 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01008182 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05008183 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07008184 v_1 := v.Args[1]
8185 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008186 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008187 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008188 if v_1.AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008189 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008190 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008191 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008192 v.Type = x.Type
8193 v.AddArg(x)
8194 return true
8195 }
Keith Randall17396572016-05-28 21:15:24 -07008196 // match: (Rsh16x64 (Const16 [0]) _)
Keith Randallfa9435c2016-04-26 12:08:31 -07008197 // cond:
8198 // result: (Const16 [0])
8199 for {
8200 v_0 := v.Args[0]
Keith Randall17396572016-05-28 21:15:24 -07008201 if v_0.Op != OpConst16 {
Keith Randallfa9435c2016-04-26 12:08:31 -07008202 break
8203 }
8204 if v_0.AuxInt != 0 {
8205 break
8206 }
8207 v.reset(OpConst16)
8208 v.AuxInt = 0
8209 return true
8210 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008211 // match: (Rsh16x64 <t> (Rsh16x64 x (Const64 [c])) (Const64 [d]))
8212 // cond: !uaddOvf(c,d)
8213 // result: (Rsh16x64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01008214 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05008215 t := v.Type
Keith Randall259b7ed2016-03-21 16:18:45 -07008216 v_0 := v.Args[0]
8217 if v_0.Op != OpRsh16x64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008218 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008219 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008220 x := v_0.Args[0]
8221 v_0_1 := v_0.Args[1]
8222 if v_0_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008223 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008224 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008225 c := v_0_1.AuxInt
8226 v_1 := v.Args[1]
8227 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008228 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008229 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008230 d := v_1.AuxInt
Todd Neal93a0b0f2016-02-03 06:21:24 -05008231 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008232 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008233 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008234 v.reset(OpRsh16x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008235 v.AddArg(x)
8236 v0 := b.NewValue0(v.Line, OpConst64, t)
8237 v0.AuxInt = c + d
8238 v.AddArg(v0)
8239 return true
8240 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008241 return false
8242}
8243func rewriteValuegeneric_OpRsh16x8(v *Value, config *Config) bool {
8244 b := v.Block
8245 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07008246 // match: (Rsh16x8 <t> x (Const8 [c]))
Todd Neal93a0b0f2016-02-03 06:21:24 -05008247 // cond:
8248 // result: (Rsh16x64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01008249 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05008250 t := v.Type
8251 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07008252 v_1 := v.Args[1]
8253 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008254 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008255 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008256 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008257 v.reset(OpRsh16x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008258 v.AddArg(x)
8259 v0 := b.NewValue0(v.Line, OpConst64, t)
8260 v0.AuxInt = int64(uint8(c))
8261 v.AddArg(v0)
8262 return true
8263 }
Keith Randall17396572016-05-28 21:15:24 -07008264 // match: (Rsh16x8 (Const16 [0]) _)
8265 // cond:
8266 // result: (Const16 [0])
8267 for {
8268 v_0 := v.Args[0]
8269 if v_0.Op != OpConst16 {
8270 break
8271 }
8272 if v_0.AuxInt != 0 {
8273 break
8274 }
8275 v.reset(OpConst16)
8276 v.AuxInt = 0
8277 return true
8278 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008279 return false
8280}
8281func rewriteValuegeneric_OpRsh32Ux16(v *Value, config *Config) bool {
8282 b := v.Block
8283 _ = b
8284 // match: (Rsh32Ux16 <t> x (Const16 [c]))
8285 // cond:
8286 // result: (Rsh32Ux64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01008287 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05008288 t := v.Type
8289 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07008290 v_1 := v.Args[1]
8291 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008292 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008293 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008294 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008295 v.reset(OpRsh32Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008296 v.AddArg(x)
8297 v0 := b.NewValue0(v.Line, OpConst64, t)
8298 v0.AuxInt = int64(uint16(c))
8299 v.AddArg(v0)
8300 return true
8301 }
Keith Randall17396572016-05-28 21:15:24 -07008302 // match: (Rsh32Ux16 (Const32 [0]) _)
8303 // cond:
8304 // result: (Const32 [0])
8305 for {
8306 v_0 := v.Args[0]
8307 if v_0.Op != OpConst32 {
8308 break
8309 }
8310 if v_0.AuxInt != 0 {
8311 break
8312 }
8313 v.reset(OpConst32)
8314 v.AuxInt = 0
8315 return true
8316 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008317 return false
8318}
8319func rewriteValuegeneric_OpRsh32Ux32(v *Value, config *Config) bool {
8320 b := v.Block
8321 _ = b
8322 // match: (Rsh32Ux32 <t> x (Const32 [c]))
8323 // cond:
8324 // result: (Rsh32Ux64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01008325 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05008326 t := v.Type
8327 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07008328 v_1 := v.Args[1]
8329 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008330 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008331 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008332 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008333 v.reset(OpRsh32Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008334 v.AddArg(x)
8335 v0 := b.NewValue0(v.Line, OpConst64, t)
8336 v0.AuxInt = int64(uint32(c))
8337 v.AddArg(v0)
8338 return true
8339 }
Keith Randall17396572016-05-28 21:15:24 -07008340 // match: (Rsh32Ux32 (Const32 [0]) _)
8341 // cond:
8342 // result: (Const32 [0])
8343 for {
8344 v_0 := v.Args[0]
8345 if v_0.Op != OpConst32 {
8346 break
8347 }
8348 if v_0.AuxInt != 0 {
8349 break
8350 }
8351 v.reset(OpConst32)
8352 v.AuxInt = 0
8353 return true
8354 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008355 return false
8356}
8357func rewriteValuegeneric_OpRsh32Ux64(v *Value, config *Config) bool {
8358 b := v.Block
8359 _ = b
8360 // match: (Rsh32Ux64 (Const32 [c]) (Const64 [d]))
8361 // cond:
Keith Randall68ac1f72016-04-07 10:21:35 -07008362 // result: (Const32 [int64(int32(uint32(c) >> uint64(d)))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01008363 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07008364 v_0 := v.Args[0]
8365 if v_0.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008366 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008367 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008368 c := v_0.AuxInt
8369 v_1 := v.Args[1]
8370 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008371 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008372 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008373 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008374 v.reset(OpConst32)
Keith Randall68ac1f72016-04-07 10:21:35 -07008375 v.AuxInt = int64(int32(uint32(c) >> uint64(d)))
Todd Neal93a0b0f2016-02-03 06:21:24 -05008376 return true
8377 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008378 // match: (Rsh32Ux64 x (Const64 [0]))
8379 // cond:
8380 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01008381 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05008382 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07008383 v_1 := v.Args[1]
8384 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008385 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008386 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008387 if v_1.AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008388 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008389 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008390 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008391 v.Type = x.Type
8392 v.AddArg(x)
8393 return true
8394 }
Keith Randall17396572016-05-28 21:15:24 -07008395 // match: (Rsh32Ux64 (Const32 [0]) _)
Keith Randallfa9435c2016-04-26 12:08:31 -07008396 // cond:
8397 // result: (Const32 [0])
8398 for {
8399 v_0 := v.Args[0]
Keith Randall17396572016-05-28 21:15:24 -07008400 if v_0.Op != OpConst32 {
Keith Randallfa9435c2016-04-26 12:08:31 -07008401 break
8402 }
8403 if v_0.AuxInt != 0 {
8404 break
8405 }
8406 v.reset(OpConst32)
8407 v.AuxInt = 0
8408 return true
8409 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008410 // match: (Rsh32Ux64 _ (Const64 [c]))
8411 // cond: uint64(c) >= 32
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01008412 // result: (Const32 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01008413 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07008414 v_1 := v.Args[1]
8415 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008416 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008417 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008418 c := v_1.AuxInt
Todd Neal93a0b0f2016-02-03 06:21:24 -05008419 if !(uint64(c) >= 32) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008420 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008421 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01008422 v.reset(OpConst32)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008423 v.AuxInt = 0
8424 return true
8425 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008426 // match: (Rsh32Ux64 <t> (Rsh32Ux64 x (Const64 [c])) (Const64 [d]))
8427 // cond: !uaddOvf(c,d)
8428 // result: (Rsh32Ux64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01008429 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05008430 t := v.Type
Keith Randall259b7ed2016-03-21 16:18:45 -07008431 v_0 := v.Args[0]
8432 if v_0.Op != OpRsh32Ux64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008433 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008434 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008435 x := v_0.Args[0]
8436 v_0_1 := v_0.Args[1]
8437 if v_0_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008438 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008439 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008440 c := v_0_1.AuxInt
8441 v_1 := v.Args[1]
8442 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008443 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008444 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008445 d := v_1.AuxInt
Todd Neal93a0b0f2016-02-03 06:21:24 -05008446 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008447 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008448 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008449 v.reset(OpRsh32Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008450 v.AddArg(x)
8451 v0 := b.NewValue0(v.Line, OpConst64, t)
8452 v0.AuxInt = c + d
8453 v.AddArg(v0)
8454 return true
8455 }
Keith Randall17396572016-05-28 21:15:24 -07008456 // match: (Rsh32Ux64 (Lsh32x64 (Rsh32Ux64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
8457 // cond: uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
8458 // result: (Rsh32Ux64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
Keith Randallfa9435c2016-04-26 12:08:31 -07008459 for {
8460 v_0 := v.Args[0]
8461 if v_0.Op != OpLsh32x64 {
8462 break
8463 }
8464 v_0_0 := v_0.Args[0]
8465 if v_0_0.Op != OpRsh32Ux64 {
8466 break
8467 }
8468 x := v_0_0.Args[0]
8469 v_0_0_1 := v_0_0.Args[1]
Keith Randall17396572016-05-28 21:15:24 -07008470 if v_0_0_1.Op != OpConst64 {
Keith Randallfa9435c2016-04-26 12:08:31 -07008471 break
8472 }
8473 c1 := v_0_0_1.AuxInt
8474 v_0_1 := v_0.Args[1]
Keith Randall17396572016-05-28 21:15:24 -07008475 if v_0_1.Op != OpConst64 {
Keith Randallfa9435c2016-04-26 12:08:31 -07008476 break
8477 }
8478 c2 := v_0_1.AuxInt
8479 v_1 := v.Args[1]
Keith Randall17396572016-05-28 21:15:24 -07008480 if v_1.Op != OpConst64 {
Keith Randallfa9435c2016-04-26 12:08:31 -07008481 break
8482 }
8483 c3 := v_1.AuxInt
Keith Randall17396572016-05-28 21:15:24 -07008484 if !(uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)) {
Keith Randallfa9435c2016-04-26 12:08:31 -07008485 break
8486 }
8487 v.reset(OpRsh32Ux64)
8488 v.AddArg(x)
Keith Randall17396572016-05-28 21:15:24 -07008489 v0 := b.NewValue0(v.Line, OpConst64, config.fe.TypeUInt64())
8490 v0.AuxInt = c1 - c2 + c3
Keith Randallfa9435c2016-04-26 12:08:31 -07008491 v.AddArg(v0)
8492 return true
8493 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008494 return false
8495}
8496func rewriteValuegeneric_OpRsh32Ux8(v *Value, config *Config) bool {
8497 b := v.Block
8498 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07008499 // match: (Rsh32Ux8 <t> x (Const8 [c]))
Todd Neal93a0b0f2016-02-03 06:21:24 -05008500 // cond:
8501 // result: (Rsh32Ux64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01008502 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05008503 t := v.Type
8504 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07008505 v_1 := v.Args[1]
8506 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008507 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008508 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008509 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008510 v.reset(OpRsh32Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008511 v.AddArg(x)
8512 v0 := b.NewValue0(v.Line, OpConst64, t)
8513 v0.AuxInt = int64(uint8(c))
8514 v.AddArg(v0)
8515 return true
8516 }
Keith Randall17396572016-05-28 21:15:24 -07008517 // match: (Rsh32Ux8 (Const32 [0]) _)
8518 // cond:
8519 // result: (Const32 [0])
8520 for {
8521 v_0 := v.Args[0]
8522 if v_0.Op != OpConst32 {
8523 break
8524 }
8525 if v_0.AuxInt != 0 {
8526 break
8527 }
8528 v.reset(OpConst32)
8529 v.AuxInt = 0
8530 return true
8531 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008532 return false
8533}
8534func rewriteValuegeneric_OpRsh32x16(v *Value, config *Config) bool {
8535 b := v.Block
8536 _ = b
8537 // match: (Rsh32x16 <t> x (Const16 [c]))
8538 // cond:
8539 // result: (Rsh32x64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01008540 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05008541 t := v.Type
8542 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07008543 v_1 := v.Args[1]
8544 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008545 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008546 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008547 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008548 v.reset(OpRsh32x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008549 v.AddArg(x)
8550 v0 := b.NewValue0(v.Line, OpConst64, t)
8551 v0.AuxInt = int64(uint16(c))
8552 v.AddArg(v0)
8553 return true
8554 }
Keith Randall17396572016-05-28 21:15:24 -07008555 // match: (Rsh32x16 (Const32 [0]) _)
8556 // cond:
8557 // result: (Const32 [0])
8558 for {
8559 v_0 := v.Args[0]
8560 if v_0.Op != OpConst32 {
8561 break
8562 }
8563 if v_0.AuxInt != 0 {
8564 break
8565 }
8566 v.reset(OpConst32)
8567 v.AuxInt = 0
8568 return true
8569 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008570 return false
8571}
8572func rewriteValuegeneric_OpRsh32x32(v *Value, config *Config) bool {
8573 b := v.Block
8574 _ = b
8575 // match: (Rsh32x32 <t> x (Const32 [c]))
8576 // cond:
8577 // result: (Rsh32x64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01008578 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05008579 t := v.Type
8580 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07008581 v_1 := v.Args[1]
8582 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008583 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008584 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008585 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008586 v.reset(OpRsh32x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008587 v.AddArg(x)
8588 v0 := b.NewValue0(v.Line, OpConst64, t)
8589 v0.AuxInt = int64(uint32(c))
8590 v.AddArg(v0)
8591 return true
8592 }
Keith Randall17396572016-05-28 21:15:24 -07008593 // match: (Rsh32x32 (Const32 [0]) _)
8594 // cond:
8595 // result: (Const32 [0])
8596 for {
8597 v_0 := v.Args[0]
8598 if v_0.Op != OpConst32 {
8599 break
8600 }
8601 if v_0.AuxInt != 0 {
8602 break
8603 }
8604 v.reset(OpConst32)
8605 v.AuxInt = 0
8606 return true
8607 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008608 return false
8609}
8610func rewriteValuegeneric_OpRsh32x64(v *Value, config *Config) bool {
8611 b := v.Block
8612 _ = b
8613 // match: (Rsh32x64 (Const32 [c]) (Const64 [d]))
8614 // cond:
8615 // result: (Const32 [int64(int32(c) >> uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01008616 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07008617 v_0 := v.Args[0]
8618 if v_0.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008619 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008620 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008621 c := v_0.AuxInt
8622 v_1 := v.Args[1]
8623 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008624 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008625 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008626 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008627 v.reset(OpConst32)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008628 v.AuxInt = int64(int32(c) >> uint64(d))
8629 return true
8630 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008631 // match: (Rsh32x64 x (Const64 [0]))
8632 // cond:
8633 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01008634 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05008635 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07008636 v_1 := v.Args[1]
8637 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008638 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008639 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008640 if v_1.AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008641 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008642 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008643 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008644 v.Type = x.Type
8645 v.AddArg(x)
8646 return true
8647 }
Keith Randall17396572016-05-28 21:15:24 -07008648 // match: (Rsh32x64 (Const32 [0]) _)
Keith Randallfa9435c2016-04-26 12:08:31 -07008649 // cond:
8650 // result: (Const32 [0])
8651 for {
8652 v_0 := v.Args[0]
Keith Randall17396572016-05-28 21:15:24 -07008653 if v_0.Op != OpConst32 {
Keith Randallfa9435c2016-04-26 12:08:31 -07008654 break
8655 }
8656 if v_0.AuxInt != 0 {
8657 break
8658 }
8659 v.reset(OpConst32)
8660 v.AuxInt = 0
8661 return true
8662 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008663 // match: (Rsh32x64 <t> (Rsh32x64 x (Const64 [c])) (Const64 [d]))
8664 // cond: !uaddOvf(c,d)
8665 // result: (Rsh32x64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01008666 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05008667 t := v.Type
Keith Randall259b7ed2016-03-21 16:18:45 -07008668 v_0 := v.Args[0]
8669 if v_0.Op != OpRsh32x64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008670 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008671 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008672 x := v_0.Args[0]
8673 v_0_1 := v_0.Args[1]
8674 if v_0_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008675 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008676 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008677 c := v_0_1.AuxInt
8678 v_1 := v.Args[1]
8679 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008680 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008681 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008682 d := v_1.AuxInt
Todd Neal93a0b0f2016-02-03 06:21:24 -05008683 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008684 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008685 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008686 v.reset(OpRsh32x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008687 v.AddArg(x)
8688 v0 := b.NewValue0(v.Line, OpConst64, t)
8689 v0.AuxInt = c + d
8690 v.AddArg(v0)
8691 return true
8692 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008693 return false
8694}
8695func rewriteValuegeneric_OpRsh32x8(v *Value, config *Config) bool {
8696 b := v.Block
8697 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07008698 // match: (Rsh32x8 <t> x (Const8 [c]))
Todd Neal93a0b0f2016-02-03 06:21:24 -05008699 // cond:
8700 // result: (Rsh32x64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01008701 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05008702 t := v.Type
8703 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07008704 v_1 := v.Args[1]
8705 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008706 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008707 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008708 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008709 v.reset(OpRsh32x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008710 v.AddArg(x)
8711 v0 := b.NewValue0(v.Line, OpConst64, t)
8712 v0.AuxInt = int64(uint8(c))
8713 v.AddArg(v0)
8714 return true
8715 }
Keith Randall17396572016-05-28 21:15:24 -07008716 // match: (Rsh32x8 (Const32 [0]) _)
8717 // cond:
8718 // result: (Const32 [0])
8719 for {
8720 v_0 := v.Args[0]
8721 if v_0.Op != OpConst32 {
8722 break
8723 }
8724 if v_0.AuxInt != 0 {
8725 break
8726 }
8727 v.reset(OpConst32)
8728 v.AuxInt = 0
8729 return true
8730 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008731 return false
8732}
8733func rewriteValuegeneric_OpRsh64Ux16(v *Value, config *Config) bool {
8734 b := v.Block
8735 _ = b
8736 // match: (Rsh64Ux16 <t> x (Const16 [c]))
8737 // cond:
8738 // result: (Rsh64Ux64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01008739 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05008740 t := v.Type
8741 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07008742 v_1 := v.Args[1]
8743 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008744 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008745 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008746 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008747 v.reset(OpRsh64Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008748 v.AddArg(x)
8749 v0 := b.NewValue0(v.Line, OpConst64, t)
8750 v0.AuxInt = int64(uint16(c))
8751 v.AddArg(v0)
8752 return true
8753 }
Keith Randall17396572016-05-28 21:15:24 -07008754 // match: (Rsh64Ux16 (Const64 [0]) _)
8755 // cond:
8756 // result: (Const64 [0])
8757 for {
8758 v_0 := v.Args[0]
8759 if v_0.Op != OpConst64 {
8760 break
8761 }
8762 if v_0.AuxInt != 0 {
8763 break
8764 }
8765 v.reset(OpConst64)
8766 v.AuxInt = 0
8767 return true
8768 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008769 return false
8770}
8771func rewriteValuegeneric_OpRsh64Ux32(v *Value, config *Config) bool {
8772 b := v.Block
8773 _ = b
8774 // match: (Rsh64Ux32 <t> x (Const32 [c]))
8775 // cond:
8776 // result: (Rsh64Ux64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01008777 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05008778 t := v.Type
8779 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07008780 v_1 := v.Args[1]
8781 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008782 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008783 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008784 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008785 v.reset(OpRsh64Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008786 v.AddArg(x)
8787 v0 := b.NewValue0(v.Line, OpConst64, t)
8788 v0.AuxInt = int64(uint32(c))
8789 v.AddArg(v0)
8790 return true
8791 }
Keith Randall17396572016-05-28 21:15:24 -07008792 // match: (Rsh64Ux32 (Const64 [0]) _)
8793 // cond:
8794 // result: (Const64 [0])
8795 for {
8796 v_0 := v.Args[0]
8797 if v_0.Op != OpConst64 {
8798 break
8799 }
8800 if v_0.AuxInt != 0 {
8801 break
8802 }
8803 v.reset(OpConst64)
8804 v.AuxInt = 0
8805 return true
8806 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008807 return false
8808}
8809func rewriteValuegeneric_OpRsh64Ux64(v *Value, config *Config) bool {
8810 b := v.Block
8811 _ = b
8812 // match: (Rsh64Ux64 (Const64 [c]) (Const64 [d]))
8813 // cond:
8814 // result: (Const64 [int64(uint64(c) >> uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01008815 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07008816 v_0 := v.Args[0]
8817 if v_0.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008818 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008819 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008820 c := v_0.AuxInt
8821 v_1 := v.Args[1]
8822 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008823 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008824 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008825 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008826 v.reset(OpConst64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008827 v.AuxInt = int64(uint64(c) >> uint64(d))
8828 return true
8829 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008830 // match: (Rsh64Ux64 x (Const64 [0]))
8831 // cond:
8832 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01008833 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05008834 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07008835 v_1 := v.Args[1]
8836 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008837 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008838 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008839 if v_1.AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008840 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008841 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008842 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008843 v.Type = x.Type
8844 v.AddArg(x)
8845 return true
8846 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01008847 // match: (Rsh64Ux64 (Const64 [0]) _)
8848 // cond:
8849 // result: (Const64 [0])
8850 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07008851 v_0 := v.Args[0]
8852 if v_0.Op != OpConst64 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01008853 break
8854 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008855 if v_0.AuxInt != 0 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01008856 break
8857 }
8858 v.reset(OpConst64)
8859 v.AuxInt = 0
8860 return true
8861 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008862 // match: (Rsh64Ux64 _ (Const64 [c]))
8863 // cond: uint64(c) >= 64
8864 // result: (Const64 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01008865 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07008866 v_1 := v.Args[1]
8867 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008868 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008869 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008870 c := v_1.AuxInt
Todd Neal93a0b0f2016-02-03 06:21:24 -05008871 if !(uint64(c) >= 64) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008872 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008873 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008874 v.reset(OpConst64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008875 v.AuxInt = 0
8876 return true
8877 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008878 // match: (Rsh64Ux64 <t> (Rsh64Ux64 x (Const64 [c])) (Const64 [d]))
8879 // cond: !uaddOvf(c,d)
8880 // result: (Rsh64Ux64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01008881 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05008882 t := v.Type
Keith Randall259b7ed2016-03-21 16:18:45 -07008883 v_0 := v.Args[0]
8884 if v_0.Op != OpRsh64Ux64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008885 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008886 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008887 x := v_0.Args[0]
8888 v_0_1 := v_0.Args[1]
8889 if v_0_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008890 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008891 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008892 c := v_0_1.AuxInt
8893 v_1 := v.Args[1]
8894 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008895 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008896 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008897 d := v_1.AuxInt
Todd Neal93a0b0f2016-02-03 06:21:24 -05008898 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008899 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008900 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008901 v.reset(OpRsh64Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008902 v.AddArg(x)
8903 v0 := b.NewValue0(v.Line, OpConst64, t)
8904 v0.AuxInt = c + d
8905 v.AddArg(v0)
8906 return true
8907 }
Keith Randallfa9435c2016-04-26 12:08:31 -07008908 // match: (Rsh64Ux64 (Lsh64x64 (Rsh64Ux64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
Keith Randall17396572016-05-28 21:15:24 -07008909 // cond: uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
Keith Randallfa9435c2016-04-26 12:08:31 -07008910 // result: (Rsh64Ux64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
8911 for {
8912 v_0 := v.Args[0]
8913 if v_0.Op != OpLsh64x64 {
8914 break
8915 }
8916 v_0_0 := v_0.Args[0]
8917 if v_0_0.Op != OpRsh64Ux64 {
8918 break
8919 }
8920 x := v_0_0.Args[0]
8921 v_0_0_1 := v_0_0.Args[1]
8922 if v_0_0_1.Op != OpConst64 {
8923 break
8924 }
8925 c1 := v_0_0_1.AuxInt
8926 v_0_1 := v_0.Args[1]
8927 if v_0_1.Op != OpConst64 {
8928 break
8929 }
8930 c2 := v_0_1.AuxInt
8931 v_1 := v.Args[1]
8932 if v_1.Op != OpConst64 {
8933 break
8934 }
8935 c3 := v_1.AuxInt
Keith Randall17396572016-05-28 21:15:24 -07008936 if !(uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)) {
Keith Randallfa9435c2016-04-26 12:08:31 -07008937 break
8938 }
8939 v.reset(OpRsh64Ux64)
8940 v.AddArg(x)
8941 v0 := b.NewValue0(v.Line, OpConst64, config.fe.TypeUInt64())
8942 v0.AuxInt = c1 - c2 + c3
8943 v.AddArg(v0)
8944 return true
8945 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008946 return false
8947}
8948func rewriteValuegeneric_OpRsh64Ux8(v *Value, config *Config) bool {
8949 b := v.Block
8950 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07008951 // match: (Rsh64Ux8 <t> x (Const8 [c]))
Todd Neal93a0b0f2016-02-03 06:21:24 -05008952 // cond:
8953 // result: (Rsh64Ux64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01008954 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05008955 t := v.Type
8956 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07008957 v_1 := v.Args[1]
8958 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008959 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008960 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008961 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01008962 v.reset(OpRsh64Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05008963 v.AddArg(x)
8964 v0 := b.NewValue0(v.Line, OpConst64, t)
8965 v0.AuxInt = int64(uint8(c))
8966 v.AddArg(v0)
8967 return true
8968 }
Keith Randall17396572016-05-28 21:15:24 -07008969 // match: (Rsh64Ux8 (Const64 [0]) _)
8970 // cond:
8971 // result: (Const64 [0])
8972 for {
8973 v_0 := v.Args[0]
8974 if v_0.Op != OpConst64 {
8975 break
8976 }
8977 if v_0.AuxInt != 0 {
8978 break
8979 }
8980 v.reset(OpConst64)
8981 v.AuxInt = 0
8982 return true
8983 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05008984 return false
8985}
8986func rewriteValuegeneric_OpRsh64x16(v *Value, config *Config) bool {
8987 b := v.Block
8988 _ = b
8989 // match: (Rsh64x16 <t> x (Const16 [c]))
8990 // cond:
8991 // result: (Rsh64x64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01008992 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05008993 t := v.Type
8994 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07008995 v_1 := v.Args[1]
8996 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01008997 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05008998 }
Keith Randall259b7ed2016-03-21 16:18:45 -07008999 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009000 v.reset(OpRsh64x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05009001 v.AddArg(x)
9002 v0 := b.NewValue0(v.Line, OpConst64, t)
9003 v0.AuxInt = int64(uint16(c))
9004 v.AddArg(v0)
9005 return true
9006 }
Keith Randall17396572016-05-28 21:15:24 -07009007 // match: (Rsh64x16 (Const64 [0]) _)
9008 // cond:
9009 // result: (Const64 [0])
9010 for {
9011 v_0 := v.Args[0]
9012 if v_0.Op != OpConst64 {
9013 break
9014 }
9015 if v_0.AuxInt != 0 {
9016 break
9017 }
9018 v.reset(OpConst64)
9019 v.AuxInt = 0
9020 return true
9021 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05009022 return false
9023}
9024func rewriteValuegeneric_OpRsh64x32(v *Value, config *Config) bool {
9025 b := v.Block
9026 _ = b
9027 // match: (Rsh64x32 <t> x (Const32 [c]))
9028 // cond:
9029 // result: (Rsh64x64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01009030 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05009031 t := v.Type
9032 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07009033 v_1 := v.Args[1]
9034 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009035 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009036 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009037 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009038 v.reset(OpRsh64x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05009039 v.AddArg(x)
9040 v0 := b.NewValue0(v.Line, OpConst64, t)
9041 v0.AuxInt = int64(uint32(c))
9042 v.AddArg(v0)
9043 return true
9044 }
Keith Randall17396572016-05-28 21:15:24 -07009045 // match: (Rsh64x32 (Const64 [0]) _)
9046 // cond:
9047 // result: (Const64 [0])
9048 for {
9049 v_0 := v.Args[0]
9050 if v_0.Op != OpConst64 {
9051 break
9052 }
9053 if v_0.AuxInt != 0 {
9054 break
9055 }
9056 v.reset(OpConst64)
9057 v.AuxInt = 0
9058 return true
9059 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05009060 return false
9061}
9062func rewriteValuegeneric_OpRsh64x64(v *Value, config *Config) bool {
9063 b := v.Block
9064 _ = b
9065 // match: (Rsh64x64 (Const64 [c]) (Const64 [d]))
9066 // cond:
9067 // result: (Const64 [c >> uint64(d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01009068 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07009069 v_0 := v.Args[0]
9070 if v_0.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009071 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009072 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009073 c := v_0.AuxInt
9074 v_1 := v.Args[1]
9075 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009076 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009077 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009078 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009079 v.reset(OpConst64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05009080 v.AuxInt = c >> uint64(d)
9081 return true
9082 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05009083 // match: (Rsh64x64 x (Const64 [0]))
9084 // cond:
9085 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01009086 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05009087 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07009088 v_1 := v.Args[1]
9089 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009090 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009091 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009092 if v_1.AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009093 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009094 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009095 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05009096 v.Type = x.Type
9097 v.AddArg(x)
9098 return true
9099 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01009100 // match: (Rsh64x64 (Const64 [0]) _)
9101 // cond:
9102 // result: (Const64 [0])
9103 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07009104 v_0 := v.Args[0]
9105 if v_0.Op != OpConst64 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01009106 break
9107 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009108 if v_0.AuxInt != 0 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01009109 break
9110 }
9111 v.reset(OpConst64)
9112 v.AuxInt = 0
9113 return true
9114 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05009115 // match: (Rsh64x64 <t> (Rsh64x64 x (Const64 [c])) (Const64 [d]))
9116 // cond: !uaddOvf(c,d)
9117 // result: (Rsh64x64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01009118 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05009119 t := v.Type
Keith Randall259b7ed2016-03-21 16:18:45 -07009120 v_0 := v.Args[0]
9121 if v_0.Op != OpRsh64x64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009122 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009123 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009124 x := v_0.Args[0]
9125 v_0_1 := v_0.Args[1]
9126 if v_0_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009127 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009128 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009129 c := v_0_1.AuxInt
9130 v_1 := v.Args[1]
9131 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009132 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009133 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009134 d := v_1.AuxInt
Todd Neal93a0b0f2016-02-03 06:21:24 -05009135 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009136 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009137 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009138 v.reset(OpRsh64x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05009139 v.AddArg(x)
9140 v0 := b.NewValue0(v.Line, OpConst64, t)
9141 v0.AuxInt = c + d
9142 v.AddArg(v0)
9143 return true
9144 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05009145 return false
9146}
9147func rewriteValuegeneric_OpRsh64x8(v *Value, config *Config) bool {
9148 b := v.Block
9149 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07009150 // match: (Rsh64x8 <t> x (Const8 [c]))
Todd Neal93a0b0f2016-02-03 06:21:24 -05009151 // cond:
9152 // result: (Rsh64x64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01009153 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05009154 t := v.Type
9155 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07009156 v_1 := v.Args[1]
9157 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009158 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009159 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009160 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009161 v.reset(OpRsh64x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05009162 v.AddArg(x)
9163 v0 := b.NewValue0(v.Line, OpConst64, t)
9164 v0.AuxInt = int64(uint8(c))
9165 v.AddArg(v0)
9166 return true
9167 }
Keith Randall17396572016-05-28 21:15:24 -07009168 // match: (Rsh64x8 (Const64 [0]) _)
9169 // cond:
9170 // result: (Const64 [0])
9171 for {
9172 v_0 := v.Args[0]
9173 if v_0.Op != OpConst64 {
9174 break
9175 }
9176 if v_0.AuxInt != 0 {
9177 break
9178 }
9179 v.reset(OpConst64)
9180 v.AuxInt = 0
9181 return true
9182 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05009183 return false
9184}
9185func rewriteValuegeneric_OpRsh8Ux16(v *Value, config *Config) bool {
9186 b := v.Block
9187 _ = b
9188 // match: (Rsh8Ux16 <t> x (Const16 [c]))
9189 // cond:
9190 // result: (Rsh8Ux64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01009191 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05009192 t := v.Type
9193 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07009194 v_1 := v.Args[1]
9195 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009196 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009197 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009198 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009199 v.reset(OpRsh8Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05009200 v.AddArg(x)
9201 v0 := b.NewValue0(v.Line, OpConst64, t)
9202 v0.AuxInt = int64(uint16(c))
9203 v.AddArg(v0)
9204 return true
9205 }
Keith Randall17396572016-05-28 21:15:24 -07009206 // match: (Rsh8Ux16 (Const8 [0]) _)
9207 // cond:
9208 // result: (Const8 [0])
9209 for {
9210 v_0 := v.Args[0]
9211 if v_0.Op != OpConst8 {
9212 break
9213 }
9214 if v_0.AuxInt != 0 {
9215 break
9216 }
9217 v.reset(OpConst8)
9218 v.AuxInt = 0
9219 return true
9220 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05009221 return false
9222}
9223func rewriteValuegeneric_OpRsh8Ux32(v *Value, config *Config) bool {
9224 b := v.Block
9225 _ = b
9226 // match: (Rsh8Ux32 <t> x (Const32 [c]))
9227 // cond:
9228 // result: (Rsh8Ux64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01009229 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05009230 t := v.Type
9231 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07009232 v_1 := v.Args[1]
9233 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009234 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009235 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009236 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009237 v.reset(OpRsh8Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05009238 v.AddArg(x)
9239 v0 := b.NewValue0(v.Line, OpConst64, t)
9240 v0.AuxInt = int64(uint32(c))
9241 v.AddArg(v0)
9242 return true
9243 }
Keith Randall17396572016-05-28 21:15:24 -07009244 // match: (Rsh8Ux32 (Const8 [0]) _)
9245 // cond:
9246 // result: (Const8 [0])
9247 for {
9248 v_0 := v.Args[0]
9249 if v_0.Op != OpConst8 {
9250 break
9251 }
9252 if v_0.AuxInt != 0 {
9253 break
9254 }
9255 v.reset(OpConst8)
9256 v.AuxInt = 0
9257 return true
9258 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05009259 return false
9260}
9261func rewriteValuegeneric_OpRsh8Ux64(v *Value, config *Config) bool {
9262 b := v.Block
9263 _ = b
9264 // match: (Rsh8Ux64 (Const8 [c]) (Const64 [d]))
9265 // cond:
Keith Randall68ac1f72016-04-07 10:21:35 -07009266 // result: (Const8 [int64(int8(uint8(c) >> uint64(d)))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01009267 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07009268 v_0 := v.Args[0]
9269 if v_0.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009270 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009271 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009272 c := v_0.AuxInt
9273 v_1 := v.Args[1]
9274 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009275 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009276 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009277 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009278 v.reset(OpConst8)
Keith Randall68ac1f72016-04-07 10:21:35 -07009279 v.AuxInt = int64(int8(uint8(c) >> uint64(d)))
Todd Neal93a0b0f2016-02-03 06:21:24 -05009280 return true
9281 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05009282 // match: (Rsh8Ux64 x (Const64 [0]))
9283 // cond:
9284 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01009285 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05009286 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07009287 v_1 := v.Args[1]
9288 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009289 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009290 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009291 if v_1.AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009292 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009293 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009294 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05009295 v.Type = x.Type
9296 v.AddArg(x)
9297 return true
9298 }
Keith Randall17396572016-05-28 21:15:24 -07009299 // match: (Rsh8Ux64 (Const8 [0]) _)
Keith Randallfa9435c2016-04-26 12:08:31 -07009300 // cond:
9301 // result: (Const8 [0])
9302 for {
9303 v_0 := v.Args[0]
Keith Randall17396572016-05-28 21:15:24 -07009304 if v_0.Op != OpConst8 {
Keith Randallfa9435c2016-04-26 12:08:31 -07009305 break
9306 }
9307 if v_0.AuxInt != 0 {
9308 break
9309 }
9310 v.reset(OpConst8)
9311 v.AuxInt = 0
9312 return true
9313 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05009314 // match: (Rsh8Ux64 _ (Const64 [c]))
9315 // cond: uint64(c) >= 8
Keith Randallfa9435c2016-04-26 12:08:31 -07009316 // result: (Const8 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01009317 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07009318 v_1 := v.Args[1]
9319 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009320 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009321 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009322 c := v_1.AuxInt
Todd Neal93a0b0f2016-02-03 06:21:24 -05009323 if !(uint64(c) >= 8) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009324 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009325 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01009326 v.reset(OpConst8)
Todd Neal93a0b0f2016-02-03 06:21:24 -05009327 v.AuxInt = 0
9328 return true
9329 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05009330 // match: (Rsh8Ux64 <t> (Rsh8Ux64 x (Const64 [c])) (Const64 [d]))
9331 // cond: !uaddOvf(c,d)
9332 // result: (Rsh8Ux64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01009333 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05009334 t := v.Type
Keith Randall259b7ed2016-03-21 16:18:45 -07009335 v_0 := v.Args[0]
9336 if v_0.Op != OpRsh8Ux64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009337 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009338 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009339 x := v_0.Args[0]
9340 v_0_1 := v_0.Args[1]
9341 if v_0_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009342 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009343 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009344 c := v_0_1.AuxInt
9345 v_1 := v.Args[1]
9346 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009347 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009348 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009349 d := v_1.AuxInt
Todd Neal93a0b0f2016-02-03 06:21:24 -05009350 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009351 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009352 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009353 v.reset(OpRsh8Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05009354 v.AddArg(x)
9355 v0 := b.NewValue0(v.Line, OpConst64, t)
9356 v0.AuxInt = c + d
9357 v.AddArg(v0)
9358 return true
9359 }
Keith Randall17396572016-05-28 21:15:24 -07009360 // match: (Rsh8Ux64 (Lsh8x64 (Rsh8Ux64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
9361 // cond: uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
9362 // result: (Rsh8Ux64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
Todd Nealc8b148e2016-03-15 19:26:21 -05009363 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07009364 v_0 := v.Args[0]
Keith Randallfa9435c2016-04-26 12:08:31 -07009365 if v_0.Op != OpLsh8x64 {
Todd Nealc8b148e2016-03-15 19:26:21 -05009366 break
9367 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009368 v_0_0 := v_0.Args[0]
Keith Randallfa9435c2016-04-26 12:08:31 -07009369 if v_0_0.Op != OpRsh8Ux64 {
Todd Nealc8b148e2016-03-15 19:26:21 -05009370 break
9371 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009372 x := v_0_0.Args[0]
9373 v_0_0_1 := v_0_0.Args[1]
Keith Randall17396572016-05-28 21:15:24 -07009374 if v_0_0_1.Op != OpConst64 {
Todd Nealc8b148e2016-03-15 19:26:21 -05009375 break
9376 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009377 c1 := v_0_0_1.AuxInt
9378 v_0_1 := v_0.Args[1]
Keith Randall17396572016-05-28 21:15:24 -07009379 if v_0_1.Op != OpConst64 {
Todd Nealc8b148e2016-03-15 19:26:21 -05009380 break
9381 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009382 c2 := v_0_1.AuxInt
9383 v_1 := v.Args[1]
Keith Randall17396572016-05-28 21:15:24 -07009384 if v_1.Op != OpConst64 {
Todd Nealc8b148e2016-03-15 19:26:21 -05009385 break
9386 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009387 c3 := v_1.AuxInt
Keith Randall17396572016-05-28 21:15:24 -07009388 if !(uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)) {
Todd Nealc8b148e2016-03-15 19:26:21 -05009389 break
9390 }
Keith Randallfa9435c2016-04-26 12:08:31 -07009391 v.reset(OpRsh8Ux64)
Todd Nealc8b148e2016-03-15 19:26:21 -05009392 v.AddArg(x)
Keith Randall17396572016-05-28 21:15:24 -07009393 v0 := b.NewValue0(v.Line, OpConst64, config.fe.TypeUInt64())
9394 v0.AuxInt = c1 - c2 + c3
Todd Nealc8b148e2016-03-15 19:26:21 -05009395 v.AddArg(v0)
9396 return true
9397 }
Keith Randallfa9435c2016-04-26 12:08:31 -07009398 return false
9399}
9400func rewriteValuegeneric_OpRsh8Ux8(v *Value, config *Config) bool {
9401 b := v.Block
9402 _ = b
9403 // match: (Rsh8Ux8 <t> x (Const8 [c]))
Todd Neal93a0b0f2016-02-03 06:21:24 -05009404 // cond:
9405 // result: (Rsh8Ux64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01009406 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05009407 t := v.Type
9408 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07009409 v_1 := v.Args[1]
9410 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009411 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009412 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009413 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009414 v.reset(OpRsh8Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05009415 v.AddArg(x)
9416 v0 := b.NewValue0(v.Line, OpConst64, t)
9417 v0.AuxInt = int64(uint8(c))
9418 v.AddArg(v0)
9419 return true
9420 }
Keith Randall17396572016-05-28 21:15:24 -07009421 // match: (Rsh8Ux8 (Const8 [0]) _)
9422 // cond:
9423 // result: (Const8 [0])
9424 for {
9425 v_0 := v.Args[0]
9426 if v_0.Op != OpConst8 {
9427 break
9428 }
9429 if v_0.AuxInt != 0 {
9430 break
9431 }
9432 v.reset(OpConst8)
9433 v.AuxInt = 0
9434 return true
9435 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05009436 return false
9437}
9438func rewriteValuegeneric_OpRsh8x16(v *Value, config *Config) bool {
9439 b := v.Block
9440 _ = b
9441 // match: (Rsh8x16 <t> x (Const16 [c]))
9442 // cond:
9443 // result: (Rsh8x64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01009444 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05009445 t := v.Type
9446 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07009447 v_1 := v.Args[1]
9448 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009449 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009450 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009451 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009452 v.reset(OpRsh8x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05009453 v.AddArg(x)
9454 v0 := b.NewValue0(v.Line, OpConst64, t)
9455 v0.AuxInt = int64(uint16(c))
9456 v.AddArg(v0)
9457 return true
9458 }
Keith Randall17396572016-05-28 21:15:24 -07009459 // match: (Rsh8x16 (Const8 [0]) _)
9460 // cond:
9461 // result: (Const8 [0])
9462 for {
9463 v_0 := v.Args[0]
9464 if v_0.Op != OpConst8 {
9465 break
9466 }
9467 if v_0.AuxInt != 0 {
9468 break
9469 }
9470 v.reset(OpConst8)
9471 v.AuxInt = 0
9472 return true
9473 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05009474 return false
9475}
9476func rewriteValuegeneric_OpRsh8x32(v *Value, config *Config) bool {
9477 b := v.Block
9478 _ = b
9479 // match: (Rsh8x32 <t> x (Const32 [c]))
9480 // cond:
9481 // result: (Rsh8x64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01009482 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05009483 t := v.Type
9484 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07009485 v_1 := v.Args[1]
9486 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009487 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009488 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009489 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009490 v.reset(OpRsh8x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05009491 v.AddArg(x)
9492 v0 := b.NewValue0(v.Line, OpConst64, t)
9493 v0.AuxInt = int64(uint32(c))
9494 v.AddArg(v0)
9495 return true
9496 }
Keith Randall17396572016-05-28 21:15:24 -07009497 // match: (Rsh8x32 (Const8 [0]) _)
9498 // cond:
9499 // result: (Const8 [0])
9500 for {
9501 v_0 := v.Args[0]
9502 if v_0.Op != OpConst8 {
9503 break
9504 }
9505 if v_0.AuxInt != 0 {
9506 break
9507 }
9508 v.reset(OpConst8)
9509 v.AuxInt = 0
9510 return true
9511 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05009512 return false
9513}
9514func rewriteValuegeneric_OpRsh8x64(v *Value, config *Config) bool {
9515 b := v.Block
9516 _ = b
9517 // match: (Rsh8x64 (Const8 [c]) (Const64 [d]))
9518 // cond:
9519 // result: (Const8 [int64(int8(c) >> uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01009520 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07009521 v_0 := v.Args[0]
9522 if v_0.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009523 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009524 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009525 c := v_0.AuxInt
9526 v_1 := v.Args[1]
9527 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009528 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009529 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009530 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009531 v.reset(OpConst8)
Todd Neal93a0b0f2016-02-03 06:21:24 -05009532 v.AuxInt = int64(int8(c) >> uint64(d))
9533 return true
9534 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05009535 // match: (Rsh8x64 x (Const64 [0]))
9536 // cond:
9537 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01009538 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05009539 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07009540 v_1 := v.Args[1]
9541 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009542 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009543 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009544 if v_1.AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009545 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009546 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009547 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05009548 v.Type = x.Type
9549 v.AddArg(x)
9550 return true
9551 }
Keith Randall17396572016-05-28 21:15:24 -07009552 // match: (Rsh8x64 (Const8 [0]) _)
Keith Randallfa9435c2016-04-26 12:08:31 -07009553 // cond:
9554 // result: (Const8 [0])
9555 for {
9556 v_0 := v.Args[0]
Keith Randall17396572016-05-28 21:15:24 -07009557 if v_0.Op != OpConst8 {
Keith Randallfa9435c2016-04-26 12:08:31 -07009558 break
9559 }
9560 if v_0.AuxInt != 0 {
9561 break
9562 }
9563 v.reset(OpConst8)
9564 v.AuxInt = 0
9565 return true
9566 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05009567 // match: (Rsh8x64 <t> (Rsh8x64 x (Const64 [c])) (Const64 [d]))
9568 // cond: !uaddOvf(c,d)
9569 // result: (Rsh8x64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01009570 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05009571 t := v.Type
Keith Randall259b7ed2016-03-21 16:18:45 -07009572 v_0 := v.Args[0]
9573 if v_0.Op != OpRsh8x64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009574 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009575 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009576 x := v_0.Args[0]
9577 v_0_1 := v_0.Args[1]
9578 if v_0_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009579 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009580 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009581 c := v_0_1.AuxInt
9582 v_1 := v.Args[1]
9583 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009584 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009585 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009586 d := v_1.AuxInt
Todd Neal93a0b0f2016-02-03 06:21:24 -05009587 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009588 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009589 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009590 v.reset(OpRsh8x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05009591 v.AddArg(x)
9592 v0 := b.NewValue0(v.Line, OpConst64, t)
9593 v0.AuxInt = c + d
9594 v.AddArg(v0)
9595 return true
9596 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05009597 return false
9598}
9599func rewriteValuegeneric_OpRsh8x8(v *Value, config *Config) bool {
9600 b := v.Block
9601 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -07009602 // match: (Rsh8x8 <t> x (Const8 [c]))
Todd Neal93a0b0f2016-02-03 06:21:24 -05009603 // cond:
9604 // result: (Rsh8x64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01009605 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05009606 t := v.Type
9607 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07009608 v_1 := v.Args[1]
9609 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009610 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05009611 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009612 c := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009613 v.reset(OpRsh8x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05009614 v.AddArg(x)
9615 v0 := b.NewValue0(v.Line, OpConst64, t)
9616 v0.AuxInt = int64(uint8(c))
9617 v.AddArg(v0)
9618 return true
9619 }
Keith Randall17396572016-05-28 21:15:24 -07009620 // match: (Rsh8x8 (Const8 [0]) _)
9621 // cond:
9622 // result: (Const8 [0])
9623 for {
9624 v_0 := v.Args[0]
9625 if v_0.Op != OpConst8 {
9626 break
9627 }
9628 if v_0.AuxInt != 0 {
9629 break
9630 }
9631 v.reset(OpConst8)
9632 v.AuxInt = 0
9633 return true
9634 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05009635 return false
9636}
Keith Randalla347ab72015-10-26 21:49:31 -07009637func rewriteValuegeneric_OpSliceCap(v *Value, config *Config) bool {
9638 b := v.Block
9639 _ = b
Alexandru Moșoidfcb8532016-03-03 11:13:43 +01009640 // match: (SliceCap (SliceMake _ _ (Const64 <t> [c])))
Keith Randalla347ab72015-10-26 21:49:31 -07009641 // cond:
Alexandru Moșoidfcb8532016-03-03 11:13:43 +01009642 // result: (Const64 <t> [c])
Alexandru Moșoi05434472016-02-04 19:52:10 +01009643 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07009644 v_0 := v.Args[0]
9645 if v_0.Op != OpSliceMake {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009646 break
Keith Randalla347ab72015-10-26 21:49:31 -07009647 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009648 v_0_2 := v_0.Args[2]
9649 if v_0_2.Op != OpConst64 {
Alexandru Moșoidfcb8532016-03-03 11:13:43 +01009650 break
9651 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009652 t := v_0_2.Type
9653 c := v_0_2.AuxInt
Alexandru Moșoidfcb8532016-03-03 11:13:43 +01009654 v.reset(OpConst64)
9655 v.Type = t
9656 v.AuxInt = c
Keith Randalla347ab72015-10-26 21:49:31 -07009657 return true
9658 }
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01009659 // match: (SliceCap (SliceMake _ _ (SliceCap x)))
9660 // cond:
9661 // result: (SliceCap x)
9662 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07009663 v_0 := v.Args[0]
9664 if v_0.Op != OpSliceMake {
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01009665 break
9666 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009667 v_0_2 := v_0.Args[2]
9668 if v_0_2.Op != OpSliceCap {
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01009669 break
9670 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009671 x := v_0_2.Args[0]
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01009672 v.reset(OpSliceCap)
9673 v.AddArg(x)
9674 return true
9675 }
Alexandru Moșoie61db312016-03-22 17:34:36 +01009676 // match: (SliceCap (SliceMake _ _ (SliceLen x)))
9677 // cond:
9678 // result: (SliceLen x)
9679 for {
9680 v_0 := v.Args[0]
9681 if v_0.Op != OpSliceMake {
9682 break
9683 }
9684 v_0_2 := v_0.Args[2]
9685 if v_0_2.Op != OpSliceLen {
9686 break
9687 }
9688 x := v_0_2.Args[0]
9689 v.reset(OpSliceLen)
9690 v.AddArg(x)
9691 return true
9692 }
Keith Randalla347ab72015-10-26 21:49:31 -07009693 return false
9694}
9695func rewriteValuegeneric_OpSliceLen(v *Value, config *Config) bool {
9696 b := v.Block
9697 _ = b
Alexandru Moșoidfcb8532016-03-03 11:13:43 +01009698 // match: (SliceLen (SliceMake _ (Const64 <t> [c]) _))
Keith Randalla347ab72015-10-26 21:49:31 -07009699 // cond:
Alexandru Moșoidfcb8532016-03-03 11:13:43 +01009700 // result: (Const64 <t> [c])
Alexandru Moșoi05434472016-02-04 19:52:10 +01009701 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07009702 v_0 := v.Args[0]
9703 if v_0.Op != OpSliceMake {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009704 break
Keith Randalla347ab72015-10-26 21:49:31 -07009705 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009706 v_0_1 := v_0.Args[1]
9707 if v_0_1.Op != OpConst64 {
Alexandru Moșoidfcb8532016-03-03 11:13:43 +01009708 break
9709 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009710 t := v_0_1.Type
9711 c := v_0_1.AuxInt
Alexandru Moșoidfcb8532016-03-03 11:13:43 +01009712 v.reset(OpConst64)
9713 v.Type = t
9714 v.AuxInt = c
Keith Randalla347ab72015-10-26 21:49:31 -07009715 return true
9716 }
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01009717 // match: (SliceLen (SliceMake _ (SliceLen x) _))
9718 // cond:
9719 // result: (SliceLen x)
9720 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07009721 v_0 := v.Args[0]
9722 if v_0.Op != OpSliceMake {
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01009723 break
9724 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009725 v_0_1 := v_0.Args[1]
9726 if v_0_1.Op != OpSliceLen {
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01009727 break
9728 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009729 x := v_0_1.Args[0]
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01009730 v.reset(OpSliceLen)
9731 v.AddArg(x)
9732 return true
9733 }
Keith Randalla347ab72015-10-26 21:49:31 -07009734 return false
9735}
9736func rewriteValuegeneric_OpSlicePtr(v *Value, config *Config) bool {
9737 b := v.Block
9738 _ = b
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01009739 // match: (SlicePtr (SliceMake (SlicePtr x) _ _))
9740 // cond:
9741 // result: (SlicePtr x)
9742 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07009743 v_0 := v.Args[0]
9744 if v_0.Op != OpSliceMake {
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01009745 break
9746 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009747 v_0_0 := v_0.Args[0]
9748 if v_0_0.Op != OpSlicePtr {
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01009749 break
9750 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009751 x := v_0_0.Args[0]
Alexandru Moșoicd798dc2016-03-07 18:36:16 +01009752 v.reset(OpSlicePtr)
9753 v.AddArg(x)
9754 return true
9755 }
Keith Randalla347ab72015-10-26 21:49:31 -07009756 return false
9757}
Kevin Burke8e24a982016-08-20 22:05:47 -07009758func rewriteValuegeneric_OpSqrt(v *Value, config *Config) bool {
9759 b := v.Block
9760 _ = b
9761 // match: (Sqrt (Const64F [c]))
9762 // cond:
9763 // result: (Const64F [f2i(math.Sqrt(i2f(c)))])
9764 for {
9765 v_0 := v.Args[0]
9766 if v_0.Op != OpConst64F {
9767 break
9768 }
9769 c := v_0.AuxInt
9770 v.reset(OpConst64F)
9771 v.AuxInt = f2i(math.Sqrt(i2f(c)))
9772 return true
9773 }
9774 return false
9775}
Keith Randalla347ab72015-10-26 21:49:31 -07009776func rewriteValuegeneric_OpStore(v *Value, config *Config) bool {
9777 b := v.Block
9778 _ = b
Keith Randalla734bbc2016-01-11 21:05:33 -08009779 // match: (Store _ (StructMake0) mem)
9780 // cond:
9781 // result: mem
Alexandru Moșoi05434472016-02-04 19:52:10 +01009782 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07009783 v_1 := v.Args[1]
9784 if v_1.Op != OpStructMake0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009785 break
Keith Randalla734bbc2016-01-11 21:05:33 -08009786 }
9787 mem := v.Args[2]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009788 v.reset(OpCopy)
Keith Randalla734bbc2016-01-11 21:05:33 -08009789 v.Type = mem.Type
9790 v.AddArg(mem)
9791 return true
9792 }
Keith Randalla734bbc2016-01-11 21:05:33 -08009793 // match: (Store dst (StructMake1 <t> f0) mem)
9794 // cond:
9795 // result: (Store [t.FieldType(0).Size()] dst f0 mem)
Alexandru Moșoi05434472016-02-04 19:52:10 +01009796 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08009797 dst := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07009798 v_1 := v.Args[1]
9799 if v_1.Op != OpStructMake1 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009800 break
Keith Randalla734bbc2016-01-11 21:05:33 -08009801 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009802 t := v_1.Type
9803 f0 := v_1.Args[0]
Keith Randalla734bbc2016-01-11 21:05:33 -08009804 mem := v.Args[2]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009805 v.reset(OpStore)
Keith Randalla734bbc2016-01-11 21:05:33 -08009806 v.AuxInt = t.FieldType(0).Size()
9807 v.AddArg(dst)
9808 v.AddArg(f0)
9809 v.AddArg(mem)
9810 return true
9811 }
Keith Randalla734bbc2016-01-11 21:05:33 -08009812 // match: (Store dst (StructMake2 <t> f0 f1) mem)
9813 // cond:
9814 // result: (Store [t.FieldType(1).Size()] (OffPtr <t.FieldType(1).PtrTo()> [t.FieldOff(1)] dst) f1 (Store [t.FieldType(0).Size()] dst f0 mem))
Alexandru Moșoi05434472016-02-04 19:52:10 +01009815 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08009816 dst := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07009817 v_1 := v.Args[1]
9818 if v_1.Op != OpStructMake2 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009819 break
Keith Randalla734bbc2016-01-11 21:05:33 -08009820 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009821 t := v_1.Type
9822 f0 := v_1.Args[0]
9823 f1 := v_1.Args[1]
Keith Randalla734bbc2016-01-11 21:05:33 -08009824 mem := v.Args[2]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009825 v.reset(OpStore)
Keith Randalla734bbc2016-01-11 21:05:33 -08009826 v.AuxInt = t.FieldType(1).Size()
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01009827 v0 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(1).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08009828 v0.AuxInt = t.FieldOff(1)
9829 v0.AddArg(dst)
9830 v.AddArg(v0)
9831 v.AddArg(f1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01009832 v1 := b.NewValue0(v.Line, OpStore, TypeMem)
Keith Randalla734bbc2016-01-11 21:05:33 -08009833 v1.AuxInt = t.FieldType(0).Size()
9834 v1.AddArg(dst)
9835 v1.AddArg(f0)
9836 v1.AddArg(mem)
Keith Randalla734bbc2016-01-11 21:05:33 -08009837 v.AddArg(v1)
9838 return true
9839 }
Keith Randalla734bbc2016-01-11 21:05:33 -08009840 // match: (Store dst (StructMake3 <t> f0 f1 f2) mem)
9841 // cond:
9842 // result: (Store [t.FieldType(2).Size()] (OffPtr <t.FieldType(2).PtrTo()> [t.FieldOff(2)] dst) f2 (Store [t.FieldType(1).Size()] (OffPtr <t.FieldType(1).PtrTo()> [t.FieldOff(1)] dst) f1 (Store [t.FieldType(0).Size()] dst f0 mem)))
Alexandru Moșoi05434472016-02-04 19:52:10 +01009843 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08009844 dst := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07009845 v_1 := v.Args[1]
9846 if v_1.Op != OpStructMake3 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009847 break
Keith Randalla734bbc2016-01-11 21:05:33 -08009848 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009849 t := v_1.Type
9850 f0 := v_1.Args[0]
9851 f1 := v_1.Args[1]
9852 f2 := v_1.Args[2]
Keith Randalla734bbc2016-01-11 21:05:33 -08009853 mem := v.Args[2]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009854 v.reset(OpStore)
Keith Randalla734bbc2016-01-11 21:05:33 -08009855 v.AuxInt = t.FieldType(2).Size()
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01009856 v0 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(2).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08009857 v0.AuxInt = t.FieldOff(2)
9858 v0.AddArg(dst)
9859 v.AddArg(v0)
9860 v.AddArg(f2)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01009861 v1 := b.NewValue0(v.Line, OpStore, TypeMem)
Keith Randalla734bbc2016-01-11 21:05:33 -08009862 v1.AuxInt = t.FieldType(1).Size()
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01009863 v2 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(1).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08009864 v2.AuxInt = t.FieldOff(1)
9865 v2.AddArg(dst)
9866 v1.AddArg(v2)
9867 v1.AddArg(f1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01009868 v3 := b.NewValue0(v.Line, OpStore, TypeMem)
Keith Randalla734bbc2016-01-11 21:05:33 -08009869 v3.AuxInt = t.FieldType(0).Size()
9870 v3.AddArg(dst)
9871 v3.AddArg(f0)
9872 v3.AddArg(mem)
Keith Randalla734bbc2016-01-11 21:05:33 -08009873 v1.AddArg(v3)
Keith Randalla734bbc2016-01-11 21:05:33 -08009874 v.AddArg(v1)
9875 return true
9876 }
Keith Randalla734bbc2016-01-11 21:05:33 -08009877 // match: (Store dst (StructMake4 <t> f0 f1 f2 f3) mem)
9878 // cond:
9879 // result: (Store [t.FieldType(3).Size()] (OffPtr <t.FieldType(3).PtrTo()> [t.FieldOff(3)] dst) f3 (Store [t.FieldType(2).Size()] (OffPtr <t.FieldType(2).PtrTo()> [t.FieldOff(2)] dst) f2 (Store [t.FieldType(1).Size()] (OffPtr <t.FieldType(1).PtrTo()> [t.FieldOff(1)] dst) f1 (Store [t.FieldType(0).Size()] dst f0 mem))))
Alexandru Moșoi05434472016-02-04 19:52:10 +01009880 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08009881 dst := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07009882 v_1 := v.Args[1]
9883 if v_1.Op != OpStructMake4 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009884 break
Keith Randalla734bbc2016-01-11 21:05:33 -08009885 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009886 t := v_1.Type
9887 f0 := v_1.Args[0]
9888 f1 := v_1.Args[1]
9889 f2 := v_1.Args[2]
9890 f3 := v_1.Args[3]
Keith Randalla734bbc2016-01-11 21:05:33 -08009891 mem := v.Args[2]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009892 v.reset(OpStore)
Keith Randalla734bbc2016-01-11 21:05:33 -08009893 v.AuxInt = t.FieldType(3).Size()
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01009894 v0 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(3).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08009895 v0.AuxInt = t.FieldOff(3)
9896 v0.AddArg(dst)
9897 v.AddArg(v0)
9898 v.AddArg(f3)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01009899 v1 := b.NewValue0(v.Line, OpStore, TypeMem)
Keith Randalla734bbc2016-01-11 21:05:33 -08009900 v1.AuxInt = t.FieldType(2).Size()
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01009901 v2 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(2).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08009902 v2.AuxInt = t.FieldOff(2)
9903 v2.AddArg(dst)
9904 v1.AddArg(v2)
9905 v1.AddArg(f2)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01009906 v3 := b.NewValue0(v.Line, OpStore, TypeMem)
Keith Randalla734bbc2016-01-11 21:05:33 -08009907 v3.AuxInt = t.FieldType(1).Size()
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01009908 v4 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(1).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08009909 v4.AuxInt = t.FieldOff(1)
9910 v4.AddArg(dst)
9911 v3.AddArg(v4)
9912 v3.AddArg(f1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01009913 v5 := b.NewValue0(v.Line, OpStore, TypeMem)
Keith Randalla734bbc2016-01-11 21:05:33 -08009914 v5.AuxInt = t.FieldType(0).Size()
9915 v5.AddArg(dst)
9916 v5.AddArg(f0)
9917 v5.AddArg(mem)
Keith Randalla734bbc2016-01-11 21:05:33 -08009918 v3.AddArg(v5)
Keith Randalla734bbc2016-01-11 21:05:33 -08009919 v1.AddArg(v3)
Keith Randalla734bbc2016-01-11 21:05:33 -08009920 v.AddArg(v1)
9921 return true
9922 }
Keith Randalla347ab72015-10-26 21:49:31 -07009923 // match: (Store [size] dst (Load <t> src mem) mem)
9924 // cond: !config.fe.CanSSA(t)
Cherry Zhangf5531782016-06-27 16:54:57 -04009925 // result: (Move [MakeSizeAndAlign(size, t.Alignment()).Int64()] dst src mem)
Alexandru Moșoi05434472016-02-04 19:52:10 +01009926 for {
Keith Randalla347ab72015-10-26 21:49:31 -07009927 size := v.AuxInt
9928 dst := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07009929 v_1 := v.Args[1]
9930 if v_1.Op != OpLoad {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009931 break
Keith Randalla347ab72015-10-26 21:49:31 -07009932 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009933 t := v_1.Type
9934 src := v_1.Args[0]
9935 mem := v_1.Args[1]
9936 if mem != v.Args[2] {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009937 break
Keith Randalla347ab72015-10-26 21:49:31 -07009938 }
9939 if !(!config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009940 break
Keith Randalla347ab72015-10-26 21:49:31 -07009941 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009942 v.reset(OpMove)
Cherry Zhangf5531782016-06-27 16:54:57 -04009943 v.AuxInt = MakeSizeAndAlign(size, t.Alignment()).Int64()
Keith Randalla347ab72015-10-26 21:49:31 -07009944 v.AddArg(dst)
9945 v.AddArg(src)
9946 v.AddArg(mem)
9947 return true
9948 }
Keith Randalla347ab72015-10-26 21:49:31 -07009949 // match: (Store [size] dst (Load <t> src mem) (VarDef {x} mem))
9950 // cond: !config.fe.CanSSA(t)
Cherry Zhangf5531782016-06-27 16:54:57 -04009951 // result: (Move [MakeSizeAndAlign(size, t.Alignment()).Int64()] dst src (VarDef {x} mem))
Alexandru Moșoi05434472016-02-04 19:52:10 +01009952 for {
Keith Randalla347ab72015-10-26 21:49:31 -07009953 size := v.AuxInt
9954 dst := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -07009955 v_1 := v.Args[1]
9956 if v_1.Op != OpLoad {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009957 break
Keith Randalla347ab72015-10-26 21:49:31 -07009958 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009959 t := v_1.Type
9960 src := v_1.Args[0]
9961 mem := v_1.Args[1]
9962 v_2 := v.Args[2]
9963 if v_2.Op != OpVarDef {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009964 break
Keith Randalla347ab72015-10-26 21:49:31 -07009965 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009966 x := v_2.Aux
9967 if mem != v_2.Args[0] {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009968 break
Keith Randalla347ab72015-10-26 21:49:31 -07009969 }
9970 if !(!config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009971 break
Keith Randalla347ab72015-10-26 21:49:31 -07009972 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01009973 v.reset(OpMove)
Cherry Zhangf5531782016-06-27 16:54:57 -04009974 v.AuxInt = MakeSizeAndAlign(size, t.Alignment()).Int64()
Keith Randalla347ab72015-10-26 21:49:31 -07009975 v.AddArg(dst)
9976 v.AddArg(src)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01009977 v0 := b.NewValue0(v.Line, OpVarDef, TypeMem)
Keith Randalla347ab72015-10-26 21:49:31 -07009978 v0.Aux = x
9979 v0.AddArg(mem)
Keith Randalla347ab72015-10-26 21:49:31 -07009980 v.AddArg(v0)
9981 return true
9982 }
Keith Randalla347ab72015-10-26 21:49:31 -07009983 return false
9984}
9985func rewriteValuegeneric_OpStringLen(v *Value, config *Config) bool {
9986 b := v.Block
9987 _ = b
Alexandru Moșoidfcb8532016-03-03 11:13:43 +01009988 // match: (StringLen (StringMake _ (Const64 <t> [c])))
Keith Randalla347ab72015-10-26 21:49:31 -07009989 // cond:
Alexandru Moșoidfcb8532016-03-03 11:13:43 +01009990 // result: (Const64 <t> [c])
Alexandru Moșoi05434472016-02-04 19:52:10 +01009991 for {
Keith Randall259b7ed2016-03-21 16:18:45 -07009992 v_0 := v.Args[0]
9993 if v_0.Op != OpStringMake {
Alexandru Moșoi05434472016-02-04 19:52:10 +01009994 break
Keith Randalla347ab72015-10-26 21:49:31 -07009995 }
Keith Randall259b7ed2016-03-21 16:18:45 -07009996 v_0_1 := v_0.Args[1]
9997 if v_0_1.Op != OpConst64 {
Alexandru Moșoidfcb8532016-03-03 11:13:43 +01009998 break
9999 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010000 t := v_0_1.Type
10001 c := v_0_1.AuxInt
Alexandru Moșoidfcb8532016-03-03 11:13:43 +010010002 v.reset(OpConst64)
10003 v.Type = t
10004 v.AuxInt = c
Keith Randalla347ab72015-10-26 21:49:31 -070010005 return true
10006 }
Keith Randalla347ab72015-10-26 21:49:31 -070010007 return false
10008}
10009func rewriteValuegeneric_OpStringPtr(v *Value, config *Config) bool {
10010 b := v.Block
10011 _ = b
Alexandru Moșoidfcb8532016-03-03 11:13:43 +010010012 // match: (StringPtr (StringMake (Const64 <t> [c]) _))
Keith Randalla347ab72015-10-26 21:49:31 -070010013 // cond:
Alexandru Moșoidfcb8532016-03-03 11:13:43 +010010014 // result: (Const64 <t> [c])
Alexandru Moșoi05434472016-02-04 19:52:10 +010010015 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010016 v_0 := v.Args[0]
10017 if v_0.Op != OpStringMake {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010018 break
Keith Randalla347ab72015-10-26 21:49:31 -070010019 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010020 v_0_0 := v_0.Args[0]
10021 if v_0_0.Op != OpConst64 {
Alexandru Moșoidfcb8532016-03-03 11:13:43 +010010022 break
10023 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010024 t := v_0_0.Type
10025 c := v_0_0.AuxInt
Alexandru Moșoidfcb8532016-03-03 11:13:43 +010010026 v.reset(OpConst64)
10027 v.Type = t
10028 v.AuxInt = c
Keith Randalla347ab72015-10-26 21:49:31 -070010029 return true
10030 }
Keith Randalla347ab72015-10-26 21:49:31 -070010031 return false
10032}
10033func rewriteValuegeneric_OpStructSelect(v *Value, config *Config) bool {
10034 b := v.Block
10035 _ = b
Keith Randalla734bbc2016-01-11 21:05:33 -080010036 // match: (StructSelect (StructMake1 x))
Keith Randalla347ab72015-10-26 21:49:31 -070010037 // cond:
Keith Randalla734bbc2016-01-11 21:05:33 -080010038 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +010010039 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010040 v_0 := v.Args[0]
10041 if v_0.Op != OpStructMake1 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010042 break
Keith Randalla347ab72015-10-26 21:49:31 -070010043 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010044 x := v_0.Args[0]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010045 v.reset(OpCopy)
Keith Randalla734bbc2016-01-11 21:05:33 -080010046 v.Type = x.Type
10047 v.AddArg(x)
10048 return true
10049 }
Keith Randalla734bbc2016-01-11 21:05:33 -080010050 // match: (StructSelect [0] (StructMake2 x _))
10051 // cond:
10052 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +010010053 for {
Keith Randalla734bbc2016-01-11 21:05:33 -080010054 if v.AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010055 break
Keith Randalla734bbc2016-01-11 21:05:33 -080010056 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010057 v_0 := v.Args[0]
10058 if v_0.Op != OpStructMake2 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010059 break
Keith Randalla734bbc2016-01-11 21:05:33 -080010060 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010061 x := v_0.Args[0]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010062 v.reset(OpCopy)
Keith Randalla734bbc2016-01-11 21:05:33 -080010063 v.Type = x.Type
10064 v.AddArg(x)
10065 return true
10066 }
Keith Randalla734bbc2016-01-11 21:05:33 -080010067 // match: (StructSelect [1] (StructMake2 _ x))
10068 // cond:
10069 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +010010070 for {
Keith Randalla734bbc2016-01-11 21:05:33 -080010071 if v.AuxInt != 1 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010072 break
Keith Randalla734bbc2016-01-11 21:05:33 -080010073 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010074 v_0 := v.Args[0]
10075 if v_0.Op != OpStructMake2 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010076 break
Keith Randalla734bbc2016-01-11 21:05:33 -080010077 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010078 x := v_0.Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010079 v.reset(OpCopy)
Keith Randalla734bbc2016-01-11 21:05:33 -080010080 v.Type = x.Type
10081 v.AddArg(x)
10082 return true
10083 }
Keith Randalla734bbc2016-01-11 21:05:33 -080010084 // match: (StructSelect [0] (StructMake3 x _ _))
10085 // cond:
10086 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +010010087 for {
Keith Randalla734bbc2016-01-11 21:05:33 -080010088 if v.AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010089 break
Keith Randalla734bbc2016-01-11 21:05:33 -080010090 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010091 v_0 := v.Args[0]
10092 if v_0.Op != OpStructMake3 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010093 break
Keith Randalla734bbc2016-01-11 21:05:33 -080010094 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010095 x := v_0.Args[0]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010096 v.reset(OpCopy)
Keith Randalla734bbc2016-01-11 21:05:33 -080010097 v.Type = x.Type
10098 v.AddArg(x)
10099 return true
10100 }
Keith Randalla734bbc2016-01-11 21:05:33 -080010101 // match: (StructSelect [1] (StructMake3 _ x _))
10102 // cond:
10103 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +010010104 for {
Keith Randalla734bbc2016-01-11 21:05:33 -080010105 if v.AuxInt != 1 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010106 break
Keith Randalla734bbc2016-01-11 21:05:33 -080010107 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010108 v_0 := v.Args[0]
10109 if v_0.Op != OpStructMake3 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010110 break
Keith Randalla734bbc2016-01-11 21:05:33 -080010111 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010112 x := v_0.Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010113 v.reset(OpCopy)
Keith Randalla734bbc2016-01-11 21:05:33 -080010114 v.Type = x.Type
10115 v.AddArg(x)
10116 return true
10117 }
Keith Randalla734bbc2016-01-11 21:05:33 -080010118 // match: (StructSelect [2] (StructMake3 _ _ x))
10119 // cond:
10120 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +010010121 for {
Keith Randalla734bbc2016-01-11 21:05:33 -080010122 if v.AuxInt != 2 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010123 break
Keith Randalla734bbc2016-01-11 21:05:33 -080010124 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010125 v_0 := v.Args[0]
10126 if v_0.Op != OpStructMake3 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010127 break
Keith Randalla734bbc2016-01-11 21:05:33 -080010128 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010129 x := v_0.Args[2]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010130 v.reset(OpCopy)
Keith Randalla734bbc2016-01-11 21:05:33 -080010131 v.Type = x.Type
10132 v.AddArg(x)
10133 return true
10134 }
Keith Randalla734bbc2016-01-11 21:05:33 -080010135 // match: (StructSelect [0] (StructMake4 x _ _ _))
10136 // cond:
10137 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +010010138 for {
Keith Randalla734bbc2016-01-11 21:05:33 -080010139 if v.AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010140 break
Keith Randalla734bbc2016-01-11 21:05:33 -080010141 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010142 v_0 := v.Args[0]
10143 if v_0.Op != OpStructMake4 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010144 break
Keith Randalla734bbc2016-01-11 21:05:33 -080010145 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010146 x := v_0.Args[0]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010147 v.reset(OpCopy)
Keith Randalla734bbc2016-01-11 21:05:33 -080010148 v.Type = x.Type
10149 v.AddArg(x)
10150 return true
10151 }
Keith Randalla734bbc2016-01-11 21:05:33 -080010152 // match: (StructSelect [1] (StructMake4 _ x _ _))
10153 // cond:
10154 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +010010155 for {
Keith Randalla734bbc2016-01-11 21:05:33 -080010156 if v.AuxInt != 1 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010157 break
Keith Randalla734bbc2016-01-11 21:05:33 -080010158 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010159 v_0 := v.Args[0]
10160 if v_0.Op != OpStructMake4 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010161 break
Keith Randalla734bbc2016-01-11 21:05:33 -080010162 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010163 x := v_0.Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010164 v.reset(OpCopy)
Keith Randalla734bbc2016-01-11 21:05:33 -080010165 v.Type = x.Type
10166 v.AddArg(x)
10167 return true
10168 }
Keith Randalla734bbc2016-01-11 21:05:33 -080010169 // match: (StructSelect [2] (StructMake4 _ _ x _))
10170 // cond:
10171 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +010010172 for {
Keith Randalla734bbc2016-01-11 21:05:33 -080010173 if v.AuxInt != 2 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010174 break
Keith Randalla734bbc2016-01-11 21:05:33 -080010175 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010176 v_0 := v.Args[0]
10177 if v_0.Op != OpStructMake4 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010178 break
Keith Randalla734bbc2016-01-11 21:05:33 -080010179 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010180 x := v_0.Args[2]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010181 v.reset(OpCopy)
Keith Randalla734bbc2016-01-11 21:05:33 -080010182 v.Type = x.Type
10183 v.AddArg(x)
10184 return true
10185 }
Keith Randalla734bbc2016-01-11 21:05:33 -080010186 // match: (StructSelect [3] (StructMake4 _ _ _ x))
10187 // cond:
10188 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +010010189 for {
Keith Randalla734bbc2016-01-11 21:05:33 -080010190 if v.AuxInt != 3 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010191 break
Keith Randalla734bbc2016-01-11 21:05:33 -080010192 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010193 v_0 := v.Args[0]
10194 if v_0.Op != OpStructMake4 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010195 break
Keith Randalla734bbc2016-01-11 21:05:33 -080010196 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010197 x := v_0.Args[3]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010198 v.reset(OpCopy)
Keith Randalla734bbc2016-01-11 21:05:33 -080010199 v.Type = x.Type
10200 v.AddArg(x)
10201 return true
10202 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010203 // match: (StructSelect [i] x:(Load <t> ptr mem))
Keith Randalla734bbc2016-01-11 21:05:33 -080010204 // cond: !config.fe.CanSSA(t)
Keith Randall259b7ed2016-03-21 16:18:45 -070010205 // result: @x.Block (Load <v.Type> (OffPtr <v.Type.PtrTo()> [t.FieldOff(int(i))] ptr) mem)
Alexandru Moșoi05434472016-02-04 19:52:10 +010010206 for {
Keith Randalla734bbc2016-01-11 21:05:33 -080010207 i := v.AuxInt
Keith Randall259b7ed2016-03-21 16:18:45 -070010208 x := v.Args[0]
10209 if x.Op != OpLoad {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010210 break
Keith Randalla734bbc2016-01-11 21:05:33 -080010211 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010212 t := x.Type
10213 ptr := x.Args[0]
10214 mem := x.Args[1]
Keith Randalla734bbc2016-01-11 21:05:33 -080010215 if !(!config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010216 break
Keith Randalla734bbc2016-01-11 21:05:33 -080010217 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010218 b = x.Block
Keith Randalled737fd2016-02-24 10:29:27 -080010219 v0 := b.NewValue0(v.Line, OpLoad, v.Type)
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010220 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -070010221 v.AddArg(v0)
Keith Randalled737fd2016-02-24 10:29:27 -080010222 v1 := b.NewValue0(v.Line, OpOffPtr, v.Type.PtrTo())
Matthew Dempsky1b9f1682016-03-14 12:45:18 -070010223 v1.AuxInt = t.FieldOff(int(i))
Keith Randalla347ab72015-10-26 21:49:31 -070010224 v1.AddArg(ptr)
10225 v0.AddArg(v1)
10226 v0.AddArg(mem)
10227 return true
10228 }
Keith Randalla347ab72015-10-26 21:49:31 -070010229 return false
10230}
10231func rewriteValuegeneric_OpSub16(v *Value, config *Config) bool {
10232 b := v.Block
10233 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -070010234 // match: (Sub16 (Const16 [c]) (Const16 [d]))
Keith Randall582baae2015-11-02 21:28:13 -080010235 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -070010236 // result: (Const16 [int64(int16(c-d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +010010237 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010238 v_0 := v.Args[0]
10239 if v_0.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010240 break
Keith Randall582baae2015-11-02 21:28:13 -080010241 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010242 c := v_0.AuxInt
10243 v_1 := v.Args[1]
10244 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010245 break
Keith Randall582baae2015-11-02 21:28:13 -080010246 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010247 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010248 v.reset(OpConst16)
Keith Randall7fc56212016-03-29 16:39:53 -070010249 v.AuxInt = int64(int16(c - d))
Keith Randall582baae2015-11-02 21:28:13 -080010250 return true
10251 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010252 // match: (Sub16 x (Const16 <t> [c]))
10253 // cond: x.Op != OpConst16
Keith Randall7fc56212016-03-29 16:39:53 -070010254 // result: (Add16 (Const16 <t> [int64(int16(-c))]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +010010255 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010256 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -070010257 v_1 := v.Args[1]
10258 if v_1.Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010259 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010260 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010261 t := v_1.Type
10262 c := v_1.AuxInt
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010263 if !(x.Op != OpConst16) {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010264 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010265 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010266 v.reset(OpAdd16)
Todd Neal93a0b0f2016-02-03 06:21:24 -050010267 v0 := b.NewValue0(v.Line, OpConst16, t)
Keith Randall7fc56212016-03-29 16:39:53 -070010268 v0.AuxInt = int64(int16(-c))
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010269 v.AddArg(v0)
10270 v.AddArg(x)
10271 return true
10272 }
Keith Randalla347ab72015-10-26 21:49:31 -070010273 // match: (Sub16 x x)
10274 // cond:
10275 // result: (Const16 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +010010276 for {
Keith Randalla347ab72015-10-26 21:49:31 -070010277 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -070010278 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010279 break
Keith Randalla347ab72015-10-26 21:49:31 -070010280 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010281 v.reset(OpConst16)
Keith Randalla347ab72015-10-26 21:49:31 -070010282 v.AuxInt = 0
10283 return true
10284 }
Keith Randall170589e2015-11-09 20:54:34 -080010285 // match: (Sub16 (Add16 x y) x)
10286 // cond:
10287 // result: y
Alexandru Moșoi05434472016-02-04 19:52:10 +010010288 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010289 v_0 := v.Args[0]
10290 if v_0.Op != OpAdd16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010291 break
Keith Randall170589e2015-11-09 20:54:34 -080010292 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010293 x := v_0.Args[0]
10294 y := v_0.Args[1]
10295 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010296 break
Keith Randall170589e2015-11-09 20:54:34 -080010297 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010298 v.reset(OpCopy)
Keith Randall170589e2015-11-09 20:54:34 -080010299 v.Type = y.Type
10300 v.AddArg(y)
10301 return true
10302 }
Keith Randall170589e2015-11-09 20:54:34 -080010303 // match: (Sub16 (Add16 x y) y)
10304 // cond:
10305 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +010010306 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010307 v_0 := v.Args[0]
10308 if v_0.Op != OpAdd16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010309 break
Keith Randall170589e2015-11-09 20:54:34 -080010310 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010311 x := v_0.Args[0]
10312 y := v_0.Args[1]
10313 if y != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010314 break
Keith Randall170589e2015-11-09 20:54:34 -080010315 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010316 v.reset(OpCopy)
Keith Randall170589e2015-11-09 20:54:34 -080010317 v.Type = x.Type
10318 v.AddArg(x)
10319 return true
10320 }
Keith Randalla347ab72015-10-26 21:49:31 -070010321 return false
10322}
10323func rewriteValuegeneric_OpSub32(v *Value, config *Config) bool {
10324 b := v.Block
10325 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -070010326 // match: (Sub32 (Const32 [c]) (Const32 [d]))
Keith Randall582baae2015-11-02 21:28:13 -080010327 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -070010328 // result: (Const32 [int64(int32(c-d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +010010329 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010330 v_0 := v.Args[0]
10331 if v_0.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010332 break
Keith Randall582baae2015-11-02 21:28:13 -080010333 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010334 c := v_0.AuxInt
10335 v_1 := v.Args[1]
10336 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010337 break
Keith Randall582baae2015-11-02 21:28:13 -080010338 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010339 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010340 v.reset(OpConst32)
Keith Randall7fc56212016-03-29 16:39:53 -070010341 v.AuxInt = int64(int32(c - d))
Keith Randall582baae2015-11-02 21:28:13 -080010342 return true
10343 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010344 // match: (Sub32 x (Const32 <t> [c]))
10345 // cond: x.Op != OpConst32
Keith Randall7fc56212016-03-29 16:39:53 -070010346 // result: (Add32 (Const32 <t> [int64(int32(-c))]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +010010347 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010348 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -070010349 v_1 := v.Args[1]
10350 if v_1.Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010351 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010352 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010353 t := v_1.Type
10354 c := v_1.AuxInt
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010355 if !(x.Op != OpConst32) {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010356 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010357 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010358 v.reset(OpAdd32)
Todd Neal93a0b0f2016-02-03 06:21:24 -050010359 v0 := b.NewValue0(v.Line, OpConst32, t)
Keith Randall7fc56212016-03-29 16:39:53 -070010360 v0.AuxInt = int64(int32(-c))
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010361 v.AddArg(v0)
10362 v.AddArg(x)
10363 return true
10364 }
Keith Randalla347ab72015-10-26 21:49:31 -070010365 // match: (Sub32 x x)
10366 // cond:
10367 // result: (Const32 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +010010368 for {
Keith Randalla347ab72015-10-26 21:49:31 -070010369 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -070010370 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010371 break
Keith Randalla347ab72015-10-26 21:49:31 -070010372 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010373 v.reset(OpConst32)
Keith Randalla347ab72015-10-26 21:49:31 -070010374 v.AuxInt = 0
10375 return true
10376 }
Keith Randall170589e2015-11-09 20:54:34 -080010377 // match: (Sub32 (Add32 x y) x)
10378 // cond:
10379 // result: y
Alexandru Moșoi05434472016-02-04 19:52:10 +010010380 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010381 v_0 := v.Args[0]
10382 if v_0.Op != OpAdd32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010383 break
Keith Randall170589e2015-11-09 20:54:34 -080010384 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010385 x := v_0.Args[0]
10386 y := v_0.Args[1]
10387 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010388 break
Keith Randall170589e2015-11-09 20:54:34 -080010389 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010390 v.reset(OpCopy)
Keith Randall170589e2015-11-09 20:54:34 -080010391 v.Type = y.Type
10392 v.AddArg(y)
10393 return true
10394 }
Keith Randall170589e2015-11-09 20:54:34 -080010395 // match: (Sub32 (Add32 x y) y)
10396 // cond:
10397 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +010010398 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010399 v_0 := v.Args[0]
10400 if v_0.Op != OpAdd32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010401 break
Keith Randall170589e2015-11-09 20:54:34 -080010402 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010403 x := v_0.Args[0]
10404 y := v_0.Args[1]
10405 if y != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010406 break
Keith Randall170589e2015-11-09 20:54:34 -080010407 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010408 v.reset(OpCopy)
Keith Randall170589e2015-11-09 20:54:34 -080010409 v.Type = x.Type
10410 v.AddArg(x)
10411 return true
10412 }
Keith Randalla347ab72015-10-26 21:49:31 -070010413 return false
10414}
Todd Nealf6ceed22016-03-11 19:36:54 -060010415func rewriteValuegeneric_OpSub32F(v *Value, config *Config) bool {
10416 b := v.Block
10417 _ = b
10418 // match: (Sub32F (Const32F [c]) (Const32F [d]))
10419 // cond:
10420 // result: (Const32F [f2i(float64(i2f32(c) - i2f32(d)))])
10421 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010422 v_0 := v.Args[0]
10423 if v_0.Op != OpConst32F {
Todd Nealf6ceed22016-03-11 19:36:54 -060010424 break
10425 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010426 c := v_0.AuxInt
10427 v_1 := v.Args[1]
10428 if v_1.Op != OpConst32F {
Todd Nealf6ceed22016-03-11 19:36:54 -060010429 break
10430 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010431 d := v_1.AuxInt
Todd Nealf6ceed22016-03-11 19:36:54 -060010432 v.reset(OpConst32F)
10433 v.AuxInt = f2i(float64(i2f32(c) - i2f32(d)))
10434 return true
10435 }
Cherry Zhang7d70f842016-07-06 10:04:45 -040010436 // match: (Sub32F x (Const32F [0]))
10437 // cond:
10438 // result: x
10439 for {
10440 x := v.Args[0]
10441 v_1 := v.Args[1]
10442 if v_1.Op != OpConst32F {
10443 break
10444 }
10445 if v_1.AuxInt != 0 {
10446 break
10447 }
10448 v.reset(OpCopy)
10449 v.Type = x.Type
10450 v.AddArg(x)
10451 return true
10452 }
Todd Nealf6ceed22016-03-11 19:36:54 -060010453 return false
10454}
Keith Randalla347ab72015-10-26 21:49:31 -070010455func rewriteValuegeneric_OpSub64(v *Value, config *Config) bool {
10456 b := v.Block
10457 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -070010458 // match: (Sub64 (Const64 [c]) (Const64 [d]))
Keith Randall582baae2015-11-02 21:28:13 -080010459 // cond:
10460 // result: (Const64 [c-d])
Alexandru Moșoi05434472016-02-04 19:52:10 +010010461 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010462 v_0 := v.Args[0]
10463 if v_0.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010464 break
Keith Randall582baae2015-11-02 21:28:13 -080010465 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010466 c := v_0.AuxInt
10467 v_1 := v.Args[1]
10468 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010469 break
Keith Randall582baae2015-11-02 21:28:13 -080010470 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010471 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010472 v.reset(OpConst64)
Keith Randall582baae2015-11-02 21:28:13 -080010473 v.AuxInt = c - d
10474 return true
10475 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010476 // match: (Sub64 x (Const64 <t> [c]))
10477 // cond: x.Op != OpConst64
10478 // result: (Add64 (Const64 <t> [-c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +010010479 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010480 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -070010481 v_1 := v.Args[1]
10482 if v_1.Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010483 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010484 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010485 t := v_1.Type
10486 c := v_1.AuxInt
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010487 if !(x.Op != OpConst64) {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010488 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010489 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010490 v.reset(OpAdd64)
Todd Neal93a0b0f2016-02-03 06:21:24 -050010491 v0 := b.NewValue0(v.Line, OpConst64, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010492 v0.AuxInt = -c
10493 v.AddArg(v0)
10494 v.AddArg(x)
10495 return true
10496 }
Keith Randalla347ab72015-10-26 21:49:31 -070010497 // match: (Sub64 x x)
10498 // cond:
10499 // result: (Const64 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +010010500 for {
Keith Randalla347ab72015-10-26 21:49:31 -070010501 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -070010502 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010503 break
Keith Randalla347ab72015-10-26 21:49:31 -070010504 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010505 v.reset(OpConst64)
Keith Randalla347ab72015-10-26 21:49:31 -070010506 v.AuxInt = 0
10507 return true
10508 }
Keith Randall170589e2015-11-09 20:54:34 -080010509 // match: (Sub64 (Add64 x y) x)
10510 // cond:
10511 // result: y
Alexandru Moșoi05434472016-02-04 19:52:10 +010010512 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010513 v_0 := v.Args[0]
10514 if v_0.Op != OpAdd64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010515 break
Keith Randall170589e2015-11-09 20:54:34 -080010516 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010517 x := v_0.Args[0]
10518 y := v_0.Args[1]
10519 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010520 break
Keith Randall170589e2015-11-09 20:54:34 -080010521 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010522 v.reset(OpCopy)
Keith Randall170589e2015-11-09 20:54:34 -080010523 v.Type = y.Type
10524 v.AddArg(y)
10525 return true
10526 }
Keith Randall170589e2015-11-09 20:54:34 -080010527 // match: (Sub64 (Add64 x y) y)
10528 // cond:
10529 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +010010530 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010531 v_0 := v.Args[0]
10532 if v_0.Op != OpAdd64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010533 break
Keith Randall170589e2015-11-09 20:54:34 -080010534 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010535 x := v_0.Args[0]
10536 y := v_0.Args[1]
10537 if y != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010538 break
Keith Randall170589e2015-11-09 20:54:34 -080010539 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010540 v.reset(OpCopy)
Keith Randall170589e2015-11-09 20:54:34 -080010541 v.Type = x.Type
10542 v.AddArg(x)
10543 return true
10544 }
Keith Randalla347ab72015-10-26 21:49:31 -070010545 return false
10546}
Todd Nealf6ceed22016-03-11 19:36:54 -060010547func rewriteValuegeneric_OpSub64F(v *Value, config *Config) bool {
10548 b := v.Block
10549 _ = b
10550 // match: (Sub64F (Const64F [c]) (Const64F [d]))
10551 // cond:
10552 // result: (Const64F [f2i(i2f(c) - i2f(d))])
10553 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010554 v_0 := v.Args[0]
10555 if v_0.Op != OpConst64F {
Todd Nealf6ceed22016-03-11 19:36:54 -060010556 break
10557 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010558 c := v_0.AuxInt
10559 v_1 := v.Args[1]
10560 if v_1.Op != OpConst64F {
Todd Nealf6ceed22016-03-11 19:36:54 -060010561 break
10562 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010563 d := v_1.AuxInt
Todd Nealf6ceed22016-03-11 19:36:54 -060010564 v.reset(OpConst64F)
10565 v.AuxInt = f2i(i2f(c) - i2f(d))
10566 return true
10567 }
Cherry Zhang7d70f842016-07-06 10:04:45 -040010568 // match: (Sub64F x (Const64F [0]))
10569 // cond:
10570 // result: x
10571 for {
10572 x := v.Args[0]
10573 v_1 := v.Args[1]
10574 if v_1.Op != OpConst64F {
10575 break
10576 }
10577 if v_1.AuxInt != 0 {
10578 break
10579 }
10580 v.reset(OpCopy)
10581 v.Type = x.Type
10582 v.AddArg(x)
10583 return true
10584 }
Todd Nealf6ceed22016-03-11 19:36:54 -060010585 return false
10586}
Keith Randalla347ab72015-10-26 21:49:31 -070010587func rewriteValuegeneric_OpSub8(v *Value, config *Config) bool {
10588 b := v.Block
10589 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -070010590 // match: (Sub8 (Const8 [c]) (Const8 [d]))
Keith Randall582baae2015-11-02 21:28:13 -080010591 // cond:
Keith Randall7fc56212016-03-29 16:39:53 -070010592 // result: (Const8 [int64(int8(c-d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +010010593 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010594 v_0 := v.Args[0]
10595 if v_0.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010596 break
Keith Randall582baae2015-11-02 21:28:13 -080010597 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010598 c := v_0.AuxInt
10599 v_1 := v.Args[1]
10600 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010601 break
Keith Randall582baae2015-11-02 21:28:13 -080010602 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010603 d := v_1.AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010604 v.reset(OpConst8)
Keith Randall7fc56212016-03-29 16:39:53 -070010605 v.AuxInt = int64(int8(c - d))
Keith Randall582baae2015-11-02 21:28:13 -080010606 return true
10607 }
Keith Randallfa9435c2016-04-26 12:08:31 -070010608 // match: (Sub8 x (Const8 <t> [c]))
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010609 // cond: x.Op != OpConst8
Keith Randallfa9435c2016-04-26 12:08:31 -070010610 // result: (Add8 (Const8 <t> [int64(int8(-c))]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +010010611 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010612 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -070010613 v_1 := v.Args[1]
10614 if v_1.Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010615 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010616 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010617 t := v_1.Type
10618 c := v_1.AuxInt
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010619 if !(x.Op != OpConst8) {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010620 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010621 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010622 v.reset(OpAdd8)
Todd Neal93a0b0f2016-02-03 06:21:24 -050010623 v0 := b.NewValue0(v.Line, OpConst8, t)
Keith Randall7fc56212016-03-29 16:39:53 -070010624 v0.AuxInt = int64(int8(-c))
Alexandru Moșoid4a95e72016-02-03 19:43:46 +010010625 v.AddArg(v0)
10626 v.AddArg(x)
10627 return true
10628 }
Keith Randallfa9435c2016-04-26 12:08:31 -070010629 // match: (Sub8 x x)
Keith Randalla347ab72015-10-26 21:49:31 -070010630 // cond:
Keith Randallfa9435c2016-04-26 12:08:31 -070010631 // result: (Const8 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +010010632 for {
Keith Randalla347ab72015-10-26 21:49:31 -070010633 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -070010634 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010635 break
Keith Randalla347ab72015-10-26 21:49:31 -070010636 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010637 v.reset(OpConst8)
Keith Randalla347ab72015-10-26 21:49:31 -070010638 v.AuxInt = 0
10639 return true
10640 }
Keith Randallfa9435c2016-04-26 12:08:31 -070010641 // match: (Sub8 (Add8 x y) x)
Keith Randall170589e2015-11-09 20:54:34 -080010642 // cond:
10643 // result: y
Alexandru Moșoi05434472016-02-04 19:52:10 +010010644 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010645 v_0 := v.Args[0]
10646 if v_0.Op != OpAdd8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010647 break
Keith Randall170589e2015-11-09 20:54:34 -080010648 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010649 x := v_0.Args[0]
10650 y := v_0.Args[1]
10651 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010652 break
Keith Randall170589e2015-11-09 20:54:34 -080010653 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010654 v.reset(OpCopy)
Keith Randall170589e2015-11-09 20:54:34 -080010655 v.Type = y.Type
10656 v.AddArg(y)
10657 return true
10658 }
Keith Randallfa9435c2016-04-26 12:08:31 -070010659 // match: (Sub8 (Add8 x y) y)
Keith Randall170589e2015-11-09 20:54:34 -080010660 // cond:
10661 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +010010662 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010663 v_0 := v.Args[0]
10664 if v_0.Op != OpAdd8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010665 break
Keith Randall170589e2015-11-09 20:54:34 -080010666 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010667 x := v_0.Args[0]
10668 y := v_0.Args[1]
10669 if y != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +010010670 break
Keith Randall170589e2015-11-09 20:54:34 -080010671 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010010672 v.reset(OpCopy)
Keith Randall170589e2015-11-09 20:54:34 -080010673 v.Type = x.Type
10674 v.AddArg(x)
10675 return true
10676 }
Keith Randalla347ab72015-10-26 21:49:31 -070010677 return false
10678}
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010010679func rewriteValuegeneric_OpTrunc16to8(v *Value, config *Config) bool {
10680 b := v.Block
10681 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -070010682 // match: (Trunc16to8 (Const16 [c]))
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010010683 // cond:
Keith Randallfa9435c2016-04-26 12:08:31 -070010684 // result: (Const8 [int64(int8(c))])
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010010685 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010686 v_0 := v.Args[0]
10687 if v_0.Op != OpConst16 {
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010010688 break
10689 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010690 c := v_0.AuxInt
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010010691 v.reset(OpConst8)
10692 v.AuxInt = int64(int8(c))
10693 return true
10694 }
Josh Bleecher Snyder5c3edc42016-08-30 09:57:48 -070010695 // match: (Trunc16to8 (ZeroExt8to16 x))
10696 // cond:
10697 // result: x
10698 for {
10699 v_0 := v.Args[0]
10700 if v_0.Op != OpZeroExt8to16 {
10701 break
10702 }
10703 x := v_0.Args[0]
10704 v.reset(OpCopy)
10705 v.Type = x.Type
10706 v.AddArg(x)
10707 return true
10708 }
10709 // match: (Trunc16to8 (SignExt8to16 x))
10710 // cond:
10711 // result: x
10712 for {
10713 v_0 := v.Args[0]
10714 if v_0.Op != OpSignExt8to16 {
10715 break
10716 }
10717 x := v_0.Args[0]
10718 v.reset(OpCopy)
10719 v.Type = x.Type
10720 v.AddArg(x)
10721 return true
10722 }
Keith Randallfa9435c2016-04-26 12:08:31 -070010723 // match: (Trunc16to8 (And16 (Const16 [y]) x))
David Chase97b22952016-03-02 15:49:55 -050010724 // cond: y&0xFF == 0xFF
10725 // result: (Trunc16to8 x)
10726 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010727 v_0 := v.Args[0]
10728 if v_0.Op != OpAnd16 {
David Chase97b22952016-03-02 15:49:55 -050010729 break
10730 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010731 v_0_0 := v_0.Args[0]
10732 if v_0_0.Op != OpConst16 {
David Chase97b22952016-03-02 15:49:55 -050010733 break
10734 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010735 y := v_0_0.AuxInt
10736 x := v_0.Args[1]
David Chase97b22952016-03-02 15:49:55 -050010737 if !(y&0xFF == 0xFF) {
10738 break
10739 }
10740 v.reset(OpTrunc16to8)
10741 v.AddArg(x)
10742 return true
10743 }
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010010744 return false
10745}
10746func rewriteValuegeneric_OpTrunc32to16(v *Value, config *Config) bool {
10747 b := v.Block
10748 _ = b
10749 // match: (Trunc32to16 (Const32 [c]))
10750 // cond:
Keith Randallfa9435c2016-04-26 12:08:31 -070010751 // result: (Const16 [int64(int16(c))])
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010010752 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010753 v_0 := v.Args[0]
10754 if v_0.Op != OpConst32 {
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010010755 break
10756 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010757 c := v_0.AuxInt
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010010758 v.reset(OpConst16)
10759 v.AuxInt = int64(int16(c))
10760 return true
10761 }
Josh Bleecher Snyder5c3edc42016-08-30 09:57:48 -070010762 // match: (Trunc32to16 (ZeroExt8to32 x))
10763 // cond:
10764 // result: (ZeroExt8to16 x)
10765 for {
10766 v_0 := v.Args[0]
10767 if v_0.Op != OpZeroExt8to32 {
10768 break
10769 }
10770 x := v_0.Args[0]
10771 v.reset(OpZeroExt8to16)
10772 v.AddArg(x)
10773 return true
10774 }
10775 // match: (Trunc32to16 (ZeroExt16to32 x))
10776 // cond:
10777 // result: x
10778 for {
10779 v_0 := v.Args[0]
10780 if v_0.Op != OpZeroExt16to32 {
10781 break
10782 }
10783 x := v_0.Args[0]
10784 v.reset(OpCopy)
10785 v.Type = x.Type
10786 v.AddArg(x)
10787 return true
10788 }
10789 // match: (Trunc32to16 (SignExt8to32 x))
10790 // cond:
10791 // result: (SignExt8to16 x)
10792 for {
10793 v_0 := v.Args[0]
10794 if v_0.Op != OpSignExt8to32 {
10795 break
10796 }
10797 x := v_0.Args[0]
10798 v.reset(OpSignExt8to16)
10799 v.AddArg(x)
10800 return true
10801 }
10802 // match: (Trunc32to16 (SignExt16to32 x))
10803 // cond:
10804 // result: x
10805 for {
10806 v_0 := v.Args[0]
10807 if v_0.Op != OpSignExt16to32 {
10808 break
10809 }
10810 x := v_0.Args[0]
10811 v.reset(OpCopy)
10812 v.Type = x.Type
10813 v.AddArg(x)
10814 return true
10815 }
David Chase97b22952016-03-02 15:49:55 -050010816 // match: (Trunc32to16 (And32 (Const32 [y]) x))
10817 // cond: y&0xFFFF == 0xFFFF
10818 // result: (Trunc32to16 x)
10819 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010820 v_0 := v.Args[0]
10821 if v_0.Op != OpAnd32 {
David Chase97b22952016-03-02 15:49:55 -050010822 break
10823 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010824 v_0_0 := v_0.Args[0]
10825 if v_0_0.Op != OpConst32 {
David Chase97b22952016-03-02 15:49:55 -050010826 break
10827 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010828 y := v_0_0.AuxInt
10829 x := v_0.Args[1]
David Chase97b22952016-03-02 15:49:55 -050010830 if !(y&0xFFFF == 0xFFFF) {
10831 break
10832 }
10833 v.reset(OpTrunc32to16)
10834 v.AddArg(x)
10835 return true
10836 }
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010010837 return false
10838}
10839func rewriteValuegeneric_OpTrunc32to8(v *Value, config *Config) bool {
10840 b := v.Block
10841 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -070010842 // match: (Trunc32to8 (Const32 [c]))
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010010843 // cond:
Keith Randallfa9435c2016-04-26 12:08:31 -070010844 // result: (Const8 [int64(int8(c))])
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010010845 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010846 v_0 := v.Args[0]
10847 if v_0.Op != OpConst32 {
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010010848 break
10849 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010850 c := v_0.AuxInt
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010010851 v.reset(OpConst8)
10852 v.AuxInt = int64(int8(c))
10853 return true
10854 }
Josh Bleecher Snyder5c3edc42016-08-30 09:57:48 -070010855 // match: (Trunc32to8 (ZeroExt8to32 x))
10856 // cond:
10857 // result: x
10858 for {
10859 v_0 := v.Args[0]
10860 if v_0.Op != OpZeroExt8to32 {
10861 break
10862 }
10863 x := v_0.Args[0]
10864 v.reset(OpCopy)
10865 v.Type = x.Type
10866 v.AddArg(x)
10867 return true
10868 }
10869 // match: (Trunc32to8 (SignExt8to32 x))
10870 // cond:
10871 // result: x
10872 for {
10873 v_0 := v.Args[0]
10874 if v_0.Op != OpSignExt8to32 {
10875 break
10876 }
10877 x := v_0.Args[0]
10878 v.reset(OpCopy)
10879 v.Type = x.Type
10880 v.AddArg(x)
10881 return true
10882 }
Keith Randallfa9435c2016-04-26 12:08:31 -070010883 // match: (Trunc32to8 (And32 (Const32 [y]) x))
David Chase97b22952016-03-02 15:49:55 -050010884 // cond: y&0xFF == 0xFF
10885 // result: (Trunc32to8 x)
10886 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010887 v_0 := v.Args[0]
10888 if v_0.Op != OpAnd32 {
David Chase97b22952016-03-02 15:49:55 -050010889 break
10890 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010891 v_0_0 := v_0.Args[0]
10892 if v_0_0.Op != OpConst32 {
David Chase97b22952016-03-02 15:49:55 -050010893 break
10894 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010895 y := v_0_0.AuxInt
10896 x := v_0.Args[1]
David Chase97b22952016-03-02 15:49:55 -050010897 if !(y&0xFF == 0xFF) {
10898 break
10899 }
10900 v.reset(OpTrunc32to8)
10901 v.AddArg(x)
10902 return true
10903 }
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010010904 return false
10905}
10906func rewriteValuegeneric_OpTrunc64to16(v *Value, config *Config) bool {
10907 b := v.Block
10908 _ = b
10909 // match: (Trunc64to16 (Const64 [c]))
10910 // cond:
Keith Randallfa9435c2016-04-26 12:08:31 -070010911 // result: (Const16 [int64(int16(c))])
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010010912 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010913 v_0 := v.Args[0]
10914 if v_0.Op != OpConst64 {
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010010915 break
10916 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010917 c := v_0.AuxInt
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010010918 v.reset(OpConst16)
10919 v.AuxInt = int64(int16(c))
10920 return true
10921 }
Josh Bleecher Snyder5c3edc42016-08-30 09:57:48 -070010922 // match: (Trunc64to16 (ZeroExt8to64 x))
10923 // cond:
10924 // result: (ZeroExt8to16 x)
10925 for {
10926 v_0 := v.Args[0]
10927 if v_0.Op != OpZeroExt8to64 {
10928 break
10929 }
10930 x := v_0.Args[0]
10931 v.reset(OpZeroExt8to16)
10932 v.AddArg(x)
10933 return true
10934 }
10935 // match: (Trunc64to16 (ZeroExt16to64 x))
10936 // cond:
10937 // result: x
10938 for {
10939 v_0 := v.Args[0]
10940 if v_0.Op != OpZeroExt16to64 {
10941 break
10942 }
10943 x := v_0.Args[0]
10944 v.reset(OpCopy)
10945 v.Type = x.Type
10946 v.AddArg(x)
10947 return true
10948 }
10949 // match: (Trunc64to16 (SignExt8to64 x))
10950 // cond:
10951 // result: (SignExt8to16 x)
10952 for {
10953 v_0 := v.Args[0]
10954 if v_0.Op != OpSignExt8to64 {
10955 break
10956 }
10957 x := v_0.Args[0]
10958 v.reset(OpSignExt8to16)
10959 v.AddArg(x)
10960 return true
10961 }
10962 // match: (Trunc64to16 (SignExt16to64 x))
10963 // cond:
10964 // result: x
10965 for {
10966 v_0 := v.Args[0]
10967 if v_0.Op != OpSignExt16to64 {
10968 break
10969 }
10970 x := v_0.Args[0]
10971 v.reset(OpCopy)
10972 v.Type = x.Type
10973 v.AddArg(x)
10974 return true
10975 }
David Chase97b22952016-03-02 15:49:55 -050010976 // match: (Trunc64to16 (And64 (Const64 [y]) x))
10977 // cond: y&0xFFFF == 0xFFFF
10978 // result: (Trunc64to16 x)
10979 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070010980 v_0 := v.Args[0]
10981 if v_0.Op != OpAnd64 {
David Chase97b22952016-03-02 15:49:55 -050010982 break
10983 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010984 v_0_0 := v_0.Args[0]
10985 if v_0_0.Op != OpConst64 {
David Chase97b22952016-03-02 15:49:55 -050010986 break
10987 }
Keith Randall259b7ed2016-03-21 16:18:45 -070010988 y := v_0_0.AuxInt
10989 x := v_0.Args[1]
David Chase97b22952016-03-02 15:49:55 -050010990 if !(y&0xFFFF == 0xFFFF) {
10991 break
10992 }
10993 v.reset(OpTrunc64to16)
10994 v.AddArg(x)
10995 return true
10996 }
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010010997 return false
10998}
10999func rewriteValuegeneric_OpTrunc64to32(v *Value, config *Config) bool {
11000 b := v.Block
11001 _ = b
11002 // match: (Trunc64to32 (Const64 [c]))
11003 // cond:
Keith Randallfa9435c2016-04-26 12:08:31 -070011004 // result: (Const32 [int64(int32(c))])
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010011005 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070011006 v_0 := v.Args[0]
11007 if v_0.Op != OpConst64 {
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010011008 break
11009 }
Keith Randall259b7ed2016-03-21 16:18:45 -070011010 c := v_0.AuxInt
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010011011 v.reset(OpConst32)
11012 v.AuxInt = int64(int32(c))
11013 return true
11014 }
Josh Bleecher Snyder5c3edc42016-08-30 09:57:48 -070011015 // match: (Trunc64to32 (ZeroExt8to64 x))
11016 // cond:
11017 // result: (ZeroExt8to32 x)
11018 for {
11019 v_0 := v.Args[0]
11020 if v_0.Op != OpZeroExt8to64 {
11021 break
11022 }
11023 x := v_0.Args[0]
11024 v.reset(OpZeroExt8to32)
11025 v.AddArg(x)
11026 return true
11027 }
11028 // match: (Trunc64to32 (ZeroExt16to64 x))
11029 // cond:
11030 // result: (ZeroExt16to32 x)
11031 for {
11032 v_0 := v.Args[0]
11033 if v_0.Op != OpZeroExt16to64 {
11034 break
11035 }
11036 x := v_0.Args[0]
11037 v.reset(OpZeroExt16to32)
11038 v.AddArg(x)
11039 return true
11040 }
11041 // match: (Trunc64to32 (ZeroExt32to64 x))
11042 // cond:
11043 // result: x
11044 for {
11045 v_0 := v.Args[0]
11046 if v_0.Op != OpZeroExt32to64 {
11047 break
11048 }
11049 x := v_0.Args[0]
11050 v.reset(OpCopy)
11051 v.Type = x.Type
11052 v.AddArg(x)
11053 return true
11054 }
11055 // match: (Trunc64to32 (SignExt8to64 x))
11056 // cond:
11057 // result: (SignExt8to32 x)
11058 for {
11059 v_0 := v.Args[0]
11060 if v_0.Op != OpSignExt8to64 {
11061 break
11062 }
11063 x := v_0.Args[0]
11064 v.reset(OpSignExt8to32)
11065 v.AddArg(x)
11066 return true
11067 }
11068 // match: (Trunc64to32 (SignExt16to64 x))
11069 // cond:
11070 // result: (SignExt16to32 x)
11071 for {
11072 v_0 := v.Args[0]
11073 if v_0.Op != OpSignExt16to64 {
11074 break
11075 }
11076 x := v_0.Args[0]
11077 v.reset(OpSignExt16to32)
11078 v.AddArg(x)
11079 return true
11080 }
11081 // match: (Trunc64to32 (SignExt32to64 x))
11082 // cond:
11083 // result: x
11084 for {
11085 v_0 := v.Args[0]
11086 if v_0.Op != OpSignExt32to64 {
11087 break
11088 }
11089 x := v_0.Args[0]
11090 v.reset(OpCopy)
11091 v.Type = x.Type
11092 v.AddArg(x)
11093 return true
11094 }
David Chase97b22952016-03-02 15:49:55 -050011095 // match: (Trunc64to32 (And64 (Const64 [y]) x))
11096 // cond: y&0xFFFFFFFF == 0xFFFFFFFF
11097 // result: (Trunc64to32 x)
11098 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070011099 v_0 := v.Args[0]
11100 if v_0.Op != OpAnd64 {
David Chase97b22952016-03-02 15:49:55 -050011101 break
11102 }
Keith Randall259b7ed2016-03-21 16:18:45 -070011103 v_0_0 := v_0.Args[0]
11104 if v_0_0.Op != OpConst64 {
David Chase97b22952016-03-02 15:49:55 -050011105 break
11106 }
Keith Randall259b7ed2016-03-21 16:18:45 -070011107 y := v_0_0.AuxInt
11108 x := v_0.Args[1]
David Chase97b22952016-03-02 15:49:55 -050011109 if !(y&0xFFFFFFFF == 0xFFFFFFFF) {
11110 break
11111 }
11112 v.reset(OpTrunc64to32)
11113 v.AddArg(x)
11114 return true
11115 }
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010011116 return false
11117}
11118func rewriteValuegeneric_OpTrunc64to8(v *Value, config *Config) bool {
11119 b := v.Block
11120 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -070011121 // match: (Trunc64to8 (Const64 [c]))
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010011122 // cond:
Keith Randallfa9435c2016-04-26 12:08:31 -070011123 // result: (Const8 [int64(int8(c))])
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010011124 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070011125 v_0 := v.Args[0]
11126 if v_0.Op != OpConst64 {
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010011127 break
11128 }
Keith Randall259b7ed2016-03-21 16:18:45 -070011129 c := v_0.AuxInt
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010011130 v.reset(OpConst8)
11131 v.AuxInt = int64(int8(c))
11132 return true
11133 }
Josh Bleecher Snyder5c3edc42016-08-30 09:57:48 -070011134 // match: (Trunc64to8 (ZeroExt8to64 x))
11135 // cond:
11136 // result: x
11137 for {
11138 v_0 := v.Args[0]
11139 if v_0.Op != OpZeroExt8to64 {
11140 break
11141 }
11142 x := v_0.Args[0]
11143 v.reset(OpCopy)
11144 v.Type = x.Type
11145 v.AddArg(x)
11146 return true
11147 }
11148 // match: (Trunc64to8 (SignExt8to64 x))
11149 // cond:
11150 // result: x
11151 for {
11152 v_0 := v.Args[0]
11153 if v_0.Op != OpSignExt8to64 {
11154 break
11155 }
11156 x := v_0.Args[0]
11157 v.reset(OpCopy)
11158 v.Type = x.Type
11159 v.AddArg(x)
11160 return true
11161 }
Keith Randallfa9435c2016-04-26 12:08:31 -070011162 // match: (Trunc64to8 (And64 (Const64 [y]) x))
David Chase97b22952016-03-02 15:49:55 -050011163 // cond: y&0xFF == 0xFF
11164 // result: (Trunc64to8 x)
11165 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070011166 v_0 := v.Args[0]
11167 if v_0.Op != OpAnd64 {
David Chase97b22952016-03-02 15:49:55 -050011168 break
11169 }
Keith Randall259b7ed2016-03-21 16:18:45 -070011170 v_0_0 := v_0.Args[0]
11171 if v_0_0.Op != OpConst64 {
David Chase97b22952016-03-02 15:49:55 -050011172 break
11173 }
Keith Randall259b7ed2016-03-21 16:18:45 -070011174 y := v_0_0.AuxInt
11175 x := v_0.Args[1]
David Chase97b22952016-03-02 15:49:55 -050011176 if !(y&0xFF == 0xFF) {
11177 break
11178 }
11179 v.reset(OpTrunc64to8)
11180 v.AddArg(x)
11181 return true
11182 }
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +010011183 return false
11184}
Keith Randalla347ab72015-10-26 21:49:31 -070011185func rewriteValuegeneric_OpXor16(v *Value, config *Config) bool {
11186 b := v.Block
11187 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011188 // match: (Xor16 x (Const16 <t> [c]))
11189 // cond: x.Op != OpConst16
11190 // result: (Xor16 (Const16 <t> [c]) x)
11191 for {
11192 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -070011193 v_1 := v.Args[1]
11194 if v_1.Op != OpConst16 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011195 break
11196 }
Keith Randall259b7ed2016-03-21 16:18:45 -070011197 t := v_1.Type
11198 c := v_1.AuxInt
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011199 if !(x.Op != OpConst16) {
11200 break
11201 }
11202 v.reset(OpXor16)
11203 v0 := b.NewValue0(v.Line, OpConst16, t)
11204 v0.AuxInt = c
11205 v.AddArg(v0)
11206 v.AddArg(x)
11207 return true
11208 }
Keith Randalla347ab72015-10-26 21:49:31 -070011209 // match: (Xor16 x x)
11210 // cond:
11211 // result: (Const16 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +010011212 for {
Keith Randalla347ab72015-10-26 21:49:31 -070011213 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -070011214 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +010011215 break
Keith Randalla347ab72015-10-26 21:49:31 -070011216 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010011217 v.reset(OpConst16)
Keith Randalla347ab72015-10-26 21:49:31 -070011218 v.AuxInt = 0
11219 return true
11220 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011221 // match: (Xor16 (Const16 [0]) x)
11222 // cond:
11223 // result: x
11224 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070011225 v_0 := v.Args[0]
11226 if v_0.Op != OpConst16 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011227 break
11228 }
Keith Randall259b7ed2016-03-21 16:18:45 -070011229 if v_0.AuxInt != 0 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011230 break
11231 }
11232 x := v.Args[1]
11233 v.reset(OpCopy)
11234 v.Type = x.Type
11235 v.AddArg(x)
11236 return true
11237 }
Keith Randall4d5adf12016-04-18 09:28:50 -070011238 // match: (Xor16 x (Xor16 x y))
11239 // cond:
11240 // result: y
11241 for {
11242 x := v.Args[0]
11243 v_1 := v.Args[1]
11244 if v_1.Op != OpXor16 {
11245 break
11246 }
11247 if x != v_1.Args[0] {
11248 break
11249 }
11250 y := v_1.Args[1]
11251 v.reset(OpCopy)
11252 v.Type = y.Type
11253 v.AddArg(y)
11254 return true
11255 }
11256 // match: (Xor16 x (Xor16 y x))
11257 // cond:
11258 // result: y
11259 for {
11260 x := v.Args[0]
11261 v_1 := v.Args[1]
11262 if v_1.Op != OpXor16 {
11263 break
11264 }
11265 y := v_1.Args[0]
11266 if x != v_1.Args[1] {
11267 break
11268 }
11269 v.reset(OpCopy)
11270 v.Type = y.Type
11271 v.AddArg(y)
11272 return true
11273 }
11274 // match: (Xor16 (Xor16 x y) x)
11275 // cond:
11276 // result: y
11277 for {
11278 v_0 := v.Args[0]
11279 if v_0.Op != OpXor16 {
11280 break
11281 }
11282 x := v_0.Args[0]
11283 y := v_0.Args[1]
11284 if x != v.Args[1] {
11285 break
11286 }
11287 v.reset(OpCopy)
11288 v.Type = y.Type
11289 v.AddArg(y)
11290 return true
11291 }
11292 // match: (Xor16 (Xor16 x y) y)
11293 // cond:
11294 // result: x
11295 for {
11296 v_0 := v.Args[0]
11297 if v_0.Op != OpXor16 {
11298 break
11299 }
11300 x := v_0.Args[0]
11301 y := v_0.Args[1]
11302 if y != v.Args[1] {
11303 break
11304 }
11305 v.reset(OpCopy)
11306 v.Type = x.Type
11307 v.AddArg(x)
11308 return true
11309 }
Keith Randalla347ab72015-10-26 21:49:31 -070011310 return false
11311}
11312func rewriteValuegeneric_OpXor32(v *Value, config *Config) bool {
11313 b := v.Block
11314 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011315 // match: (Xor32 x (Const32 <t> [c]))
11316 // cond: x.Op != OpConst32
11317 // result: (Xor32 (Const32 <t> [c]) x)
11318 for {
11319 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -070011320 v_1 := v.Args[1]
11321 if v_1.Op != OpConst32 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011322 break
11323 }
Keith Randall259b7ed2016-03-21 16:18:45 -070011324 t := v_1.Type
11325 c := v_1.AuxInt
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011326 if !(x.Op != OpConst32) {
11327 break
11328 }
11329 v.reset(OpXor32)
11330 v0 := b.NewValue0(v.Line, OpConst32, t)
11331 v0.AuxInt = c
11332 v.AddArg(v0)
11333 v.AddArg(x)
11334 return true
11335 }
Keith Randalla347ab72015-10-26 21:49:31 -070011336 // match: (Xor32 x x)
11337 // cond:
11338 // result: (Const32 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +010011339 for {
Keith Randalla347ab72015-10-26 21:49:31 -070011340 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -070011341 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +010011342 break
Keith Randalla347ab72015-10-26 21:49:31 -070011343 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010011344 v.reset(OpConst32)
Keith Randalla347ab72015-10-26 21:49:31 -070011345 v.AuxInt = 0
11346 return true
11347 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011348 // match: (Xor32 (Const32 [0]) x)
11349 // cond:
11350 // result: x
11351 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070011352 v_0 := v.Args[0]
11353 if v_0.Op != OpConst32 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011354 break
11355 }
Keith Randall259b7ed2016-03-21 16:18:45 -070011356 if v_0.AuxInt != 0 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011357 break
11358 }
11359 x := v.Args[1]
11360 v.reset(OpCopy)
11361 v.Type = x.Type
11362 v.AddArg(x)
11363 return true
11364 }
Keith Randall4d5adf12016-04-18 09:28:50 -070011365 // match: (Xor32 x (Xor32 x y))
11366 // cond:
11367 // result: y
11368 for {
11369 x := v.Args[0]
11370 v_1 := v.Args[1]
11371 if v_1.Op != OpXor32 {
11372 break
11373 }
11374 if x != v_1.Args[0] {
11375 break
11376 }
11377 y := v_1.Args[1]
11378 v.reset(OpCopy)
11379 v.Type = y.Type
11380 v.AddArg(y)
11381 return true
11382 }
11383 // match: (Xor32 x (Xor32 y x))
11384 // cond:
11385 // result: y
11386 for {
11387 x := v.Args[0]
11388 v_1 := v.Args[1]
11389 if v_1.Op != OpXor32 {
11390 break
11391 }
11392 y := v_1.Args[0]
11393 if x != v_1.Args[1] {
11394 break
11395 }
11396 v.reset(OpCopy)
11397 v.Type = y.Type
11398 v.AddArg(y)
11399 return true
11400 }
11401 // match: (Xor32 (Xor32 x y) x)
11402 // cond:
11403 // result: y
11404 for {
11405 v_0 := v.Args[0]
11406 if v_0.Op != OpXor32 {
11407 break
11408 }
11409 x := v_0.Args[0]
11410 y := v_0.Args[1]
11411 if x != v.Args[1] {
11412 break
11413 }
11414 v.reset(OpCopy)
11415 v.Type = y.Type
11416 v.AddArg(y)
11417 return true
11418 }
11419 // match: (Xor32 (Xor32 x y) y)
11420 // cond:
11421 // result: x
11422 for {
11423 v_0 := v.Args[0]
11424 if v_0.Op != OpXor32 {
11425 break
11426 }
11427 x := v_0.Args[0]
11428 y := v_0.Args[1]
11429 if y != v.Args[1] {
11430 break
11431 }
11432 v.reset(OpCopy)
11433 v.Type = x.Type
11434 v.AddArg(x)
11435 return true
11436 }
Keith Randalla347ab72015-10-26 21:49:31 -070011437 return false
11438}
11439func rewriteValuegeneric_OpXor64(v *Value, config *Config) bool {
11440 b := v.Block
11441 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011442 // match: (Xor64 x (Const64 <t> [c]))
11443 // cond: x.Op != OpConst64
11444 // result: (Xor64 (Const64 <t> [c]) x)
11445 for {
11446 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -070011447 v_1 := v.Args[1]
11448 if v_1.Op != OpConst64 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011449 break
11450 }
Keith Randall259b7ed2016-03-21 16:18:45 -070011451 t := v_1.Type
11452 c := v_1.AuxInt
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011453 if !(x.Op != OpConst64) {
11454 break
11455 }
11456 v.reset(OpXor64)
11457 v0 := b.NewValue0(v.Line, OpConst64, t)
11458 v0.AuxInt = c
11459 v.AddArg(v0)
11460 v.AddArg(x)
11461 return true
11462 }
Keith Randalla347ab72015-10-26 21:49:31 -070011463 // match: (Xor64 x x)
11464 // cond:
11465 // result: (Const64 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +010011466 for {
Keith Randalla347ab72015-10-26 21:49:31 -070011467 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -070011468 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +010011469 break
Keith Randalla347ab72015-10-26 21:49:31 -070011470 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010011471 v.reset(OpConst64)
Keith Randalla347ab72015-10-26 21:49:31 -070011472 v.AuxInt = 0
11473 return true
11474 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011475 // match: (Xor64 (Const64 [0]) x)
11476 // cond:
11477 // result: x
11478 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070011479 v_0 := v.Args[0]
11480 if v_0.Op != OpConst64 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011481 break
11482 }
Keith Randall259b7ed2016-03-21 16:18:45 -070011483 if v_0.AuxInt != 0 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011484 break
11485 }
11486 x := v.Args[1]
11487 v.reset(OpCopy)
11488 v.Type = x.Type
11489 v.AddArg(x)
11490 return true
11491 }
Keith Randall4d5adf12016-04-18 09:28:50 -070011492 // match: (Xor64 x (Xor64 x y))
11493 // cond:
11494 // result: y
11495 for {
11496 x := v.Args[0]
11497 v_1 := v.Args[1]
11498 if v_1.Op != OpXor64 {
11499 break
11500 }
11501 if x != v_1.Args[0] {
11502 break
11503 }
11504 y := v_1.Args[1]
11505 v.reset(OpCopy)
11506 v.Type = y.Type
11507 v.AddArg(y)
11508 return true
11509 }
11510 // match: (Xor64 x (Xor64 y x))
11511 // cond:
11512 // result: y
11513 for {
11514 x := v.Args[0]
11515 v_1 := v.Args[1]
11516 if v_1.Op != OpXor64 {
11517 break
11518 }
11519 y := v_1.Args[0]
11520 if x != v_1.Args[1] {
11521 break
11522 }
11523 v.reset(OpCopy)
11524 v.Type = y.Type
11525 v.AddArg(y)
11526 return true
11527 }
11528 // match: (Xor64 (Xor64 x y) x)
11529 // cond:
11530 // result: y
11531 for {
11532 v_0 := v.Args[0]
11533 if v_0.Op != OpXor64 {
11534 break
11535 }
11536 x := v_0.Args[0]
11537 y := v_0.Args[1]
11538 if x != v.Args[1] {
11539 break
11540 }
11541 v.reset(OpCopy)
11542 v.Type = y.Type
11543 v.AddArg(y)
11544 return true
11545 }
11546 // match: (Xor64 (Xor64 x y) y)
11547 // cond:
11548 // result: x
11549 for {
11550 v_0 := v.Args[0]
11551 if v_0.Op != OpXor64 {
11552 break
11553 }
11554 x := v_0.Args[0]
11555 y := v_0.Args[1]
11556 if y != v.Args[1] {
11557 break
11558 }
11559 v.reset(OpCopy)
11560 v.Type = x.Type
11561 v.AddArg(x)
11562 return true
11563 }
Keith Randalla347ab72015-10-26 21:49:31 -070011564 return false
11565}
11566func rewriteValuegeneric_OpXor8(v *Value, config *Config) bool {
11567 b := v.Block
11568 _ = b
Keith Randallfa9435c2016-04-26 12:08:31 -070011569 // match: (Xor8 x (Const8 <t> [c]))
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011570 // cond: x.Op != OpConst8
Keith Randallfa9435c2016-04-26 12:08:31 -070011571 // result: (Xor8 (Const8 <t> [c]) x)
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011572 for {
11573 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -070011574 v_1 := v.Args[1]
11575 if v_1.Op != OpConst8 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011576 break
11577 }
Keith Randall259b7ed2016-03-21 16:18:45 -070011578 t := v_1.Type
11579 c := v_1.AuxInt
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011580 if !(x.Op != OpConst8) {
11581 break
11582 }
11583 v.reset(OpXor8)
11584 v0 := b.NewValue0(v.Line, OpConst8, t)
11585 v0.AuxInt = c
11586 v.AddArg(v0)
11587 v.AddArg(x)
11588 return true
11589 }
Keith Randallfa9435c2016-04-26 12:08:31 -070011590 // match: (Xor8 x x)
Keith Randalla347ab72015-10-26 21:49:31 -070011591 // cond:
Keith Randallfa9435c2016-04-26 12:08:31 -070011592 // result: (Const8 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +010011593 for {
Keith Randalla347ab72015-10-26 21:49:31 -070011594 x := v.Args[0]
Keith Randall259b7ed2016-03-21 16:18:45 -070011595 if x != v.Args[1] {
Alexandru Moșoi05434472016-02-04 19:52:10 +010011596 break
Keith Randalla347ab72015-10-26 21:49:31 -070011597 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +010011598 v.reset(OpConst8)
Keith Randalla347ab72015-10-26 21:49:31 -070011599 v.AuxInt = 0
11600 return true
11601 }
Keith Randallfa9435c2016-04-26 12:08:31 -070011602 // match: (Xor8 (Const8 [0]) x)
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011603 // cond:
11604 // result: x
11605 for {
Keith Randall259b7ed2016-03-21 16:18:45 -070011606 v_0 := v.Args[0]
11607 if v_0.Op != OpConst8 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011608 break
11609 }
Keith Randall259b7ed2016-03-21 16:18:45 -070011610 if v_0.AuxInt != 0 {
Alexandru Moșoifd458ba2016-02-09 19:13:43 +010011611 break
11612 }
11613 x := v.Args[1]
11614 v.reset(OpCopy)
11615 v.Type = x.Type
11616 v.AddArg(x)
11617 return true
11618 }
Keith Randall4d5adf12016-04-18 09:28:50 -070011619 // match: (Xor8 x (Xor8 x y))
11620 // cond:
11621 // result: y
11622 for {
11623 x := v.Args[0]
11624 v_1 := v.Args[1]
11625 if v_1.Op != OpXor8 {
11626 break
11627 }
11628 if x != v_1.Args[0] {
11629 break
11630 }
11631 y := v_1.Args[1]
11632 v.reset(OpCopy)
11633 v.Type = y.Type
11634 v.AddArg(y)
11635 return true
11636 }
11637 // match: (Xor8 x (Xor8 y x))
11638 // cond:
11639 // result: y
11640 for {
11641 x := v.Args[0]
11642 v_1 := v.Args[1]
11643 if v_1.Op != OpXor8 {
11644 break
11645 }
11646 y := v_1.Args[0]
11647 if x != v_1.Args[1] {
11648 break
11649 }
11650 v.reset(OpCopy)
11651 v.Type = y.Type
11652 v.AddArg(y)
11653 return true
11654 }
11655 // match: (Xor8 (Xor8 x y) x)
11656 // cond:
11657 // result: y
11658 for {
11659 v_0 := v.Args[0]
11660 if v_0.Op != OpXor8 {
11661 break
11662 }
11663 x := v_0.Args[0]
11664 y := v_0.Args[1]
11665 if x != v.Args[1] {
11666 break
11667 }
11668 v.reset(OpCopy)
11669 v.Type = y.Type
11670 v.AddArg(y)
11671 return true
11672 }
11673 // match: (Xor8 (Xor8 x y) y)
11674 // cond:
11675 // result: x
11676 for {
11677 v_0 := v.Args[0]
11678 if v_0.Op != OpXor8 {
11679 break
11680 }
11681 x := v_0.Args[0]
11682 y := v_0.Args[1]
11683 if y != v.Args[1] {
11684 break
11685 }
11686 v.reset(OpCopy)
11687 v.Type = x.Type
11688 v.AddArg(x)
11689 return true
11690 }
Keith Randalla347ab72015-10-26 21:49:31 -070011691 return false
11692}
Cherry Zhangb2e0e962016-08-26 15:41:51 -040011693func rewriteValuegeneric_OpZero(v *Value, config *Config) bool {
11694 b := v.Block
11695 _ = b
Keith Randall3134ab32016-09-13 17:01:01 -070011696 // match: (Zero (Load (OffPtr [c] (SP)) mem) mem)
11697 // cond: mem.Op == OpStaticCall && isSameSym(mem.Aux, "runtime.newobject") && c == config.ctxt.FixedFrameSize() + config.PtrSize
Cherry Zhangb2e0e962016-08-26 15:41:51 -040011698 // result: mem
11699 for {
11700 v_0 := v.Args[0]
11701 if v_0.Op != OpLoad {
11702 break
11703 }
11704 v_0_0 := v_0.Args[0]
11705 if v_0_0.Op != OpOffPtr {
11706 break
11707 }
11708 c := v_0_0.AuxInt
11709 v_0_0_0 := v_0_0.Args[0]
11710 if v_0_0_0.Op != OpSP {
11711 break
11712 }
11713 mem := v_0.Args[1]
Keith Randall3134ab32016-09-13 17:01:01 -070011714 if mem != v.Args[1] {
Cherry Zhangb2e0e962016-08-26 15:41:51 -040011715 break
11716 }
Keith Randall3134ab32016-09-13 17:01:01 -070011717 if !(mem.Op == OpStaticCall && isSameSym(mem.Aux, "runtime.newobject") && c == config.ctxt.FixedFrameSize()+config.PtrSize) {
Cherry Zhangb2e0e962016-08-26 15:41:51 -040011718 break
11719 }
11720 v.reset(OpCopy)
11721 v.Type = mem.Type
11722 v.AddArg(mem)
11723 return true
11724 }
11725 return false
11726}
11727func rewriteBlockgeneric(b *Block, config *Config) bool {
Keith Randall0dca7352015-06-06 16:03:33 -070011728 switch b.Kind {
Keith Randall31115a52015-10-23 19:12:49 -070011729 case BlockIf:
Todd Neal52d76f72015-07-23 18:44:09 -050011730 // match: (If (Not cond) yes no)
11731 // cond:
11732 // result: (If cond no yes)
Alexandru Moșoi05434472016-02-04 19:52:10 +010011733 for {
Todd Neal52d76f72015-07-23 18:44:09 -050011734 v := b.Control
11735 if v.Op != OpNot {
Alexandru Moșoi05434472016-02-04 19:52:10 +010011736 break
Todd Neal52d76f72015-07-23 18:44:09 -050011737 }
11738 cond := v.Args[0]
11739 yes := b.Succs[0]
11740 no := b.Succs[1]
11741 b.Kind = BlockIf
Keith Randall56e0ecc2016-03-15 20:45:50 -070011742 b.SetControl(cond)
Keith Randall4fa05002016-04-28 16:52:47 -070011743 b.swapSuccessors()
11744 _ = no
11745 _ = yes
Todd Neal52d76f72015-07-23 18:44:09 -050011746 return true
11747 }
Todd Neal991036a2015-09-03 18:24:22 -050011748 // match: (If (ConstBool [c]) yes no)
11749 // cond: c == 1
Keith Randall186cf1b2015-08-28 16:45:17 -070011750 // result: (First nil yes no)
Alexandru Moșoi05434472016-02-04 19:52:10 +010011751 for {
Keith Randall0dca7352015-06-06 16:03:33 -070011752 v := b.Control
Keith Randall9cb332e2015-07-28 14:19:20 -070011753 if v.Op != OpConstBool {
Alexandru Moșoi05434472016-02-04 19:52:10 +010011754 break
Keith Randall0dca7352015-06-06 16:03:33 -070011755 }
Todd Neal991036a2015-09-03 18:24:22 -050011756 c := v.AuxInt
Keith Randall0dca7352015-06-06 16:03:33 -070011757 yes := b.Succs[0]
11758 no := b.Succs[1]
Todd Neal991036a2015-09-03 18:24:22 -050011759 if !(c == 1) {
Alexandru Moșoi05434472016-02-04 19:52:10 +010011760 break
Keith Randall0dca7352015-06-06 16:03:33 -070011761 }
Keith Randall186cf1b2015-08-28 16:45:17 -070011762 b.Kind = BlockFirst
Keith Randall56e0ecc2016-03-15 20:45:50 -070011763 b.SetControl(nil)
Keith Randall4fa05002016-04-28 16:52:47 -070011764 _ = yes
11765 _ = no
Keith Randall0dca7352015-06-06 16:03:33 -070011766 return true
11767 }
Todd Neal991036a2015-09-03 18:24:22 -050011768 // match: (If (ConstBool [c]) yes no)
11769 // cond: c == 0
Keith Randall186cf1b2015-08-28 16:45:17 -070011770 // result: (First nil no yes)
Alexandru Moșoi05434472016-02-04 19:52:10 +010011771 for {
Keith Randall0dca7352015-06-06 16:03:33 -070011772 v := b.Control
Keith Randall9cb332e2015-07-28 14:19:20 -070011773 if v.Op != OpConstBool {
Alexandru Moșoi05434472016-02-04 19:52:10 +010011774 break
Keith Randall0dca7352015-06-06 16:03:33 -070011775 }
Todd Neal991036a2015-09-03 18:24:22 -050011776 c := v.AuxInt
Keith Randall0dca7352015-06-06 16:03:33 -070011777 yes := b.Succs[0]
11778 no := b.Succs[1]
Todd Neal991036a2015-09-03 18:24:22 -050011779 if !(c == 0) {
Alexandru Moșoi05434472016-02-04 19:52:10 +010011780 break
Keith Randall0dca7352015-06-06 16:03:33 -070011781 }
Keith Randall186cf1b2015-08-28 16:45:17 -070011782 b.Kind = BlockFirst
Keith Randall56e0ecc2016-03-15 20:45:50 -070011783 b.SetControl(nil)
Keith Randall4fa05002016-04-28 16:52:47 -070011784 b.swapSuccessors()
11785 _ = no
11786 _ = yes
Keith Randall0dca7352015-06-06 16:03:33 -070011787 return true
11788 }
Keith Randall0dca7352015-06-06 16:03:33 -070011789 }
11790 return false
11791}