blob: 2e15daca4c69b8621f4f1f8ead5ffa218e99d9dc [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)
Keith Randall67fdb0d2015-07-19 15:48:20 -070015 case OpAdd64:
Keith Randalla347ab72015-10-26 21:49:31 -070016 return rewriteValuegeneric_OpAdd64(v, config)
Keith Randall582baae2015-11-02 21:28:13 -080017 case OpAdd8:
18 return rewriteValuegeneric_OpAdd8(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +020019 case OpAnd16:
Keith Randalla347ab72015-10-26 21:49:31 -070020 return rewriteValuegeneric_OpAnd16(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +020021 case OpAnd32:
Keith Randalla347ab72015-10-26 21:49:31 -070022 return rewriteValuegeneric_OpAnd32(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +020023 case OpAnd64:
Keith Randalla347ab72015-10-26 21:49:31 -070024 return rewriteValuegeneric_OpAnd64(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +020025 case OpAnd8:
Keith Randalla347ab72015-10-26 21:49:31 -070026 return rewriteValuegeneric_OpAnd8(v, config)
Keith Randall02f4d0a2015-11-02 08:10:26 -080027 case OpArg:
28 return rewriteValuegeneric_OpArg(v, config)
Keith Randall0dca7352015-06-06 16:03:33 -070029 case OpArrayIndex:
Keith Randalla347ab72015-10-26 21:49:31 -070030 return rewriteValuegeneric_OpArrayIndex(v, config)
Todd Neal38ed6c12015-07-30 16:02:24 -040031 case OpCom16:
Keith Randalla347ab72015-10-26 21:49:31 -070032 return rewriteValuegeneric_OpCom16(v, config)
Todd Neal38ed6c12015-07-30 16:02:24 -040033 case OpCom32:
Keith Randalla347ab72015-10-26 21:49:31 -070034 return rewriteValuegeneric_OpCom32(v, config)
Todd Neal38ed6c12015-07-30 16:02:24 -040035 case OpCom64:
Keith Randalla347ab72015-10-26 21:49:31 -070036 return rewriteValuegeneric_OpCom64(v, config)
Todd Neal38ed6c12015-07-30 16:02:24 -040037 case OpCom8:
Keith Randalla347ab72015-10-26 21:49:31 -070038 return rewriteValuegeneric_OpCom8(v, config)
David Chase52578582015-08-28 14:24:10 -040039 case OpComplexImag:
Keith Randalla347ab72015-10-26 21:49:31 -070040 return rewriteValuegeneric_OpComplexImag(v, config)
David Chase52578582015-08-28 14:24:10 -040041 case OpComplexReal:
Keith Randalla347ab72015-10-26 21:49:31 -070042 return rewriteValuegeneric_OpComplexReal(v, config)
Keith Randall9f954db2015-08-18 10:26:28 -070043 case OpConstInterface:
Keith Randalla347ab72015-10-26 21:49:31 -070044 return rewriteValuegeneric_OpConstInterface(v, config)
Keith Randall9f954db2015-08-18 10:26:28 -070045 case OpConstSlice:
Keith Randalla347ab72015-10-26 21:49:31 -070046 return rewriteValuegeneric_OpConstSlice(v, config)
Keith Randall9cb332e2015-07-28 14:19:20 -070047 case OpConstString:
Keith Randalla347ab72015-10-26 21:49:31 -070048 return rewriteValuegeneric_OpConstString(v, config)
Keith Randalla3180d82015-10-23 14:08:50 -070049 case OpConvert:
Keith Randalla347ab72015-10-26 21:49:31 -070050 return rewriteValuegeneric_OpConvert(v, config)
Keith Randalla3055af2016-02-05 20:26:18 -080051 case OpDiv64:
52 return rewriteValuegeneric_OpDiv64(v, config)
53 case OpDiv64u:
54 return rewriteValuegeneric_OpDiv64u(v, config)
Alexandru Moșoi9b25da72015-07-31 12:32:22 +020055 case OpEq16:
Keith Randalla347ab72015-10-26 21:49:31 -070056 return rewriteValuegeneric_OpEq16(v, config)
Alexandru Moșoi9b25da72015-07-31 12:32:22 +020057 case OpEq32:
Keith Randalla347ab72015-10-26 21:49:31 -070058 return rewriteValuegeneric_OpEq32(v, config)
Alexandru Moșoi9b25da72015-07-31 12:32:22 +020059 case OpEq64:
Keith Randalla347ab72015-10-26 21:49:31 -070060 return rewriteValuegeneric_OpEq64(v, config)
Alexandru Moșoi9b25da72015-07-31 12:32:22 +020061 case OpEq8:
Keith Randalla347ab72015-10-26 21:49:31 -070062 return rewriteValuegeneric_OpEq8(v, config)
Keith Randall1e4ebfd2015-09-10 13:53:27 -070063 case OpEqInter:
Keith Randalla347ab72015-10-26 21:49:31 -070064 return rewriteValuegeneric_OpEqInter(v, config)
Todd Nealec8a5972015-08-30 21:19:20 -050065 case OpEqPtr:
Keith Randalla347ab72015-10-26 21:49:31 -070066 return rewriteValuegeneric_OpEqPtr(v, config)
Keith Randall1e4ebfd2015-09-10 13:53:27 -070067 case OpEqSlice:
Keith Randalla347ab72015-10-26 21:49:31 -070068 return rewriteValuegeneric_OpEqSlice(v, config)
Todd Nealcdc36252015-10-27 17:46:53 -050069 case OpGeq16:
70 return rewriteValuegeneric_OpGeq16(v, config)
71 case OpGeq16U:
72 return rewriteValuegeneric_OpGeq16U(v, config)
73 case OpGeq32:
74 return rewriteValuegeneric_OpGeq32(v, config)
75 case OpGeq32U:
76 return rewriteValuegeneric_OpGeq32U(v, config)
77 case OpGeq64:
78 return rewriteValuegeneric_OpGeq64(v, config)
79 case OpGeq64U:
80 return rewriteValuegeneric_OpGeq64U(v, config)
81 case OpGeq8:
82 return rewriteValuegeneric_OpGeq8(v, config)
83 case OpGeq8U:
84 return rewriteValuegeneric_OpGeq8U(v, config)
85 case OpGreater16:
86 return rewriteValuegeneric_OpGreater16(v, config)
87 case OpGreater16U:
88 return rewriteValuegeneric_OpGreater16U(v, config)
89 case OpGreater32:
90 return rewriteValuegeneric_OpGreater32(v, config)
91 case OpGreater32U:
92 return rewriteValuegeneric_OpGreater32U(v, config)
93 case OpGreater64:
94 return rewriteValuegeneric_OpGreater64(v, config)
95 case OpGreater64U:
96 return rewriteValuegeneric_OpGreater64U(v, config)
97 case OpGreater8:
98 return rewriteValuegeneric_OpGreater8(v, config)
99 case OpGreater8U:
100 return rewriteValuegeneric_OpGreater8U(v, config)
Keith Randall9f954db2015-08-18 10:26:28 -0700101 case OpIData:
Keith Randalla347ab72015-10-26 21:49:31 -0700102 return rewriteValuegeneric_OpIData(v, config)
Keith Randall9f954db2015-08-18 10:26:28 -0700103 case OpITab:
Keith Randalla347ab72015-10-26 21:49:31 -0700104 return rewriteValuegeneric_OpITab(v, config)
Keith Randall0dca7352015-06-06 16:03:33 -0700105 case OpIsInBounds:
Keith Randalla347ab72015-10-26 21:49:31 -0700106 return rewriteValuegeneric_OpIsInBounds(v, config)
Keith Randall582baae2015-11-02 21:28:13 -0800107 case OpIsSliceInBounds:
108 return rewriteValuegeneric_OpIsSliceInBounds(v, config)
Todd Nealcdc36252015-10-27 17:46:53 -0500109 case OpLeq16:
110 return rewriteValuegeneric_OpLeq16(v, config)
111 case OpLeq16U:
112 return rewriteValuegeneric_OpLeq16U(v, config)
113 case OpLeq32:
114 return rewriteValuegeneric_OpLeq32(v, config)
115 case OpLeq32U:
116 return rewriteValuegeneric_OpLeq32U(v, config)
117 case OpLeq64:
118 return rewriteValuegeneric_OpLeq64(v, config)
119 case OpLeq64U:
120 return rewriteValuegeneric_OpLeq64U(v, config)
121 case OpLeq8:
122 return rewriteValuegeneric_OpLeq8(v, config)
123 case OpLeq8U:
124 return rewriteValuegeneric_OpLeq8U(v, config)
125 case OpLess16:
126 return rewriteValuegeneric_OpLess16(v, config)
127 case OpLess16U:
128 return rewriteValuegeneric_OpLess16U(v, config)
129 case OpLess32:
130 return rewriteValuegeneric_OpLess32(v, config)
131 case OpLess32U:
132 return rewriteValuegeneric_OpLess32U(v, config)
133 case OpLess64:
134 return rewriteValuegeneric_OpLess64(v, config)
135 case OpLess64U:
136 return rewriteValuegeneric_OpLess64U(v, config)
137 case OpLess8:
138 return rewriteValuegeneric_OpLess8(v, config)
139 case OpLess8U:
140 return rewriteValuegeneric_OpLess8U(v, config)
Keith Randall0dca7352015-06-06 16:03:33 -0700141 case OpLoad:
Keith Randalla347ab72015-10-26 21:49:31 -0700142 return rewriteValuegeneric_OpLoad(v, config)
Todd Neal93a0b0f2016-02-03 06:21:24 -0500143 case OpLsh16x16:
144 return rewriteValuegeneric_OpLsh16x16(v, config)
145 case OpLsh16x32:
146 return rewriteValuegeneric_OpLsh16x32(v, config)
147 case OpLsh16x64:
148 return rewriteValuegeneric_OpLsh16x64(v, config)
149 case OpLsh16x8:
150 return rewriteValuegeneric_OpLsh16x8(v, config)
151 case OpLsh32x16:
152 return rewriteValuegeneric_OpLsh32x16(v, config)
153 case OpLsh32x32:
154 return rewriteValuegeneric_OpLsh32x32(v, config)
155 case OpLsh32x64:
156 return rewriteValuegeneric_OpLsh32x64(v, config)
157 case OpLsh32x8:
158 return rewriteValuegeneric_OpLsh32x8(v, config)
159 case OpLsh64x16:
160 return rewriteValuegeneric_OpLsh64x16(v, config)
161 case OpLsh64x32:
162 return rewriteValuegeneric_OpLsh64x32(v, config)
163 case OpLsh64x64:
164 return rewriteValuegeneric_OpLsh64x64(v, config)
165 case OpLsh64x8:
166 return rewriteValuegeneric_OpLsh64x8(v, config)
167 case OpLsh8x16:
168 return rewriteValuegeneric_OpLsh8x16(v, config)
169 case OpLsh8x32:
170 return rewriteValuegeneric_OpLsh8x32(v, config)
171 case OpLsh8x64:
172 return rewriteValuegeneric_OpLsh8x64(v, config)
173 case OpLsh8x8:
174 return rewriteValuegeneric_OpLsh8x8(v, config)
Keith Randalla3055af2016-02-05 20:26:18 -0800175 case OpMod64:
176 return rewriteValuegeneric_OpMod64(v, config)
177 case OpMod64u:
178 return rewriteValuegeneric_OpMod64u(v, config)
Keith Randall582baae2015-11-02 21:28:13 -0800179 case OpMul16:
180 return rewriteValuegeneric_OpMul16(v, config)
181 case OpMul32:
182 return rewriteValuegeneric_OpMul32(v, config)
Keith Randallbe1eb572015-07-22 13:46:15 -0700183 case OpMul64:
Keith Randalla347ab72015-10-26 21:49:31 -0700184 return rewriteValuegeneric_OpMul64(v, config)
Keith Randall582baae2015-11-02 21:28:13 -0800185 case OpMul8:
186 return rewriteValuegeneric_OpMul8(v, config)
Alexandru Moșoi964dda92016-02-08 18:55:56 +0100187 case OpNeg16:
188 return rewriteValuegeneric_OpNeg16(v, config)
189 case OpNeg32:
190 return rewriteValuegeneric_OpNeg32(v, config)
191 case OpNeg64:
192 return rewriteValuegeneric_OpNeg64(v, config)
193 case OpNeg8:
194 return rewriteValuegeneric_OpNeg8(v, config)
Alexandru Moșoi9b25da72015-07-31 12:32:22 +0200195 case OpNeq16:
Keith Randalla347ab72015-10-26 21:49:31 -0700196 return rewriteValuegeneric_OpNeq16(v, config)
Alexandru Moșoi9b25da72015-07-31 12:32:22 +0200197 case OpNeq32:
Keith Randalla347ab72015-10-26 21:49:31 -0700198 return rewriteValuegeneric_OpNeq32(v, config)
Alexandru Moșoi9b25da72015-07-31 12:32:22 +0200199 case OpNeq64:
Keith Randalla347ab72015-10-26 21:49:31 -0700200 return rewriteValuegeneric_OpNeq64(v, config)
Alexandru Moșoi9b25da72015-07-31 12:32:22 +0200201 case OpNeq8:
Keith Randalla347ab72015-10-26 21:49:31 -0700202 return rewriteValuegeneric_OpNeq8(v, config)
Keith Randall1e4ebfd2015-09-10 13:53:27 -0700203 case OpNeqInter:
Keith Randalla347ab72015-10-26 21:49:31 -0700204 return rewriteValuegeneric_OpNeqInter(v, config)
Todd Nealec8a5972015-08-30 21:19:20 -0500205 case OpNeqPtr:
Keith Randalla347ab72015-10-26 21:49:31 -0700206 return rewriteValuegeneric_OpNeqPtr(v, config)
Keith Randall1e4ebfd2015-09-10 13:53:27 -0700207 case OpNeqSlice:
Keith Randalla347ab72015-10-26 21:49:31 -0700208 return rewriteValuegeneric_OpNeqSlice(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200209 case OpOr16:
Keith Randalla347ab72015-10-26 21:49:31 -0700210 return rewriteValuegeneric_OpOr16(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200211 case OpOr32:
Keith Randalla347ab72015-10-26 21:49:31 -0700212 return rewriteValuegeneric_OpOr32(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200213 case OpOr64:
Keith Randalla347ab72015-10-26 21:49:31 -0700214 return rewriteValuegeneric_OpOr64(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200215 case OpOr8:
Keith Randalla347ab72015-10-26 21:49:31 -0700216 return rewriteValuegeneric_OpOr8(v, config)
Alexandru Moșoid0d04d22016-02-09 19:46:26 +0100217 case OpPhi:
218 return rewriteValuegeneric_OpPhi(v, config)
Keith Randall0dca7352015-06-06 16:03:33 -0700219 case OpPtrIndex:
Keith Randalla347ab72015-10-26 21:49:31 -0700220 return rewriteValuegeneric_OpPtrIndex(v, config)
Todd Neal93a0b0f2016-02-03 06:21:24 -0500221 case OpRsh16Ux16:
222 return rewriteValuegeneric_OpRsh16Ux16(v, config)
223 case OpRsh16Ux32:
224 return rewriteValuegeneric_OpRsh16Ux32(v, config)
225 case OpRsh16Ux64:
226 return rewriteValuegeneric_OpRsh16Ux64(v, config)
227 case OpRsh16Ux8:
228 return rewriteValuegeneric_OpRsh16Ux8(v, config)
229 case OpRsh16x16:
230 return rewriteValuegeneric_OpRsh16x16(v, config)
231 case OpRsh16x32:
232 return rewriteValuegeneric_OpRsh16x32(v, config)
233 case OpRsh16x64:
234 return rewriteValuegeneric_OpRsh16x64(v, config)
235 case OpRsh16x8:
236 return rewriteValuegeneric_OpRsh16x8(v, config)
237 case OpRsh32Ux16:
238 return rewriteValuegeneric_OpRsh32Ux16(v, config)
239 case OpRsh32Ux32:
240 return rewriteValuegeneric_OpRsh32Ux32(v, config)
241 case OpRsh32Ux64:
242 return rewriteValuegeneric_OpRsh32Ux64(v, config)
243 case OpRsh32Ux8:
244 return rewriteValuegeneric_OpRsh32Ux8(v, config)
245 case OpRsh32x16:
246 return rewriteValuegeneric_OpRsh32x16(v, config)
247 case OpRsh32x32:
248 return rewriteValuegeneric_OpRsh32x32(v, config)
249 case OpRsh32x64:
250 return rewriteValuegeneric_OpRsh32x64(v, config)
251 case OpRsh32x8:
252 return rewriteValuegeneric_OpRsh32x8(v, config)
253 case OpRsh64Ux16:
254 return rewriteValuegeneric_OpRsh64Ux16(v, config)
255 case OpRsh64Ux32:
256 return rewriteValuegeneric_OpRsh64Ux32(v, config)
257 case OpRsh64Ux64:
258 return rewriteValuegeneric_OpRsh64Ux64(v, config)
259 case OpRsh64Ux8:
260 return rewriteValuegeneric_OpRsh64Ux8(v, config)
261 case OpRsh64x16:
262 return rewriteValuegeneric_OpRsh64x16(v, config)
263 case OpRsh64x32:
264 return rewriteValuegeneric_OpRsh64x32(v, config)
265 case OpRsh64x64:
266 return rewriteValuegeneric_OpRsh64x64(v, config)
267 case OpRsh64x8:
268 return rewriteValuegeneric_OpRsh64x8(v, config)
269 case OpRsh8Ux16:
270 return rewriteValuegeneric_OpRsh8Ux16(v, config)
271 case OpRsh8Ux32:
272 return rewriteValuegeneric_OpRsh8Ux32(v, config)
273 case OpRsh8Ux64:
274 return rewriteValuegeneric_OpRsh8Ux64(v, config)
275 case OpRsh8Ux8:
276 return rewriteValuegeneric_OpRsh8Ux8(v, config)
277 case OpRsh8x16:
278 return rewriteValuegeneric_OpRsh8x16(v, config)
279 case OpRsh8x32:
280 return rewriteValuegeneric_OpRsh8x32(v, config)
281 case OpRsh8x64:
282 return rewriteValuegeneric_OpRsh8x64(v, config)
283 case OpRsh8x8:
284 return rewriteValuegeneric_OpRsh8x8(v, config)
Keith Randall0dca7352015-06-06 16:03:33 -0700285 case OpSliceCap:
Keith Randalla347ab72015-10-26 21:49:31 -0700286 return rewriteValuegeneric_OpSliceCap(v, config)
Keith Randall0dca7352015-06-06 16:03:33 -0700287 case OpSliceLen:
Keith Randalla347ab72015-10-26 21:49:31 -0700288 return rewriteValuegeneric_OpSliceLen(v, config)
Keith Randall0dca7352015-06-06 16:03:33 -0700289 case OpSlicePtr:
Keith Randalla347ab72015-10-26 21:49:31 -0700290 return rewriteValuegeneric_OpSlicePtr(v, config)
Keith Randall0dca7352015-06-06 16:03:33 -0700291 case OpStore:
Keith Randalla347ab72015-10-26 21:49:31 -0700292 return rewriteValuegeneric_OpStore(v, config)
Keith Randall0dca7352015-06-06 16:03:33 -0700293 case OpStringLen:
Keith Randalla347ab72015-10-26 21:49:31 -0700294 return rewriteValuegeneric_OpStringLen(v, config)
Keith Randall0dca7352015-06-06 16:03:33 -0700295 case OpStringPtr:
Keith Randalla347ab72015-10-26 21:49:31 -0700296 return rewriteValuegeneric_OpStringPtr(v, config)
Keith Randallcd7e0592015-07-15 21:33:49 -0700297 case OpStructSelect:
Keith Randalla347ab72015-10-26 21:49:31 -0700298 return rewriteValuegeneric_OpStructSelect(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200299 case OpSub16:
Keith Randalla347ab72015-10-26 21:49:31 -0700300 return rewriteValuegeneric_OpSub16(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200301 case OpSub32:
Keith Randalla347ab72015-10-26 21:49:31 -0700302 return rewriteValuegeneric_OpSub32(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200303 case OpSub64:
Keith Randalla347ab72015-10-26 21:49:31 -0700304 return rewriteValuegeneric_OpSub64(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200305 case OpSub8:
Keith Randalla347ab72015-10-26 21:49:31 -0700306 return rewriteValuegeneric_OpSub8(v, config)
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +0100307 case OpTrunc16to8:
308 return rewriteValuegeneric_OpTrunc16to8(v, config)
309 case OpTrunc32to16:
310 return rewriteValuegeneric_OpTrunc32to16(v, config)
311 case OpTrunc32to8:
312 return rewriteValuegeneric_OpTrunc32to8(v, config)
313 case OpTrunc64to16:
314 return rewriteValuegeneric_OpTrunc64to16(v, config)
315 case OpTrunc64to32:
316 return rewriteValuegeneric_OpTrunc64to32(v, config)
317 case OpTrunc64to8:
318 return rewriteValuegeneric_OpTrunc64to8(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200319 case OpXor16:
Keith Randalla347ab72015-10-26 21:49:31 -0700320 return rewriteValuegeneric_OpXor16(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200321 case OpXor32:
Keith Randalla347ab72015-10-26 21:49:31 -0700322 return rewriteValuegeneric_OpXor32(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200323 case OpXor64:
Keith Randalla347ab72015-10-26 21:49:31 -0700324 return rewriteValuegeneric_OpXor64(v, config)
Alexandru Moșoi198fc9a2015-08-14 12:59:33 +0200325 case OpXor8:
Keith Randalla347ab72015-10-26 21:49:31 -0700326 return rewriteValuegeneric_OpXor8(v, config)
Keith Randall0dca7352015-06-06 16:03:33 -0700327 }
328 return false
329}
Keith Randall582baae2015-11-02 21:28:13 -0800330func rewriteValuegeneric_OpAdd16(v *Value, config *Config) bool {
331 b := v.Block
332 _ = b
333 // match: (Add16 (Const16 [c]) (Const16 [d]))
334 // cond:
335 // result: (Const16 [c+d])
Alexandru Moșoi05434472016-02-04 19:52:10 +0100336 for {
Keith Randall582baae2015-11-02 21:28:13 -0800337 if v.Args[0].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100338 break
Keith Randall582baae2015-11-02 21:28:13 -0800339 }
340 c := v.Args[0].AuxInt
341 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100342 break
Keith Randall582baae2015-11-02 21:28:13 -0800343 }
344 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100345 v.reset(OpConst16)
Keith Randall582baae2015-11-02 21:28:13 -0800346 v.AuxInt = c + d
347 return true
348 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100349 // match: (Add16 x (Const16 <t> [c]))
350 // cond: x.Op != OpConst16
351 // result: (Add16 (Const16 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +0100352 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100353 x := v.Args[0]
354 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100355 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100356 }
357 t := v.Args[1].Type
358 c := v.Args[1].AuxInt
359 if !(x.Op != OpConst16) {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100360 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100361 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100362 v.reset(OpAdd16)
Todd Neal93a0b0f2016-02-03 06:21:24 -0500363 v0 := b.NewValue0(v.Line, OpConst16, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100364 v0.AuxInt = c
365 v.AddArg(v0)
366 v.AddArg(x)
367 return true
368 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100369 // match: (Add16 (Const16 [0]) x)
370 // cond:
371 // result: x
372 for {
373 if v.Args[0].Op != OpConst16 {
374 break
375 }
376 if v.Args[0].AuxInt != 0 {
377 break
378 }
379 x := v.Args[1]
380 v.reset(OpCopy)
381 v.Type = x.Type
382 v.AddArg(x)
383 return true
384 }
Keith Randall582baae2015-11-02 21:28:13 -0800385 return false
386}
387func rewriteValuegeneric_OpAdd32(v *Value, config *Config) bool {
388 b := v.Block
389 _ = b
390 // match: (Add32 (Const32 [c]) (Const32 [d]))
391 // cond:
392 // result: (Const32 [c+d])
Alexandru Moșoi05434472016-02-04 19:52:10 +0100393 for {
Keith Randall582baae2015-11-02 21:28:13 -0800394 if v.Args[0].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100395 break
Keith Randall582baae2015-11-02 21:28:13 -0800396 }
397 c := v.Args[0].AuxInt
398 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100399 break
Keith Randall582baae2015-11-02 21:28:13 -0800400 }
401 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100402 v.reset(OpConst32)
Keith Randall582baae2015-11-02 21:28:13 -0800403 v.AuxInt = c + d
404 return true
405 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100406 // match: (Add32 x (Const32 <t> [c]))
407 // cond: x.Op != OpConst32
408 // result: (Add32 (Const32 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +0100409 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100410 x := v.Args[0]
411 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100412 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100413 }
414 t := v.Args[1].Type
415 c := v.Args[1].AuxInt
416 if !(x.Op != OpConst32) {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100417 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100418 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100419 v.reset(OpAdd32)
Todd Neal93a0b0f2016-02-03 06:21:24 -0500420 v0 := b.NewValue0(v.Line, OpConst32, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100421 v0.AuxInt = c
422 v.AddArg(v0)
423 v.AddArg(x)
424 return true
425 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100426 // match: (Add32 (Const32 [0]) x)
427 // cond:
428 // result: x
429 for {
430 if v.Args[0].Op != OpConst32 {
431 break
432 }
433 if v.Args[0].AuxInt != 0 {
434 break
435 }
436 x := v.Args[1]
437 v.reset(OpCopy)
438 v.Type = x.Type
439 v.AddArg(x)
440 return true
441 }
Keith Randall582baae2015-11-02 21:28:13 -0800442 return false
443}
Keith Randalla347ab72015-10-26 21:49:31 -0700444func rewriteValuegeneric_OpAdd64(v *Value, config *Config) bool {
445 b := v.Block
446 _ = b
447 // match: (Add64 (Const64 [c]) (Const64 [d]))
448 // cond:
449 // result: (Const64 [c+d])
Alexandru Moșoi05434472016-02-04 19:52:10 +0100450 for {
Keith Randalla347ab72015-10-26 21:49:31 -0700451 if v.Args[0].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100452 break
Keith Randalla347ab72015-10-26 21:49:31 -0700453 }
454 c := v.Args[0].AuxInt
455 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100456 break
Keith Randalla347ab72015-10-26 21:49:31 -0700457 }
458 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100459 v.reset(OpConst64)
Keith Randalla347ab72015-10-26 21:49:31 -0700460 v.AuxInt = c + d
461 return true
462 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100463 // match: (Add64 x (Const64 <t> [c]))
464 // cond: x.Op != OpConst64
465 // result: (Add64 (Const64 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +0100466 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100467 x := v.Args[0]
468 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100469 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100470 }
471 t := v.Args[1].Type
472 c := v.Args[1].AuxInt
473 if !(x.Op != OpConst64) {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100474 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100475 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100476 v.reset(OpAdd64)
Todd Neal93a0b0f2016-02-03 06:21:24 -0500477 v0 := b.NewValue0(v.Line, OpConst64, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100478 v0.AuxInt = c
479 v.AddArg(v0)
480 v.AddArg(x)
481 return true
482 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100483 // match: (Add64 (Const64 [0]) x)
484 // cond:
485 // result: x
486 for {
487 if v.Args[0].Op != OpConst64 {
488 break
489 }
490 if v.Args[0].AuxInt != 0 {
491 break
492 }
493 x := v.Args[1]
494 v.reset(OpCopy)
495 v.Type = x.Type
496 v.AddArg(x)
497 return true
498 }
Keith Randalla347ab72015-10-26 21:49:31 -0700499 return false
500}
Keith Randall582baae2015-11-02 21:28:13 -0800501func rewriteValuegeneric_OpAdd8(v *Value, config *Config) bool {
Keith Randalla347ab72015-10-26 21:49:31 -0700502 b := v.Block
503 _ = b
Keith Randall582baae2015-11-02 21:28:13 -0800504 // match: (Add8 (Const8 [c]) (Const8 [d]))
Keith Randalla347ab72015-10-26 21:49:31 -0700505 // cond:
Keith Randall582baae2015-11-02 21:28:13 -0800506 // result: (Const8 [c+d])
Alexandru Moșoi05434472016-02-04 19:52:10 +0100507 for {
Keith Randall582baae2015-11-02 21:28:13 -0800508 if v.Args[0].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100509 break
Keith Randalla347ab72015-10-26 21:49:31 -0700510 }
511 c := v.Args[0].AuxInt
Keith Randall582baae2015-11-02 21:28:13 -0800512 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100513 break
Keith Randalla347ab72015-10-26 21:49:31 -0700514 }
515 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100516 v.reset(OpConst8)
Keith Randalla347ab72015-10-26 21:49:31 -0700517 v.AuxInt = c + d
518 return true
519 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100520 // match: (Add8 x (Const8 <t> [c]))
521 // cond: x.Op != OpConst8
522 // result: (Add8 (Const8 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +0100523 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100524 x := v.Args[0]
525 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100526 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100527 }
528 t := v.Args[1].Type
529 c := v.Args[1].AuxInt
530 if !(x.Op != OpConst8) {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100531 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100532 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100533 v.reset(OpAdd8)
Todd Neal93a0b0f2016-02-03 06:21:24 -0500534 v0 := b.NewValue0(v.Line, OpConst8, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +0100535 v0.AuxInt = c
536 v.AddArg(v0)
537 v.AddArg(x)
538 return true
539 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100540 // match: (Add8 (Const8 [0]) x)
541 // cond:
542 // result: x
543 for {
544 if v.Args[0].Op != OpConst8 {
545 break
546 }
547 if v.Args[0].AuxInt != 0 {
548 break
549 }
550 x := v.Args[1]
551 v.reset(OpCopy)
552 v.Type = x.Type
553 v.AddArg(x)
554 return true
555 }
Keith Randalla347ab72015-10-26 21:49:31 -0700556 return false
557}
558func rewriteValuegeneric_OpAnd16(v *Value, config *Config) bool {
559 b := v.Block
560 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100561 // match: (And16 x (Const16 <t> [c]))
562 // cond: x.Op != OpConst16
563 // result: (And16 (Const16 <t> [c]) x)
564 for {
565 x := v.Args[0]
566 if v.Args[1].Op != OpConst16 {
567 break
568 }
569 t := v.Args[1].Type
570 c := v.Args[1].AuxInt
571 if !(x.Op != OpConst16) {
572 break
573 }
574 v.reset(OpAnd16)
575 v0 := b.NewValue0(v.Line, OpConst16, t)
576 v0.AuxInt = c
577 v.AddArg(v0)
578 v.AddArg(x)
579 return true
580 }
Keith Randalla347ab72015-10-26 21:49:31 -0700581 // match: (And16 x x)
582 // cond:
583 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +0100584 for {
Keith Randalla347ab72015-10-26 21:49:31 -0700585 x := v.Args[0]
586 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100587 break
Keith Randalla347ab72015-10-26 21:49:31 -0700588 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100589 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -0700590 v.Type = x.Type
591 v.AddArg(x)
592 return true
593 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100594 // match: (And16 (Const16 [-1]) x)
595 // cond:
596 // result: x
597 for {
598 if v.Args[0].Op != OpConst16 {
599 break
600 }
601 if v.Args[0].AuxInt != -1 {
602 break
603 }
604 x := v.Args[1]
605 v.reset(OpCopy)
606 v.Type = x.Type
607 v.AddArg(x)
608 return true
609 }
610 // match: (And16 (Const16 [0]) _)
611 // cond:
612 // result: (Const16 [0])
613 for {
614 if v.Args[0].Op != OpConst16 {
615 break
616 }
617 if v.Args[0].AuxInt != 0 {
618 break
619 }
620 v.reset(OpConst16)
621 v.AuxInt = 0
622 return true
623 }
Keith Randalla347ab72015-10-26 21:49:31 -0700624 return false
625}
626func rewriteValuegeneric_OpAnd32(v *Value, config *Config) bool {
627 b := v.Block
628 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100629 // match: (And32 x (Const32 <t> [c]))
630 // cond: x.Op != OpConst32
631 // result: (And32 (Const32 <t> [c]) x)
632 for {
633 x := v.Args[0]
634 if v.Args[1].Op != OpConst32 {
635 break
636 }
637 t := v.Args[1].Type
638 c := v.Args[1].AuxInt
639 if !(x.Op != OpConst32) {
640 break
641 }
642 v.reset(OpAnd32)
643 v0 := b.NewValue0(v.Line, OpConst32, t)
644 v0.AuxInt = c
645 v.AddArg(v0)
646 v.AddArg(x)
647 return true
648 }
Keith Randalla347ab72015-10-26 21:49:31 -0700649 // match: (And32 x x)
650 // cond:
651 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +0100652 for {
Keith Randalla347ab72015-10-26 21:49:31 -0700653 x := v.Args[0]
654 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100655 break
Keith Randalla347ab72015-10-26 21:49:31 -0700656 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100657 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -0700658 v.Type = x.Type
659 v.AddArg(x)
660 return true
661 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100662 // match: (And32 (Const32 [-1]) x)
663 // cond:
664 // result: x
665 for {
666 if v.Args[0].Op != OpConst32 {
667 break
668 }
669 if v.Args[0].AuxInt != -1 {
670 break
671 }
672 x := v.Args[1]
673 v.reset(OpCopy)
674 v.Type = x.Type
675 v.AddArg(x)
676 return true
677 }
678 // match: (And32 (Const32 [0]) _)
679 // cond:
680 // result: (Const32 [0])
681 for {
682 if v.Args[0].Op != OpConst32 {
683 break
684 }
685 if v.Args[0].AuxInt != 0 {
686 break
687 }
688 v.reset(OpConst32)
689 v.AuxInt = 0
690 return true
691 }
Todd Nealadc8d492016-02-11 20:43:15 -0600692 // match: (And32 <t> (Const32 [y]) x)
693 // cond: nlz(int64(int32(y))) + nto(int64(int32(y))) == 64
694 // result: (Rsh32Ux32 (Lsh32x32 <t> x (Const32 <t> [nlz(int64(int32(y)))-32])) (Const32 <t> [nlz(int64(int32(y)))-32]))
695 for {
696 t := v.Type
697 if v.Args[0].Op != OpConst32 {
698 break
699 }
700 y := v.Args[0].AuxInt
701 x := v.Args[1]
702 if !(nlz(int64(int32(y)))+nto(int64(int32(y))) == 64) {
703 break
704 }
705 v.reset(OpRsh32Ux32)
706 v0 := b.NewValue0(v.Line, OpLsh32x32, t)
707 v0.AddArg(x)
708 v1 := b.NewValue0(v.Line, OpConst32, t)
709 v1.AuxInt = nlz(int64(int32(y))) - 32
710 v0.AddArg(v1)
711 v.AddArg(v0)
712 v2 := b.NewValue0(v.Line, OpConst32, t)
713 v2.AuxInt = nlz(int64(int32(y))) - 32
714 v.AddArg(v2)
715 return true
716 }
717 // match: (And32 <t> (Const32 [y]) x)
718 // cond: nlo(int64(int32(y))) + ntz(int64(int32(y))) == 64
719 // result: (Lsh32x32 (Rsh32Ux32 <t> x (Const32 <t> [ntz(int64(int32(y)))])) (Const32 <t> [ntz(int64(int32(y)))]))
720 for {
721 t := v.Type
722 if v.Args[0].Op != OpConst32 {
723 break
724 }
725 y := v.Args[0].AuxInt
726 x := v.Args[1]
727 if !(nlo(int64(int32(y)))+ntz(int64(int32(y))) == 64) {
728 break
729 }
730 v.reset(OpLsh32x32)
731 v0 := b.NewValue0(v.Line, OpRsh32Ux32, t)
732 v0.AddArg(x)
733 v1 := b.NewValue0(v.Line, OpConst32, t)
734 v1.AuxInt = ntz(int64(int32(y)))
735 v0.AddArg(v1)
736 v.AddArg(v0)
737 v2 := b.NewValue0(v.Line, OpConst32, t)
738 v2.AuxInt = ntz(int64(int32(y)))
739 v.AddArg(v2)
740 return true
741 }
Keith Randalla347ab72015-10-26 21:49:31 -0700742 return false
743}
744func rewriteValuegeneric_OpAnd64(v *Value, config *Config) bool {
745 b := v.Block
746 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100747 // match: (And64 x (Const64 <t> [c]))
748 // cond: x.Op != OpConst64
749 // result: (And64 (Const64 <t> [c]) x)
750 for {
751 x := v.Args[0]
752 if v.Args[1].Op != OpConst64 {
753 break
754 }
755 t := v.Args[1].Type
756 c := v.Args[1].AuxInt
757 if !(x.Op != OpConst64) {
758 break
759 }
760 v.reset(OpAnd64)
761 v0 := b.NewValue0(v.Line, OpConst64, t)
762 v0.AuxInt = c
763 v.AddArg(v0)
764 v.AddArg(x)
765 return true
766 }
Keith Randalla347ab72015-10-26 21:49:31 -0700767 // match: (And64 x x)
768 // cond:
769 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +0100770 for {
Keith Randalla347ab72015-10-26 21:49:31 -0700771 x := v.Args[0]
772 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100773 break
Keith Randalla347ab72015-10-26 21:49:31 -0700774 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100775 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -0700776 v.Type = x.Type
777 v.AddArg(x)
778 return true
779 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100780 // match: (And64 (Const64 [-1]) x)
781 // cond:
782 // result: x
783 for {
784 if v.Args[0].Op != OpConst64 {
785 break
786 }
787 if v.Args[0].AuxInt != -1 {
788 break
789 }
790 x := v.Args[1]
791 v.reset(OpCopy)
792 v.Type = x.Type
793 v.AddArg(x)
794 return true
795 }
796 // match: (And64 (Const64 [0]) _)
797 // cond:
798 // result: (Const64 [0])
799 for {
800 if v.Args[0].Op != OpConst64 {
801 break
802 }
803 if v.Args[0].AuxInt != 0 {
804 break
805 }
806 v.reset(OpConst64)
807 v.AuxInt = 0
808 return true
809 }
Todd Nealadc8d492016-02-11 20:43:15 -0600810 // match: (And64 <t> (Const64 [y]) x)
811 // cond: nlz(y) + nto(y) == 64
812 // result: (Rsh64Ux64 (Lsh64x64 <t> x (Const64 <t> [nlz(y)])) (Const64 <t> [nlz(y)]))
813 for {
814 t := v.Type
815 if v.Args[0].Op != OpConst64 {
816 break
817 }
818 y := v.Args[0].AuxInt
819 x := v.Args[1]
820 if !(nlz(y)+nto(y) == 64) {
821 break
822 }
823 v.reset(OpRsh64Ux64)
824 v0 := b.NewValue0(v.Line, OpLsh64x64, t)
825 v0.AddArg(x)
826 v1 := b.NewValue0(v.Line, OpConst64, t)
827 v1.AuxInt = nlz(y)
828 v0.AddArg(v1)
829 v.AddArg(v0)
830 v2 := b.NewValue0(v.Line, OpConst64, t)
831 v2.AuxInt = nlz(y)
832 v.AddArg(v2)
833 return true
834 }
835 // match: (And64 <t> (Const64 [y]) x)
836 // cond: nlo(y) + ntz(y) == 64
837 // result: (Lsh64x64 (Rsh64Ux64 <t> x (Const64 <t> [ntz(y)])) (Const64 <t> [ntz(y)]))
838 for {
839 t := v.Type
840 if v.Args[0].Op != OpConst64 {
841 break
842 }
843 y := v.Args[0].AuxInt
844 x := v.Args[1]
845 if !(nlo(y)+ntz(y) == 64) {
846 break
847 }
848 v.reset(OpLsh64x64)
849 v0 := b.NewValue0(v.Line, OpRsh64Ux64, t)
850 v0.AddArg(x)
851 v1 := b.NewValue0(v.Line, OpConst64, t)
852 v1.AuxInt = ntz(y)
853 v0.AddArg(v1)
854 v.AddArg(v0)
855 v2 := b.NewValue0(v.Line, OpConst64, t)
856 v2.AuxInt = ntz(y)
857 v.AddArg(v2)
858 return true
859 }
Keith Randalla347ab72015-10-26 21:49:31 -0700860 return false
861}
862func rewriteValuegeneric_OpAnd8(v *Value, config *Config) bool {
863 b := v.Block
864 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100865 // match: (And8 x (Const8 <t> [c]))
866 // cond: x.Op != OpConst8
867 // result: (And8 (Const8 <t> [c]) x)
868 for {
869 x := v.Args[0]
870 if v.Args[1].Op != OpConst8 {
871 break
872 }
873 t := v.Args[1].Type
874 c := v.Args[1].AuxInt
875 if !(x.Op != OpConst8) {
876 break
877 }
878 v.reset(OpAnd8)
879 v0 := b.NewValue0(v.Line, OpConst8, t)
880 v0.AuxInt = c
881 v.AddArg(v0)
882 v.AddArg(x)
883 return true
884 }
Keith Randalla347ab72015-10-26 21:49:31 -0700885 // match: (And8 x x)
886 // cond:
887 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +0100888 for {
Keith Randalla347ab72015-10-26 21:49:31 -0700889 x := v.Args[0]
890 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100891 break
Keith Randalla347ab72015-10-26 21:49:31 -0700892 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100893 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -0700894 v.Type = x.Type
895 v.AddArg(x)
896 return true
897 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +0100898 // match: (And8 (Const8 [-1]) x)
899 // cond:
900 // result: x
901 for {
902 if v.Args[0].Op != OpConst8 {
903 break
904 }
905 if v.Args[0].AuxInt != -1 {
906 break
907 }
908 x := v.Args[1]
909 v.reset(OpCopy)
910 v.Type = x.Type
911 v.AddArg(x)
912 return true
913 }
914 // match: (And8 (Const8 [0]) _)
915 // cond:
916 // result: (Const8 [0])
917 for {
918 if v.Args[0].Op != OpConst8 {
919 break
920 }
921 if v.Args[0].AuxInt != 0 {
922 break
923 }
924 v.reset(OpConst8)
925 v.AuxInt = 0
926 return true
927 }
Keith Randalla347ab72015-10-26 21:49:31 -0700928 return false
929}
Keith Randall02f4d0a2015-11-02 08:10:26 -0800930func rewriteValuegeneric_OpArg(v *Value, config *Config) bool {
931 b := v.Block
932 _ = b
933 // match: (Arg {n} [off])
934 // cond: v.Type.IsString()
935 // result: (StringMake (Arg <config.fe.TypeBytePtr()> {n} [off]) (Arg <config.fe.TypeInt()> {n} [off+config.PtrSize]))
Alexandru Moșoi05434472016-02-04 19:52:10 +0100936 for {
Keith Randall02f4d0a2015-11-02 08:10:26 -0800937 n := v.Aux
938 off := v.AuxInt
939 if !(v.Type.IsString()) {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100940 break
Keith Randall02f4d0a2015-11-02 08:10:26 -0800941 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100942 v.reset(OpStringMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +0100943 v0 := b.NewValue0(v.Line, OpArg, config.fe.TypeBytePtr())
Keith Randall02f4d0a2015-11-02 08:10:26 -0800944 v0.Aux = n
945 v0.AuxInt = off
946 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +0100947 v1 := b.NewValue0(v.Line, OpArg, config.fe.TypeInt())
Keith Randall02f4d0a2015-11-02 08:10:26 -0800948 v1.Aux = n
949 v1.AuxInt = off + config.PtrSize
950 v.AddArg(v1)
951 return true
952 }
Keith Randall02f4d0a2015-11-02 08:10:26 -0800953 // match: (Arg {n} [off])
954 // cond: v.Type.IsSlice()
955 // result: (SliceMake (Arg <config.fe.TypeBytePtr()> {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 +0100956 for {
Keith Randall02f4d0a2015-11-02 08:10:26 -0800957 n := v.Aux
958 off := v.AuxInt
959 if !(v.Type.IsSlice()) {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100960 break
Keith Randall02f4d0a2015-11-02 08:10:26 -0800961 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100962 v.reset(OpSliceMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +0100963 v0 := b.NewValue0(v.Line, OpArg, config.fe.TypeBytePtr())
Keith Randall02f4d0a2015-11-02 08:10:26 -0800964 v0.Aux = n
965 v0.AuxInt = off
966 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +0100967 v1 := b.NewValue0(v.Line, OpArg, config.fe.TypeInt())
Keith Randall02f4d0a2015-11-02 08:10:26 -0800968 v1.Aux = n
969 v1.AuxInt = off + config.PtrSize
970 v.AddArg(v1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +0100971 v2 := b.NewValue0(v.Line, OpArg, config.fe.TypeInt())
Keith Randall02f4d0a2015-11-02 08:10:26 -0800972 v2.Aux = n
973 v2.AuxInt = off + 2*config.PtrSize
974 v.AddArg(v2)
975 return true
976 }
Keith Randall02f4d0a2015-11-02 08:10:26 -0800977 // match: (Arg {n} [off])
978 // cond: v.Type.IsInterface()
979 // result: (IMake (Arg <config.fe.TypeBytePtr()> {n} [off]) (Arg <config.fe.TypeBytePtr()> {n} [off+config.PtrSize]))
Alexandru Moșoi05434472016-02-04 19:52:10 +0100980 for {
Keith Randall02f4d0a2015-11-02 08:10:26 -0800981 n := v.Aux
982 off := v.AuxInt
983 if !(v.Type.IsInterface()) {
Alexandru Moșoi05434472016-02-04 19:52:10 +0100984 break
Keith Randall02f4d0a2015-11-02 08:10:26 -0800985 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +0100986 v.reset(OpIMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +0100987 v0 := b.NewValue0(v.Line, OpArg, config.fe.TypeBytePtr())
Keith Randall02f4d0a2015-11-02 08:10:26 -0800988 v0.Aux = n
989 v0.AuxInt = off
990 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +0100991 v1 := b.NewValue0(v.Line, OpArg, config.fe.TypeBytePtr())
Keith Randall02f4d0a2015-11-02 08:10:26 -0800992 v1.Aux = n
993 v1.AuxInt = off + config.PtrSize
994 v.AddArg(v1)
995 return true
996 }
Keith Randall02f4d0a2015-11-02 08:10:26 -0800997 // match: (Arg {n} [off])
998 // cond: v.Type.IsComplex() && v.Type.Size() == 16
999 // result: (ComplexMake (Arg <config.fe.TypeFloat64()> {n} [off]) (Arg <config.fe.TypeFloat64()> {n} [off+8]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001000 for {
Keith Randall02f4d0a2015-11-02 08:10:26 -08001001 n := v.Aux
1002 off := v.AuxInt
1003 if !(v.Type.IsComplex() && v.Type.Size() == 16) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001004 break
Keith Randall02f4d0a2015-11-02 08:10:26 -08001005 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001006 v.reset(OpComplexMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001007 v0 := b.NewValue0(v.Line, OpArg, config.fe.TypeFloat64())
Keith Randall02f4d0a2015-11-02 08:10:26 -08001008 v0.Aux = n
1009 v0.AuxInt = off
1010 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001011 v1 := b.NewValue0(v.Line, OpArg, config.fe.TypeFloat64())
Keith Randall02f4d0a2015-11-02 08:10:26 -08001012 v1.Aux = n
1013 v1.AuxInt = off + 8
1014 v.AddArg(v1)
1015 return true
1016 }
Keith Randall02f4d0a2015-11-02 08:10:26 -08001017 // match: (Arg {n} [off])
1018 // cond: v.Type.IsComplex() && v.Type.Size() == 8
1019 // result: (ComplexMake (Arg <config.fe.TypeFloat32()> {n} [off]) (Arg <config.fe.TypeFloat32()> {n} [off+4]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001020 for {
Keith Randall02f4d0a2015-11-02 08:10:26 -08001021 n := v.Aux
1022 off := v.AuxInt
1023 if !(v.Type.IsComplex() && v.Type.Size() == 8) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001024 break
Keith Randall02f4d0a2015-11-02 08:10:26 -08001025 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001026 v.reset(OpComplexMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001027 v0 := b.NewValue0(v.Line, OpArg, config.fe.TypeFloat32())
Keith Randall02f4d0a2015-11-02 08:10:26 -08001028 v0.Aux = n
1029 v0.AuxInt = off
1030 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001031 v1 := b.NewValue0(v.Line, OpArg, config.fe.TypeFloat32())
Keith Randall02f4d0a2015-11-02 08:10:26 -08001032 v1.Aux = n
1033 v1.AuxInt = off + 4
1034 v.AddArg(v1)
1035 return true
1036 }
Keith Randalla734bbc2016-01-11 21:05:33 -08001037 // match: (Arg <t>)
1038 // cond: t.IsStruct() && t.NumFields() == 0 && config.fe.CanSSA(t)
1039 // result: (StructMake0)
Alexandru Moșoi05434472016-02-04 19:52:10 +01001040 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08001041 t := v.Type
1042 if !(t.IsStruct() && t.NumFields() == 0 && config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001043 break
Keith Randalla734bbc2016-01-11 21:05:33 -08001044 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001045 v.reset(OpStructMake0)
Keith Randalla734bbc2016-01-11 21:05:33 -08001046 return true
1047 }
Keith Randalla734bbc2016-01-11 21:05:33 -08001048 // match: (Arg <t> {n} [off])
1049 // cond: t.IsStruct() && t.NumFields() == 1 && config.fe.CanSSA(t)
1050 // result: (StructMake1 (Arg <t.FieldType(0)> {n} [off+t.FieldOff(0)]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001051 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08001052 t := v.Type
1053 n := v.Aux
1054 off := v.AuxInt
1055 if !(t.IsStruct() && t.NumFields() == 1 && config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001056 break
Keith Randalla734bbc2016-01-11 21:05:33 -08001057 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001058 v.reset(OpStructMake1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001059 v0 := b.NewValue0(v.Line, OpArg, t.FieldType(0))
Keith Randalla734bbc2016-01-11 21:05:33 -08001060 v0.Aux = n
1061 v0.AuxInt = off + t.FieldOff(0)
1062 v.AddArg(v0)
1063 return true
1064 }
Keith Randalla734bbc2016-01-11 21:05:33 -08001065 // match: (Arg <t> {n} [off])
1066 // cond: t.IsStruct() && t.NumFields() == 2 && config.fe.CanSSA(t)
1067 // 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 +01001068 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08001069 t := v.Type
1070 n := v.Aux
1071 off := v.AuxInt
1072 if !(t.IsStruct() && t.NumFields() == 2 && config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001073 break
Keith Randalla734bbc2016-01-11 21:05:33 -08001074 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001075 v.reset(OpStructMake2)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001076 v0 := b.NewValue0(v.Line, OpArg, t.FieldType(0))
Keith Randalla734bbc2016-01-11 21:05:33 -08001077 v0.Aux = n
1078 v0.AuxInt = off + t.FieldOff(0)
1079 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001080 v1 := b.NewValue0(v.Line, OpArg, t.FieldType(1))
Keith Randalla734bbc2016-01-11 21:05:33 -08001081 v1.Aux = n
1082 v1.AuxInt = off + t.FieldOff(1)
1083 v.AddArg(v1)
1084 return true
1085 }
Keith Randalla734bbc2016-01-11 21:05:33 -08001086 // match: (Arg <t> {n} [off])
1087 // cond: t.IsStruct() && t.NumFields() == 3 && config.fe.CanSSA(t)
1088 // 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 +01001089 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08001090 t := v.Type
1091 n := v.Aux
1092 off := v.AuxInt
1093 if !(t.IsStruct() && t.NumFields() == 3 && config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001094 break
Keith Randalla734bbc2016-01-11 21:05:33 -08001095 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001096 v.reset(OpStructMake3)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001097 v0 := b.NewValue0(v.Line, OpArg, t.FieldType(0))
Keith Randalla734bbc2016-01-11 21:05:33 -08001098 v0.Aux = n
1099 v0.AuxInt = off + t.FieldOff(0)
1100 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001101 v1 := b.NewValue0(v.Line, OpArg, t.FieldType(1))
Keith Randalla734bbc2016-01-11 21:05:33 -08001102 v1.Aux = n
1103 v1.AuxInt = off + t.FieldOff(1)
1104 v.AddArg(v1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001105 v2 := b.NewValue0(v.Line, OpArg, t.FieldType(2))
Keith Randalla734bbc2016-01-11 21:05:33 -08001106 v2.Aux = n
1107 v2.AuxInt = off + t.FieldOff(2)
1108 v.AddArg(v2)
1109 return true
1110 }
Keith Randalla734bbc2016-01-11 21:05:33 -08001111 // match: (Arg <t> {n} [off])
1112 // cond: t.IsStruct() && t.NumFields() == 4 && config.fe.CanSSA(t)
1113 // 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 +01001114 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08001115 t := v.Type
1116 n := v.Aux
1117 off := v.AuxInt
1118 if !(t.IsStruct() && t.NumFields() == 4 && config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001119 break
Keith Randalla734bbc2016-01-11 21:05:33 -08001120 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001121 v.reset(OpStructMake4)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001122 v0 := b.NewValue0(v.Line, OpArg, t.FieldType(0))
Keith Randalla734bbc2016-01-11 21:05:33 -08001123 v0.Aux = n
1124 v0.AuxInt = off + t.FieldOff(0)
1125 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001126 v1 := b.NewValue0(v.Line, OpArg, t.FieldType(1))
Keith Randalla734bbc2016-01-11 21:05:33 -08001127 v1.Aux = n
1128 v1.AuxInt = off + t.FieldOff(1)
1129 v.AddArg(v1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001130 v2 := b.NewValue0(v.Line, OpArg, t.FieldType(2))
Keith Randalla734bbc2016-01-11 21:05:33 -08001131 v2.Aux = n
1132 v2.AuxInt = off + t.FieldOff(2)
1133 v.AddArg(v2)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001134 v3 := b.NewValue0(v.Line, OpArg, t.FieldType(3))
Keith Randalla734bbc2016-01-11 21:05:33 -08001135 v3.Aux = n
1136 v3.AuxInt = off + t.FieldOff(3)
1137 v.AddArg(v3)
1138 return true
1139 }
Keith Randall02f4d0a2015-11-02 08:10:26 -08001140 return false
1141}
Keith Randalla347ab72015-10-26 21:49:31 -07001142func rewriteValuegeneric_OpArrayIndex(v *Value, config *Config) bool {
1143 b := v.Block
1144 _ = b
Keith Randall62ac1072016-03-01 15:59:15 -08001145 // match: (ArrayIndex <t> [0] (Load ptr mem))
1146 // cond:
1147 // result: @v.Args[0].Block (Load <t> ptr mem)
Alexandru Moșoi05434472016-02-04 19:52:10 +01001148 for {
Keith Randall62ac1072016-03-01 15:59:15 -08001149 t := v.Type
1150 if v.AuxInt != 0 {
1151 break
1152 }
Keith Randalla347ab72015-10-26 21:49:31 -07001153 if v.Args[0].Op != OpLoad {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001154 break
Keith Randalla347ab72015-10-26 21:49:31 -07001155 }
1156 ptr := v.Args[0].Args[0]
1157 mem := v.Args[0].Args[1]
Keith Randall62ac1072016-03-01 15:59:15 -08001158 b = v.Args[0].Block
1159 v0 := b.NewValue0(v.Line, OpLoad, t)
1160 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07001161 v.AddArg(v0)
Keith Randall62ac1072016-03-01 15:59:15 -08001162 v0.AddArg(ptr)
1163 v0.AddArg(mem)
Keith Randalla347ab72015-10-26 21:49:31 -07001164 return true
1165 }
Keith Randalla347ab72015-10-26 21:49:31 -07001166 return false
1167}
1168func rewriteValuegeneric_OpCom16(v *Value, config *Config) bool {
1169 b := v.Block
1170 _ = b
1171 // match: (Com16 (Com16 x))
1172 // cond:
1173 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01001174 for {
Keith Randalla347ab72015-10-26 21:49:31 -07001175 if v.Args[0].Op != OpCom16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001176 break
Keith Randalla347ab72015-10-26 21:49:31 -07001177 }
1178 x := v.Args[0].Args[0]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001179 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07001180 v.Type = x.Type
1181 v.AddArg(x)
1182 return true
1183 }
Keith Randalla347ab72015-10-26 21:49:31 -07001184 return false
1185}
1186func rewriteValuegeneric_OpCom32(v *Value, config *Config) bool {
1187 b := v.Block
1188 _ = b
1189 // match: (Com32 (Com32 x))
1190 // cond:
1191 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01001192 for {
Keith Randalla347ab72015-10-26 21:49:31 -07001193 if v.Args[0].Op != OpCom32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001194 break
Keith Randalla347ab72015-10-26 21:49:31 -07001195 }
1196 x := v.Args[0].Args[0]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001197 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07001198 v.Type = x.Type
1199 v.AddArg(x)
1200 return true
1201 }
Keith Randalla347ab72015-10-26 21:49:31 -07001202 return false
1203}
1204func rewriteValuegeneric_OpCom64(v *Value, config *Config) bool {
1205 b := v.Block
1206 _ = b
1207 // match: (Com64 (Com64 x))
1208 // cond:
1209 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01001210 for {
Keith Randalla347ab72015-10-26 21:49:31 -07001211 if v.Args[0].Op != OpCom64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001212 break
Keith Randalla347ab72015-10-26 21:49:31 -07001213 }
1214 x := v.Args[0].Args[0]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001215 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07001216 v.Type = x.Type
1217 v.AddArg(x)
1218 return true
1219 }
Keith Randalla347ab72015-10-26 21:49:31 -07001220 return false
1221}
1222func rewriteValuegeneric_OpCom8(v *Value, config *Config) bool {
1223 b := v.Block
1224 _ = b
1225 // match: (Com8 (Com8 x))
1226 // cond:
1227 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01001228 for {
Keith Randalla347ab72015-10-26 21:49:31 -07001229 if v.Args[0].Op != OpCom8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001230 break
Keith Randalla347ab72015-10-26 21:49:31 -07001231 }
1232 x := v.Args[0].Args[0]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001233 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07001234 v.Type = x.Type
1235 v.AddArg(x)
1236 return true
1237 }
Keith Randalla347ab72015-10-26 21:49:31 -07001238 return false
1239}
1240func rewriteValuegeneric_OpComplexImag(v *Value, config *Config) bool {
1241 b := v.Block
1242 _ = b
1243 // match: (ComplexImag (ComplexMake _ imag ))
1244 // cond:
1245 // result: imag
Alexandru Moșoi05434472016-02-04 19:52:10 +01001246 for {
Keith Randalla347ab72015-10-26 21:49:31 -07001247 if v.Args[0].Op != OpComplexMake {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001248 break
Keith Randalla347ab72015-10-26 21:49:31 -07001249 }
1250 imag := v.Args[0].Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001251 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07001252 v.Type = imag.Type
1253 v.AddArg(imag)
1254 return true
1255 }
Keith Randalla347ab72015-10-26 21:49:31 -07001256 return false
1257}
1258func rewriteValuegeneric_OpComplexReal(v *Value, config *Config) bool {
1259 b := v.Block
1260 _ = b
1261 // match: (ComplexReal (ComplexMake real _ ))
1262 // cond:
1263 // result: real
Alexandru Moșoi05434472016-02-04 19:52:10 +01001264 for {
Keith Randalla347ab72015-10-26 21:49:31 -07001265 if v.Args[0].Op != OpComplexMake {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001266 break
Keith Randalla347ab72015-10-26 21:49:31 -07001267 }
1268 real := v.Args[0].Args[0]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001269 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07001270 v.Type = real.Type
1271 v.AddArg(real)
1272 return true
1273 }
Keith Randalla347ab72015-10-26 21:49:31 -07001274 return false
1275}
1276func rewriteValuegeneric_OpConstInterface(v *Value, config *Config) bool {
1277 b := v.Block
1278 _ = b
1279 // match: (ConstInterface)
1280 // cond:
1281 // result: (IMake (ConstNil <config.fe.TypeBytePtr()>) (ConstNil <config.fe.TypeBytePtr()>))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001282 for {
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001283 v.reset(OpIMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001284 v0 := b.NewValue0(v.Line, OpConstNil, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07001285 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001286 v1 := b.NewValue0(v.Line, OpConstNil, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07001287 v.AddArg(v1)
1288 return true
1289 }
Keith Randalla347ab72015-10-26 21:49:31 -07001290 return false
1291}
1292func rewriteValuegeneric_OpConstSlice(v *Value, config *Config) bool {
1293 b := v.Block
1294 _ = b
1295 // match: (ConstSlice)
Keith Randall582baae2015-11-02 21:28:13 -08001296 // cond: config.PtrSize == 4
1297 // result: (SliceMake (ConstNil <config.fe.TypeBytePtr()>) (Const32 <config.fe.TypeInt()> [0]) (Const32 <config.fe.TypeInt()> [0]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001298 for {
Keith Randall582baae2015-11-02 21:28:13 -08001299 if !(config.PtrSize == 4) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001300 break
Keith Randall582baae2015-11-02 21:28:13 -08001301 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001302 v.reset(OpSliceMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001303 v0 := b.NewValue0(v.Line, OpConstNil, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07001304 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001305 v1 := b.NewValue0(v.Line, OpConst32, config.fe.TypeInt())
Keith Randalla347ab72015-10-26 21:49:31 -07001306 v1.AuxInt = 0
Keith Randalla347ab72015-10-26 21:49:31 -07001307 v.AddArg(v1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001308 v2 := b.NewValue0(v.Line, OpConst32, config.fe.TypeInt())
Keith Randalla347ab72015-10-26 21:49:31 -07001309 v2.AuxInt = 0
Keith Randalla347ab72015-10-26 21:49:31 -07001310 v.AddArg(v2)
1311 return true
1312 }
Keith Randall582baae2015-11-02 21:28:13 -08001313 // match: (ConstSlice)
1314 // cond: config.PtrSize == 8
1315 // result: (SliceMake (ConstNil <config.fe.TypeBytePtr()>) (Const64 <config.fe.TypeInt()> [0]) (Const64 <config.fe.TypeInt()> [0]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001316 for {
Keith Randall582baae2015-11-02 21:28:13 -08001317 if !(config.PtrSize == 8) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001318 break
Keith Randall582baae2015-11-02 21:28:13 -08001319 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001320 v.reset(OpSliceMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001321 v0 := b.NewValue0(v.Line, OpConstNil, config.fe.TypeBytePtr())
Keith Randall582baae2015-11-02 21:28:13 -08001322 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001323 v1 := b.NewValue0(v.Line, OpConst64, config.fe.TypeInt())
Keith Randall582baae2015-11-02 21:28:13 -08001324 v1.AuxInt = 0
1325 v.AddArg(v1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001326 v2 := b.NewValue0(v.Line, OpConst64, config.fe.TypeInt())
Keith Randall582baae2015-11-02 21:28:13 -08001327 v2.AuxInt = 0
1328 v.AddArg(v2)
1329 return true
1330 }
Keith Randalla347ab72015-10-26 21:49:31 -07001331 return false
1332}
1333func rewriteValuegeneric_OpConstString(v *Value, config *Config) bool {
1334 b := v.Block
1335 _ = b
1336 // match: (ConstString {s})
Keith Randall170589e2015-11-09 20:54:34 -08001337 // cond: config.PtrSize == 4 && s.(string) == ""
1338 // result: (StringMake (ConstNil) (Const32 <config.fe.TypeInt()> [0]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001339 for {
Keith Randall170589e2015-11-09 20:54:34 -08001340 s := v.Aux
1341 if !(config.PtrSize == 4 && s.(string) == "") {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001342 break
Keith Randall170589e2015-11-09 20:54:34 -08001343 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001344 v.reset(OpStringMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001345 v0 := b.NewValue0(v.Line, OpConstNil, config.fe.TypeBytePtr())
Keith Randall170589e2015-11-09 20:54:34 -08001346 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001347 v1 := b.NewValue0(v.Line, OpConst32, config.fe.TypeInt())
Keith Randall170589e2015-11-09 20:54:34 -08001348 v1.AuxInt = 0
1349 v.AddArg(v1)
1350 return true
1351 }
Keith Randall170589e2015-11-09 20:54:34 -08001352 // match: (ConstString {s})
1353 // cond: config.PtrSize == 8 && s.(string) == ""
1354 // result: (StringMake (ConstNil) (Const64 <config.fe.TypeInt()> [0]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01001355 for {
Keith Randall170589e2015-11-09 20:54:34 -08001356 s := v.Aux
1357 if !(config.PtrSize == 8 && s.(string) == "") {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001358 break
Keith Randall170589e2015-11-09 20:54:34 -08001359 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001360 v.reset(OpStringMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001361 v0 := b.NewValue0(v.Line, OpConstNil, config.fe.TypeBytePtr())
Keith Randall170589e2015-11-09 20:54:34 -08001362 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001363 v1 := b.NewValue0(v.Line, OpConst64, config.fe.TypeInt())
Keith Randall170589e2015-11-09 20:54:34 -08001364 v1.AuxInt = 0
1365 v.AddArg(v1)
1366 return true
1367 }
Keith Randall170589e2015-11-09 20:54:34 -08001368 // match: (ConstString {s})
1369 // cond: config.PtrSize == 4 && s.(string) != ""
Keith Randall582baae2015-11-02 21:28:13 -08001370 // 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 +01001371 for {
Keith Randalla347ab72015-10-26 21:49:31 -07001372 s := v.Aux
Keith Randall170589e2015-11-09 20:54:34 -08001373 if !(config.PtrSize == 4 && s.(string) != "") {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001374 break
Keith Randall582baae2015-11-02 21:28:13 -08001375 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001376 v.reset(OpStringMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001377 v0 := b.NewValue0(v.Line, OpAddr, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07001378 v0.Aux = config.fe.StringData(s.(string))
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001379 v1 := b.NewValue0(v.Line, OpSB, config.fe.TypeUintptr())
Keith Randalla347ab72015-10-26 21:49:31 -07001380 v0.AddArg(v1)
1381 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001382 v2 := b.NewValue0(v.Line, OpConst32, config.fe.TypeInt())
Keith Randalla347ab72015-10-26 21:49:31 -07001383 v2.AuxInt = int64(len(s.(string)))
Keith Randalla347ab72015-10-26 21:49:31 -07001384 v.AddArg(v2)
1385 return true
1386 }
Keith Randall582baae2015-11-02 21:28:13 -08001387 // match: (ConstString {s})
Keith Randall170589e2015-11-09 20:54:34 -08001388 // cond: config.PtrSize == 8 && s.(string) != ""
Keith Randall582baae2015-11-02 21:28:13 -08001389 // 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 +01001390 for {
Keith Randall582baae2015-11-02 21:28:13 -08001391 s := v.Aux
Keith Randall170589e2015-11-09 20:54:34 -08001392 if !(config.PtrSize == 8 && s.(string) != "") {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001393 break
Keith Randall582baae2015-11-02 21:28:13 -08001394 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001395 v.reset(OpStringMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001396 v0 := b.NewValue0(v.Line, OpAddr, config.fe.TypeBytePtr())
Keith Randall582baae2015-11-02 21:28:13 -08001397 v0.Aux = config.fe.StringData(s.(string))
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001398 v1 := b.NewValue0(v.Line, OpSB, config.fe.TypeUintptr())
Keith Randall582baae2015-11-02 21:28:13 -08001399 v0.AddArg(v1)
1400 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01001401 v2 := b.NewValue0(v.Line, OpConst64, config.fe.TypeInt())
Keith Randall582baae2015-11-02 21:28:13 -08001402 v2.AuxInt = int64(len(s.(string)))
1403 v.AddArg(v2)
1404 return true
1405 }
Keith Randalla347ab72015-10-26 21:49:31 -07001406 return false
1407}
1408func rewriteValuegeneric_OpConvert(v *Value, config *Config) bool {
1409 b := v.Block
1410 _ = b
Keith Randall7807bda2015-11-10 15:35:36 -08001411 // match: (Convert (Add64 (Convert ptr mem) off) mem)
Keith Randalla347ab72015-10-26 21:49:31 -07001412 // cond:
1413 // result: (Add64 ptr off)
Alexandru Moșoi05434472016-02-04 19:52:10 +01001414 for {
Keith Randalla347ab72015-10-26 21:49:31 -07001415 if v.Args[0].Op != OpAdd64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001416 break
Keith Randalla347ab72015-10-26 21:49:31 -07001417 }
1418 if v.Args[0].Args[0].Op != OpConvert {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001419 break
Keith Randalla347ab72015-10-26 21:49:31 -07001420 }
1421 ptr := v.Args[0].Args[0].Args[0]
Keith Randall7807bda2015-11-10 15:35:36 -08001422 mem := v.Args[0].Args[0].Args[1]
Keith Randalla347ab72015-10-26 21:49:31 -07001423 off := v.Args[0].Args[1]
Keith Randall7807bda2015-11-10 15:35:36 -08001424 if v.Args[1] != mem {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001425 break
Keith Randall7807bda2015-11-10 15:35:36 -08001426 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001427 v.reset(OpAdd64)
Keith Randalla347ab72015-10-26 21:49:31 -07001428 v.AddArg(ptr)
1429 v.AddArg(off)
1430 return true
1431 }
Alexandru Moșoid337e552016-02-23 21:48:33 +01001432 // match: (Convert (Add64 off (Convert ptr mem)) mem)
1433 // cond:
1434 // result: (Add64 ptr off)
1435 for {
1436 if v.Args[0].Op != OpAdd64 {
1437 break
1438 }
1439 off := v.Args[0].Args[0]
1440 if v.Args[0].Args[1].Op != OpConvert {
1441 break
1442 }
1443 ptr := v.Args[0].Args[1].Args[0]
1444 mem := v.Args[0].Args[1].Args[1]
1445 if v.Args[1] != mem {
1446 break
1447 }
1448 v.reset(OpAdd64)
1449 v.AddArg(ptr)
1450 v.AddArg(off)
1451 return true
1452 }
Keith Randall7807bda2015-11-10 15:35:36 -08001453 // match: (Convert (Convert ptr mem) mem)
1454 // cond:
1455 // result: ptr
Alexandru Moșoi05434472016-02-04 19:52:10 +01001456 for {
Keith Randall7807bda2015-11-10 15:35:36 -08001457 if v.Args[0].Op != OpConvert {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001458 break
Keith Randall7807bda2015-11-10 15:35:36 -08001459 }
1460 ptr := v.Args[0].Args[0]
1461 mem := v.Args[0].Args[1]
1462 if v.Args[1] != mem {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001463 break
Keith Randall7807bda2015-11-10 15:35:36 -08001464 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001465 v.reset(OpCopy)
Keith Randall7807bda2015-11-10 15:35:36 -08001466 v.Type = ptr.Type
1467 v.AddArg(ptr)
1468 return true
1469 }
Keith Randalla347ab72015-10-26 21:49:31 -07001470 return false
1471}
Keith Randalla3055af2016-02-05 20:26:18 -08001472func rewriteValuegeneric_OpDiv64(v *Value, config *Config) bool {
1473 b := v.Block
1474 _ = b
1475 // match: (Div64 <t> x (Const64 [c]))
1476 // cond: c > 0 && smagic64ok(c) && smagic64m(c) > 0
1477 // result: (Sub64 <t> (Rsh64x64 <t> (Hmul64 <t> (Const64 <t> [smagic64m(c)]) x) (Const64 <t> [smagic64s(c)])) (Rsh64x64 <t> x (Const64 <t> [63])))
1478 for {
1479 t := v.Type
1480 x := v.Args[0]
1481 if v.Args[1].Op != OpConst64 {
1482 break
1483 }
1484 c := v.Args[1].AuxInt
1485 if !(c > 0 && smagic64ok(c) && smagic64m(c) > 0) {
1486 break
1487 }
1488 v.reset(OpSub64)
1489 v.Type = t
1490 v0 := b.NewValue0(v.Line, OpRsh64x64, t)
1491 v1 := b.NewValue0(v.Line, OpHmul64, t)
1492 v2 := b.NewValue0(v.Line, OpConst64, t)
1493 v2.AuxInt = smagic64m(c)
1494 v1.AddArg(v2)
1495 v1.AddArg(x)
1496 v0.AddArg(v1)
1497 v3 := b.NewValue0(v.Line, OpConst64, t)
1498 v3.AuxInt = smagic64s(c)
1499 v0.AddArg(v3)
1500 v.AddArg(v0)
1501 v4 := b.NewValue0(v.Line, OpRsh64x64, t)
1502 v4.AddArg(x)
1503 v5 := b.NewValue0(v.Line, OpConst64, t)
1504 v5.AuxInt = 63
1505 v4.AddArg(v5)
1506 v.AddArg(v4)
1507 return true
1508 }
1509 // match: (Div64 <t> x (Const64 [c]))
1510 // cond: c > 0 && smagic64ok(c) && smagic64m(c) < 0
1511 // 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])))
1512 for {
1513 t := v.Type
1514 x := v.Args[0]
1515 if v.Args[1].Op != OpConst64 {
1516 break
1517 }
1518 c := v.Args[1].AuxInt
1519 if !(c > 0 && smagic64ok(c) && smagic64m(c) < 0) {
1520 break
1521 }
1522 v.reset(OpSub64)
1523 v.Type = t
1524 v0 := b.NewValue0(v.Line, OpRsh64x64, t)
1525 v1 := b.NewValue0(v.Line, OpAdd64, t)
1526 v2 := b.NewValue0(v.Line, OpHmul64, t)
1527 v3 := b.NewValue0(v.Line, OpConst64, t)
1528 v3.AuxInt = smagic64m(c)
1529 v2.AddArg(v3)
1530 v2.AddArg(x)
1531 v1.AddArg(v2)
1532 v1.AddArg(x)
1533 v0.AddArg(v1)
1534 v4 := b.NewValue0(v.Line, OpConst64, t)
1535 v4.AuxInt = smagic64s(c)
1536 v0.AddArg(v4)
1537 v.AddArg(v0)
1538 v5 := b.NewValue0(v.Line, OpRsh64x64, t)
1539 v5.AddArg(x)
1540 v6 := b.NewValue0(v.Line, OpConst64, t)
1541 v6.AuxInt = 63
1542 v5.AddArg(v6)
1543 v.AddArg(v5)
1544 return true
1545 }
1546 // match: (Div64 <t> x (Const64 [c]))
1547 // cond: c < 0 && smagic64ok(c) && smagic64m(c) > 0
1548 // result: (Neg64 <t> (Sub64 <t> (Rsh64x64 <t> (Hmul64 <t> (Const64 <t> [smagic64m(c)]) x) (Const64 <t> [smagic64s(c)])) (Rsh64x64 <t> x (Const64 <t> [63]))))
1549 for {
1550 t := v.Type
1551 x := v.Args[0]
1552 if v.Args[1].Op != OpConst64 {
1553 break
1554 }
1555 c := v.Args[1].AuxInt
1556 if !(c < 0 && smagic64ok(c) && smagic64m(c) > 0) {
1557 break
1558 }
1559 v.reset(OpNeg64)
1560 v.Type = t
1561 v0 := b.NewValue0(v.Line, OpSub64, t)
1562 v1 := b.NewValue0(v.Line, OpRsh64x64, t)
1563 v2 := b.NewValue0(v.Line, OpHmul64, t)
1564 v3 := b.NewValue0(v.Line, OpConst64, t)
1565 v3.AuxInt = smagic64m(c)
1566 v2.AddArg(v3)
1567 v2.AddArg(x)
1568 v1.AddArg(v2)
1569 v4 := b.NewValue0(v.Line, OpConst64, t)
1570 v4.AuxInt = smagic64s(c)
1571 v1.AddArg(v4)
1572 v0.AddArg(v1)
1573 v5 := b.NewValue0(v.Line, OpRsh64x64, t)
1574 v5.AddArg(x)
1575 v6 := b.NewValue0(v.Line, OpConst64, t)
1576 v6.AuxInt = 63
1577 v5.AddArg(v6)
1578 v0.AddArg(v5)
1579 v.AddArg(v0)
1580 return true
1581 }
1582 // match: (Div64 <t> x (Const64 [c]))
1583 // cond: c < 0 && smagic64ok(c) && smagic64m(c) < 0
1584 // 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]))))
1585 for {
1586 t := v.Type
1587 x := v.Args[0]
1588 if v.Args[1].Op != OpConst64 {
1589 break
1590 }
1591 c := v.Args[1].AuxInt
1592 if !(c < 0 && smagic64ok(c) && smagic64m(c) < 0) {
1593 break
1594 }
1595 v.reset(OpNeg64)
1596 v.Type = t
1597 v0 := b.NewValue0(v.Line, OpSub64, t)
1598 v1 := b.NewValue0(v.Line, OpRsh64x64, t)
1599 v2 := b.NewValue0(v.Line, OpAdd64, t)
1600 v3 := b.NewValue0(v.Line, OpHmul64, t)
1601 v4 := b.NewValue0(v.Line, OpConst64, t)
1602 v4.AuxInt = smagic64m(c)
1603 v3.AddArg(v4)
1604 v3.AddArg(x)
1605 v2.AddArg(v3)
1606 v2.AddArg(x)
1607 v1.AddArg(v2)
1608 v5 := b.NewValue0(v.Line, OpConst64, t)
1609 v5.AuxInt = smagic64s(c)
1610 v1.AddArg(v5)
1611 v0.AddArg(v1)
1612 v6 := b.NewValue0(v.Line, OpRsh64x64, t)
1613 v6.AddArg(x)
1614 v7 := b.NewValue0(v.Line, OpConst64, t)
1615 v7.AuxInt = 63
1616 v6.AddArg(v7)
1617 v0.AddArg(v6)
1618 v.AddArg(v0)
1619 return true
1620 }
1621 return false
1622}
1623func rewriteValuegeneric_OpDiv64u(v *Value, config *Config) bool {
1624 b := v.Block
1625 _ = b
1626 // match: (Div64u <t> x (Const64 [c]))
1627 // cond: umagic64ok(c) && !umagic64a(c)
1628 // result: (Rsh64Ux64 (Hmul64u <t> (Const64 <t> [umagic64m(c)]) x) (Const64 <t> [umagic64s(c)]))
1629 for {
1630 t := v.Type
1631 x := v.Args[0]
1632 if v.Args[1].Op != OpConst64 {
1633 break
1634 }
1635 c := v.Args[1].AuxInt
1636 if !(umagic64ok(c) && !umagic64a(c)) {
1637 break
1638 }
1639 v.reset(OpRsh64Ux64)
1640 v0 := b.NewValue0(v.Line, OpHmul64u, t)
1641 v1 := b.NewValue0(v.Line, OpConst64, t)
1642 v1.AuxInt = umagic64m(c)
1643 v0.AddArg(v1)
1644 v0.AddArg(x)
1645 v.AddArg(v0)
1646 v2 := b.NewValue0(v.Line, OpConst64, t)
1647 v2.AuxInt = umagic64s(c)
1648 v.AddArg(v2)
1649 return true
1650 }
1651 // match: (Div64u <t> x (Const64 [c]))
1652 // cond: umagic64ok(c) && umagic64a(c)
1653 // result: (Rsh64Ux64 (Avg64u <t> (Hmul64u <t> x (Const64 <t> [umagic64m(c)])) x) (Const64 <t> [umagic64s(c)-1]))
1654 for {
1655 t := v.Type
1656 x := v.Args[0]
1657 if v.Args[1].Op != OpConst64 {
1658 break
1659 }
1660 c := v.Args[1].AuxInt
1661 if !(umagic64ok(c) && umagic64a(c)) {
1662 break
1663 }
1664 v.reset(OpRsh64Ux64)
1665 v0 := b.NewValue0(v.Line, OpAvg64u, t)
1666 v1 := b.NewValue0(v.Line, OpHmul64u, t)
1667 v1.AddArg(x)
1668 v2 := b.NewValue0(v.Line, OpConst64, t)
1669 v2.AuxInt = umagic64m(c)
1670 v1.AddArg(v2)
1671 v0.AddArg(v1)
1672 v0.AddArg(x)
1673 v.AddArg(v0)
1674 v3 := b.NewValue0(v.Line, OpConst64, t)
1675 v3.AuxInt = umagic64s(c) - 1
1676 v.AddArg(v3)
1677 return true
1678 }
1679 return false
1680}
Keith Randalla347ab72015-10-26 21:49:31 -07001681func rewriteValuegeneric_OpEq16(v *Value, config *Config) bool {
1682 b := v.Block
1683 _ = b
1684 // match: (Eq16 x x)
1685 // cond:
1686 // result: (ConstBool [1])
Alexandru Moșoi05434472016-02-04 19:52:10 +01001687 for {
Keith Randalla347ab72015-10-26 21:49:31 -07001688 x := v.Args[0]
1689 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001690 break
Keith Randalla347ab72015-10-26 21:49:31 -07001691 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001692 v.reset(OpConstBool)
Keith Randalla347ab72015-10-26 21:49:31 -07001693 v.AuxInt = 1
1694 return true
1695 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001696 // match: (Eq16 (Const16 <t> [c]) (Add16 (Const16 <t> [d]) x))
1697 // cond:
1698 // result: (Eq16 (Const16 <t> [c-d]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01001699 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001700 if v.Args[0].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001701 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001702 }
1703 t := v.Args[0].Type
1704 c := v.Args[0].AuxInt
1705 if v.Args[1].Op != OpAdd16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001706 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001707 }
1708 if v.Args[1].Args[0].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001709 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001710 }
1711 if v.Args[1].Args[0].Type != v.Args[0].Type {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001712 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001713 }
1714 d := v.Args[1].Args[0].AuxInt
1715 x := v.Args[1].Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001716 v.reset(OpEq16)
Todd Neal93a0b0f2016-02-03 06:21:24 -05001717 v0 := b.NewValue0(v.Line, OpConst16, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001718 v0.AuxInt = c - d
1719 v.AddArg(v0)
1720 v.AddArg(x)
1721 return true
1722 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001723 // match: (Eq16 x (Const16 <t> [c]))
1724 // cond: x.Op != OpConst16
1725 // result: (Eq16 (Const16 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01001726 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001727 x := v.Args[0]
1728 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001729 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001730 }
1731 t := v.Args[1].Type
1732 c := v.Args[1].AuxInt
1733 if !(x.Op != OpConst16) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001734 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001735 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001736 v.reset(OpEq16)
Todd Neal93a0b0f2016-02-03 06:21:24 -05001737 v0 := b.NewValue0(v.Line, OpConst16, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001738 v0.AuxInt = c
1739 v.AddArg(v0)
1740 v.AddArg(x)
1741 return true
1742 }
Todd Nealcdc36252015-10-27 17:46:53 -05001743 // match: (Eq16 (Const16 [c]) (Const16 [d]))
1744 // cond:
1745 // result: (ConstBool [b2i(int16(c) == int16(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01001746 for {
Todd Nealcdc36252015-10-27 17:46:53 -05001747 if v.Args[0].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001748 break
Todd Nealcdc36252015-10-27 17:46:53 -05001749 }
1750 c := v.Args[0].AuxInt
1751 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001752 break
Todd Nealcdc36252015-10-27 17:46:53 -05001753 }
1754 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001755 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05001756 v.AuxInt = b2i(int16(c) == int16(d))
1757 return true
1758 }
Keith Randalla347ab72015-10-26 21:49:31 -07001759 return false
1760}
1761func rewriteValuegeneric_OpEq32(v *Value, config *Config) bool {
1762 b := v.Block
1763 _ = b
1764 // match: (Eq32 x x)
1765 // cond:
1766 // result: (ConstBool [1])
Alexandru Moșoi05434472016-02-04 19:52:10 +01001767 for {
Keith Randalla347ab72015-10-26 21:49:31 -07001768 x := v.Args[0]
1769 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001770 break
Keith Randalla347ab72015-10-26 21:49:31 -07001771 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001772 v.reset(OpConstBool)
Keith Randalla347ab72015-10-26 21:49:31 -07001773 v.AuxInt = 1
1774 return true
1775 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001776 // match: (Eq32 (Const32 <t> [c]) (Add32 (Const32 <t> [d]) x))
1777 // cond:
1778 // result: (Eq32 (Const32 <t> [c-d]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01001779 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001780 if v.Args[0].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001781 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001782 }
1783 t := v.Args[0].Type
1784 c := v.Args[0].AuxInt
1785 if v.Args[1].Op != OpAdd32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001786 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001787 }
1788 if v.Args[1].Args[0].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001789 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001790 }
1791 if v.Args[1].Args[0].Type != v.Args[0].Type {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001792 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001793 }
1794 d := v.Args[1].Args[0].AuxInt
1795 x := v.Args[1].Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001796 v.reset(OpEq32)
Todd Neal93a0b0f2016-02-03 06:21:24 -05001797 v0 := b.NewValue0(v.Line, OpConst32, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001798 v0.AuxInt = c - d
1799 v.AddArg(v0)
1800 v.AddArg(x)
1801 return true
1802 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001803 // match: (Eq32 x (Const32 <t> [c]))
1804 // cond: x.Op != OpConst32
1805 // result: (Eq32 (Const32 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01001806 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001807 x := v.Args[0]
1808 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001809 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001810 }
1811 t := v.Args[1].Type
1812 c := v.Args[1].AuxInt
1813 if !(x.Op != OpConst32) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001814 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001815 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001816 v.reset(OpEq32)
Todd Neal93a0b0f2016-02-03 06:21:24 -05001817 v0 := b.NewValue0(v.Line, OpConst32, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001818 v0.AuxInt = c
1819 v.AddArg(v0)
1820 v.AddArg(x)
1821 return true
1822 }
Todd Nealcdc36252015-10-27 17:46:53 -05001823 // match: (Eq32 (Const32 [c]) (Const32 [d]))
1824 // cond:
1825 // result: (ConstBool [b2i(int32(c) == int32(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01001826 for {
Todd Nealcdc36252015-10-27 17:46:53 -05001827 if v.Args[0].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001828 break
Todd Nealcdc36252015-10-27 17:46:53 -05001829 }
1830 c := v.Args[0].AuxInt
1831 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001832 break
Todd Nealcdc36252015-10-27 17:46:53 -05001833 }
1834 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001835 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05001836 v.AuxInt = b2i(int32(c) == int32(d))
1837 return true
1838 }
Keith Randalla347ab72015-10-26 21:49:31 -07001839 return false
1840}
1841func rewriteValuegeneric_OpEq64(v *Value, config *Config) bool {
1842 b := v.Block
1843 _ = b
1844 // match: (Eq64 x x)
1845 // cond:
1846 // result: (ConstBool [1])
Alexandru Moșoi05434472016-02-04 19:52:10 +01001847 for {
Keith Randalla347ab72015-10-26 21:49:31 -07001848 x := v.Args[0]
1849 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001850 break
Keith Randalla347ab72015-10-26 21:49:31 -07001851 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001852 v.reset(OpConstBool)
Keith Randalla347ab72015-10-26 21:49:31 -07001853 v.AuxInt = 1
1854 return true
1855 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001856 // match: (Eq64 (Const64 <t> [c]) (Add64 (Const64 <t> [d]) x))
1857 // cond:
1858 // result: (Eq64 (Const64 <t> [c-d]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01001859 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001860 if v.Args[0].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001861 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001862 }
1863 t := v.Args[0].Type
1864 c := v.Args[0].AuxInt
1865 if v.Args[1].Op != OpAdd64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001866 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001867 }
1868 if v.Args[1].Args[0].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001869 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001870 }
1871 if v.Args[1].Args[0].Type != v.Args[0].Type {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001872 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001873 }
1874 d := v.Args[1].Args[0].AuxInt
1875 x := v.Args[1].Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001876 v.reset(OpEq64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05001877 v0 := b.NewValue0(v.Line, OpConst64, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001878 v0.AuxInt = c - d
1879 v.AddArg(v0)
1880 v.AddArg(x)
1881 return true
1882 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001883 // match: (Eq64 x (Const64 <t> [c]))
1884 // cond: x.Op != OpConst64
1885 // result: (Eq64 (Const64 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01001886 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001887 x := v.Args[0]
1888 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001889 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001890 }
1891 t := v.Args[1].Type
1892 c := v.Args[1].AuxInt
1893 if !(x.Op != OpConst64) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001894 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001895 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001896 v.reset(OpEq64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05001897 v0 := b.NewValue0(v.Line, OpConst64, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001898 v0.AuxInt = c
1899 v.AddArg(v0)
1900 v.AddArg(x)
1901 return true
1902 }
Todd Nealcdc36252015-10-27 17:46:53 -05001903 // match: (Eq64 (Const64 [c]) (Const64 [d]))
1904 // cond:
1905 // result: (ConstBool [b2i(int64(c) == int64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01001906 for {
Todd Nealcdc36252015-10-27 17:46:53 -05001907 if v.Args[0].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001908 break
Todd Nealcdc36252015-10-27 17:46:53 -05001909 }
1910 c := v.Args[0].AuxInt
1911 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001912 break
Todd Nealcdc36252015-10-27 17:46:53 -05001913 }
1914 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001915 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05001916 v.AuxInt = b2i(int64(c) == int64(d))
1917 return true
1918 }
Keith Randalla347ab72015-10-26 21:49:31 -07001919 return false
1920}
1921func rewriteValuegeneric_OpEq8(v *Value, config *Config) bool {
1922 b := v.Block
1923 _ = b
1924 // match: (Eq8 x x)
1925 // cond:
1926 // result: (ConstBool [1])
Alexandru Moșoi05434472016-02-04 19:52:10 +01001927 for {
Keith Randalla347ab72015-10-26 21:49:31 -07001928 x := v.Args[0]
1929 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001930 break
Keith Randalla347ab72015-10-26 21:49:31 -07001931 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01001932 v.reset(OpConstBool)
Keith Randalla347ab72015-10-26 21:49:31 -07001933 v.AuxInt = 1
1934 return true
1935 }
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +01001936 // match: (Eq8 (ConstBool [c]) (ConstBool [d]))
1937 // cond:
1938 // result: (ConstBool [b2i((int8(c) != 0) == (int8(d) != 0))])
1939 for {
1940 if v.Args[0].Op != OpConstBool {
1941 break
1942 }
1943 c := v.Args[0].AuxInt
1944 if v.Args[1].Op != OpConstBool {
1945 break
1946 }
1947 d := v.Args[1].AuxInt
1948 v.reset(OpConstBool)
1949 v.AuxInt = b2i((int8(c) != 0) == (int8(d) != 0))
1950 return true
1951 }
1952 // match: (Eq8 (ConstBool [0]) x)
1953 // cond:
1954 // result: (Not x)
1955 for {
1956 if v.Args[0].Op != OpConstBool {
1957 break
1958 }
1959 if v.Args[0].AuxInt != 0 {
1960 break
1961 }
1962 x := v.Args[1]
1963 v.reset(OpNot)
1964 v.AddArg(x)
1965 return true
1966 }
1967 // match: (Eq8 (ConstBool [1]) x)
1968 // cond:
1969 // result: x
1970 for {
1971 if v.Args[0].Op != OpConstBool {
1972 break
1973 }
1974 if v.Args[0].AuxInt != 1 {
1975 break
1976 }
1977 x := v.Args[1]
1978 v.reset(OpCopy)
1979 v.Type = x.Type
1980 v.AddArg(x)
1981 return true
1982 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001983 // match: (Eq8 (Const8 <t> [c]) (Add8 (Const8 <t> [d]) x))
1984 // cond:
1985 // result: (Eq8 (Const8 <t> [c-d]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01001986 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001987 if v.Args[0].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001988 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001989 }
1990 t := v.Args[0].Type
1991 c := v.Args[0].AuxInt
1992 if v.Args[1].Op != OpAdd8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001993 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001994 }
1995 if v.Args[1].Args[0].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001996 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01001997 }
1998 if v.Args[1].Args[0].Type != v.Args[0].Type {
Alexandru Moșoi05434472016-02-04 19:52:10 +01001999 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002000 }
2001 d := v.Args[1].Args[0].AuxInt
2002 x := v.Args[1].Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002003 v.reset(OpEq8)
Todd Neal93a0b0f2016-02-03 06:21:24 -05002004 v0 := b.NewValue0(v.Line, OpConst8, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002005 v0.AuxInt = c - d
2006 v.AddArg(v0)
2007 v.AddArg(x)
2008 return true
2009 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002010 // match: (Eq8 x (Const8 <t> [c]))
2011 // cond: x.Op != OpConst8
2012 // result: (Eq8 (Const8 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01002013 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002014 x := v.Args[0]
2015 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002016 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002017 }
2018 t := v.Args[1].Type
2019 c := v.Args[1].AuxInt
2020 if !(x.Op != OpConst8) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002021 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002022 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002023 v.reset(OpEq8)
Todd Neal93a0b0f2016-02-03 06:21:24 -05002024 v0 := b.NewValue0(v.Line, OpConst8, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01002025 v0.AuxInt = c
2026 v.AddArg(v0)
2027 v.AddArg(x)
2028 return true
2029 }
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +01002030 // match: (Eq8 x (ConstBool <t> [c]))
2031 // cond: x.Op != OpConstBool
2032 // result: (Eq8 (ConstBool <t> [c]) x)
2033 for {
2034 x := v.Args[0]
2035 if v.Args[1].Op != OpConstBool {
2036 break
2037 }
2038 t := v.Args[1].Type
2039 c := v.Args[1].AuxInt
2040 if !(x.Op != OpConstBool) {
2041 break
2042 }
2043 v.reset(OpEq8)
2044 v0 := b.NewValue0(v.Line, OpConstBool, t)
2045 v0.AuxInt = c
2046 v.AddArg(v0)
2047 v.AddArg(x)
2048 return true
2049 }
Todd Nealcdc36252015-10-27 17:46:53 -05002050 // match: (Eq8 (Const8 [c]) (Const8 [d]))
2051 // cond:
2052 // result: (ConstBool [b2i(int8(c) == int8(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002053 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002054 if v.Args[0].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002055 break
Todd Nealcdc36252015-10-27 17:46:53 -05002056 }
2057 c := v.Args[0].AuxInt
2058 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002059 break
Todd Nealcdc36252015-10-27 17:46:53 -05002060 }
2061 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002062 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002063 v.AuxInt = b2i(int8(c) == int8(d))
2064 return true
2065 }
Keith Randalla347ab72015-10-26 21:49:31 -07002066 return false
2067}
2068func rewriteValuegeneric_OpEqInter(v *Value, config *Config) bool {
2069 b := v.Block
2070 _ = b
2071 // match: (EqInter x y)
2072 // cond:
2073 // result: (EqPtr (ITab x) (ITab y))
Alexandru Moșoi05434472016-02-04 19:52:10 +01002074 for {
Keith Randalla347ab72015-10-26 21:49:31 -07002075 x := v.Args[0]
2076 y := v.Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002077 v.reset(OpEqPtr)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01002078 v0 := b.NewValue0(v.Line, OpITab, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07002079 v0.AddArg(x)
Keith Randalla347ab72015-10-26 21:49:31 -07002080 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01002081 v1 := b.NewValue0(v.Line, OpITab, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07002082 v1.AddArg(y)
Keith Randalla347ab72015-10-26 21:49:31 -07002083 v.AddArg(v1)
2084 return true
2085 }
Keith Randalla347ab72015-10-26 21:49:31 -07002086 return false
2087}
2088func rewriteValuegeneric_OpEqPtr(v *Value, config *Config) bool {
2089 b := v.Block
2090 _ = b
2091 // match: (EqPtr p (ConstNil))
2092 // cond:
2093 // result: (Not (IsNonNil p))
Alexandru Moșoi05434472016-02-04 19:52:10 +01002094 for {
Keith Randalla347ab72015-10-26 21:49:31 -07002095 p := v.Args[0]
2096 if v.Args[1].Op != OpConstNil {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002097 break
Keith Randalla347ab72015-10-26 21:49:31 -07002098 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002099 v.reset(OpNot)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01002100 v0 := b.NewValue0(v.Line, OpIsNonNil, config.fe.TypeBool())
Keith Randalla347ab72015-10-26 21:49:31 -07002101 v0.AddArg(p)
Keith Randalla347ab72015-10-26 21:49:31 -07002102 v.AddArg(v0)
2103 return true
2104 }
Keith Randalla347ab72015-10-26 21:49:31 -07002105 // match: (EqPtr (ConstNil) p)
2106 // cond:
2107 // result: (Not (IsNonNil p))
Alexandru Moșoi05434472016-02-04 19:52:10 +01002108 for {
Keith Randalla347ab72015-10-26 21:49:31 -07002109 if v.Args[0].Op != OpConstNil {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002110 break
Keith Randalla347ab72015-10-26 21:49:31 -07002111 }
2112 p := v.Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002113 v.reset(OpNot)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01002114 v0 := b.NewValue0(v.Line, OpIsNonNil, config.fe.TypeBool())
Keith Randalla347ab72015-10-26 21:49:31 -07002115 v0.AddArg(p)
Keith Randalla347ab72015-10-26 21:49:31 -07002116 v.AddArg(v0)
2117 return true
2118 }
Keith Randalla347ab72015-10-26 21:49:31 -07002119 return false
2120}
2121func rewriteValuegeneric_OpEqSlice(v *Value, config *Config) bool {
2122 b := v.Block
2123 _ = b
2124 // match: (EqSlice x y)
2125 // cond:
2126 // result: (EqPtr (SlicePtr x) (SlicePtr y))
Alexandru Moșoi05434472016-02-04 19:52:10 +01002127 for {
Keith Randalla347ab72015-10-26 21:49:31 -07002128 x := v.Args[0]
2129 y := v.Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002130 v.reset(OpEqPtr)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01002131 v0 := b.NewValue0(v.Line, OpSlicePtr, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07002132 v0.AddArg(x)
Keith Randalla347ab72015-10-26 21:49:31 -07002133 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01002134 v1 := b.NewValue0(v.Line, OpSlicePtr, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07002135 v1.AddArg(y)
Keith Randalla347ab72015-10-26 21:49:31 -07002136 v.AddArg(v1)
2137 return true
2138 }
Keith Randalla347ab72015-10-26 21:49:31 -07002139 return false
2140}
Todd Nealcdc36252015-10-27 17:46:53 -05002141func rewriteValuegeneric_OpGeq16(v *Value, config *Config) bool {
2142 b := v.Block
2143 _ = b
2144 // match: (Geq16 (Const16 [c]) (Const16 [d]))
2145 // cond:
2146 // result: (ConstBool [b2i(int16(c) >= int16(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002147 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002148 if v.Args[0].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002149 break
Todd Nealcdc36252015-10-27 17:46:53 -05002150 }
2151 c := v.Args[0].AuxInt
2152 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002153 break
Todd Nealcdc36252015-10-27 17:46:53 -05002154 }
2155 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002156 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002157 v.AuxInt = b2i(int16(c) >= int16(d))
2158 return true
2159 }
Todd Nealcdc36252015-10-27 17:46:53 -05002160 return false
2161}
2162func rewriteValuegeneric_OpGeq16U(v *Value, config *Config) bool {
2163 b := v.Block
2164 _ = b
2165 // match: (Geq16U (Const16 [c]) (Const16 [d]))
2166 // cond:
2167 // result: (ConstBool [b2i(uint16(c) >= uint16(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002168 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002169 if v.Args[0].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002170 break
Todd Nealcdc36252015-10-27 17:46:53 -05002171 }
2172 c := v.Args[0].AuxInt
2173 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002174 break
Todd Nealcdc36252015-10-27 17:46:53 -05002175 }
2176 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002177 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002178 v.AuxInt = b2i(uint16(c) >= uint16(d))
2179 return true
2180 }
Todd Nealcdc36252015-10-27 17:46:53 -05002181 return false
2182}
2183func rewriteValuegeneric_OpGeq32(v *Value, config *Config) bool {
2184 b := v.Block
2185 _ = b
2186 // match: (Geq32 (Const32 [c]) (Const32 [d]))
2187 // cond:
2188 // result: (ConstBool [b2i(int32(c) >= int32(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002189 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002190 if v.Args[0].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002191 break
Todd Nealcdc36252015-10-27 17:46:53 -05002192 }
2193 c := v.Args[0].AuxInt
2194 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002195 break
Todd Nealcdc36252015-10-27 17:46:53 -05002196 }
2197 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002198 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002199 v.AuxInt = b2i(int32(c) >= int32(d))
2200 return true
2201 }
Todd Nealcdc36252015-10-27 17:46:53 -05002202 return false
2203}
2204func rewriteValuegeneric_OpGeq32U(v *Value, config *Config) bool {
2205 b := v.Block
2206 _ = b
2207 // match: (Geq32U (Const32 [c]) (Const32 [d]))
2208 // cond:
2209 // result: (ConstBool [b2i(uint32(c) >= uint32(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002210 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002211 if v.Args[0].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002212 break
Todd Nealcdc36252015-10-27 17:46:53 -05002213 }
2214 c := v.Args[0].AuxInt
2215 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002216 break
Todd Nealcdc36252015-10-27 17:46:53 -05002217 }
2218 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002219 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002220 v.AuxInt = b2i(uint32(c) >= uint32(d))
2221 return true
2222 }
Todd Nealcdc36252015-10-27 17:46:53 -05002223 return false
2224}
2225func rewriteValuegeneric_OpGeq64(v *Value, config *Config) bool {
2226 b := v.Block
2227 _ = b
2228 // match: (Geq64 (Const64 [c]) (Const64 [d]))
2229 // cond:
2230 // result: (ConstBool [b2i(int64(c) >= int64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002231 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002232 if v.Args[0].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002233 break
Todd Nealcdc36252015-10-27 17:46:53 -05002234 }
2235 c := v.Args[0].AuxInt
2236 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002237 break
Todd Nealcdc36252015-10-27 17:46:53 -05002238 }
2239 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002240 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002241 v.AuxInt = b2i(int64(c) >= int64(d))
2242 return true
2243 }
Todd Nealcdc36252015-10-27 17:46:53 -05002244 return false
2245}
2246func rewriteValuegeneric_OpGeq64U(v *Value, config *Config) bool {
2247 b := v.Block
2248 _ = b
2249 // match: (Geq64U (Const64 [c]) (Const64 [d]))
2250 // cond:
2251 // result: (ConstBool [b2i(uint64(c) >= uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002252 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002253 if v.Args[0].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002254 break
Todd Nealcdc36252015-10-27 17:46:53 -05002255 }
2256 c := v.Args[0].AuxInt
2257 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002258 break
Todd Nealcdc36252015-10-27 17:46:53 -05002259 }
2260 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002261 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002262 v.AuxInt = b2i(uint64(c) >= uint64(d))
2263 return true
2264 }
Todd Nealcdc36252015-10-27 17:46:53 -05002265 return false
2266}
2267func rewriteValuegeneric_OpGeq8(v *Value, config *Config) bool {
2268 b := v.Block
2269 _ = b
2270 // match: (Geq8 (Const8 [c]) (Const8 [d]))
2271 // cond:
2272 // result: (ConstBool [b2i(int8(c) >= int8(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002273 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002274 if v.Args[0].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002275 break
Todd Nealcdc36252015-10-27 17:46:53 -05002276 }
2277 c := v.Args[0].AuxInt
2278 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002279 break
Todd Nealcdc36252015-10-27 17:46:53 -05002280 }
2281 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002282 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002283 v.AuxInt = b2i(int8(c) >= int8(d))
2284 return true
2285 }
Todd Nealcdc36252015-10-27 17:46:53 -05002286 return false
2287}
2288func rewriteValuegeneric_OpGeq8U(v *Value, config *Config) bool {
2289 b := v.Block
2290 _ = b
2291 // match: (Geq8U (Const8 [c]) (Const8 [d]))
2292 // cond:
2293 // result: (ConstBool [b2i(uint8(c) >= uint8(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002294 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002295 if v.Args[0].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002296 break
Todd Nealcdc36252015-10-27 17:46:53 -05002297 }
2298 c := v.Args[0].AuxInt
2299 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002300 break
Todd Nealcdc36252015-10-27 17:46:53 -05002301 }
2302 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002303 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002304 v.AuxInt = b2i(uint8(c) >= uint8(d))
2305 return true
2306 }
Todd Nealcdc36252015-10-27 17:46:53 -05002307 return false
2308}
2309func rewriteValuegeneric_OpGreater16(v *Value, config *Config) bool {
2310 b := v.Block
2311 _ = b
2312 // match: (Greater16 (Const16 [c]) (Const16 [d]))
2313 // cond:
2314 // result: (ConstBool [b2i(int16(c) > int16(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002315 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002316 if v.Args[0].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002317 break
Todd Nealcdc36252015-10-27 17:46:53 -05002318 }
2319 c := v.Args[0].AuxInt
2320 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002321 break
Todd Nealcdc36252015-10-27 17:46:53 -05002322 }
2323 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002324 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002325 v.AuxInt = b2i(int16(c) > int16(d))
2326 return true
2327 }
Todd Nealcdc36252015-10-27 17:46:53 -05002328 return false
2329}
2330func rewriteValuegeneric_OpGreater16U(v *Value, config *Config) bool {
2331 b := v.Block
2332 _ = b
2333 // match: (Greater16U (Const16 [c]) (Const16 [d]))
2334 // cond:
2335 // result: (ConstBool [b2i(uint16(c) > uint16(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002336 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002337 if v.Args[0].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002338 break
Todd Nealcdc36252015-10-27 17:46:53 -05002339 }
2340 c := v.Args[0].AuxInt
2341 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002342 break
Todd Nealcdc36252015-10-27 17:46:53 -05002343 }
2344 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002345 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002346 v.AuxInt = b2i(uint16(c) > uint16(d))
2347 return true
2348 }
Todd Nealcdc36252015-10-27 17:46:53 -05002349 return false
2350}
2351func rewriteValuegeneric_OpGreater32(v *Value, config *Config) bool {
2352 b := v.Block
2353 _ = b
2354 // match: (Greater32 (Const32 [c]) (Const32 [d]))
2355 // cond:
2356 // result: (ConstBool [b2i(int32(c) > int32(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002357 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002358 if v.Args[0].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002359 break
Todd Nealcdc36252015-10-27 17:46:53 -05002360 }
2361 c := v.Args[0].AuxInt
2362 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002363 break
Todd Nealcdc36252015-10-27 17:46:53 -05002364 }
2365 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002366 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002367 v.AuxInt = b2i(int32(c) > int32(d))
2368 return true
2369 }
Todd Nealcdc36252015-10-27 17:46:53 -05002370 return false
2371}
2372func rewriteValuegeneric_OpGreater32U(v *Value, config *Config) bool {
2373 b := v.Block
2374 _ = b
2375 // match: (Greater32U (Const32 [c]) (Const32 [d]))
2376 // cond:
2377 // result: (ConstBool [b2i(uint32(c) > uint32(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002378 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002379 if v.Args[0].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002380 break
Todd Nealcdc36252015-10-27 17:46:53 -05002381 }
2382 c := v.Args[0].AuxInt
2383 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002384 break
Todd Nealcdc36252015-10-27 17:46:53 -05002385 }
2386 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002387 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002388 v.AuxInt = b2i(uint32(c) > uint32(d))
2389 return true
2390 }
Todd Nealcdc36252015-10-27 17:46:53 -05002391 return false
2392}
2393func rewriteValuegeneric_OpGreater64(v *Value, config *Config) bool {
2394 b := v.Block
2395 _ = b
2396 // match: (Greater64 (Const64 [c]) (Const64 [d]))
2397 // cond:
2398 // result: (ConstBool [b2i(int64(c) > int64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002399 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002400 if v.Args[0].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002401 break
Todd Nealcdc36252015-10-27 17:46:53 -05002402 }
2403 c := v.Args[0].AuxInt
2404 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002405 break
Todd Nealcdc36252015-10-27 17:46:53 -05002406 }
2407 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002408 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002409 v.AuxInt = b2i(int64(c) > int64(d))
2410 return true
2411 }
Todd Nealcdc36252015-10-27 17:46:53 -05002412 return false
2413}
2414func rewriteValuegeneric_OpGreater64U(v *Value, config *Config) bool {
2415 b := v.Block
2416 _ = b
2417 // match: (Greater64U (Const64 [c]) (Const64 [d]))
2418 // cond:
2419 // result: (ConstBool [b2i(uint64(c) > uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002420 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002421 if v.Args[0].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002422 break
Todd Nealcdc36252015-10-27 17:46:53 -05002423 }
2424 c := v.Args[0].AuxInt
2425 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002426 break
Todd Nealcdc36252015-10-27 17:46:53 -05002427 }
2428 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002429 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002430 v.AuxInt = b2i(uint64(c) > uint64(d))
2431 return true
2432 }
Todd Nealcdc36252015-10-27 17:46:53 -05002433 return false
2434}
2435func rewriteValuegeneric_OpGreater8(v *Value, config *Config) bool {
2436 b := v.Block
2437 _ = b
2438 // match: (Greater8 (Const8 [c]) (Const8 [d]))
2439 // cond:
2440 // result: (ConstBool [b2i(int8(c) > int8(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002441 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002442 if v.Args[0].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002443 break
Todd Nealcdc36252015-10-27 17:46:53 -05002444 }
2445 c := v.Args[0].AuxInt
2446 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002447 break
Todd Nealcdc36252015-10-27 17:46:53 -05002448 }
2449 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002450 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002451 v.AuxInt = b2i(int8(c) > int8(d))
2452 return true
2453 }
Todd Nealcdc36252015-10-27 17:46:53 -05002454 return false
2455}
2456func rewriteValuegeneric_OpGreater8U(v *Value, config *Config) bool {
2457 b := v.Block
2458 _ = b
2459 // match: (Greater8U (Const8 [c]) (Const8 [d]))
2460 // cond:
2461 // result: (ConstBool [b2i(uint8(c) > uint8(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002462 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002463 if v.Args[0].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002464 break
Todd Nealcdc36252015-10-27 17:46:53 -05002465 }
2466 c := v.Args[0].AuxInt
2467 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002468 break
Todd Nealcdc36252015-10-27 17:46:53 -05002469 }
2470 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002471 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002472 v.AuxInt = b2i(uint8(c) > uint8(d))
2473 return true
2474 }
Todd Nealcdc36252015-10-27 17:46:53 -05002475 return false
2476}
Keith Randalla347ab72015-10-26 21:49:31 -07002477func rewriteValuegeneric_OpIData(v *Value, config *Config) bool {
2478 b := v.Block
2479 _ = b
2480 // match: (IData (IMake _ data))
2481 // cond:
2482 // result: data
Alexandru Moșoi05434472016-02-04 19:52:10 +01002483 for {
Keith Randalla347ab72015-10-26 21:49:31 -07002484 if v.Args[0].Op != OpIMake {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002485 break
Keith Randalla347ab72015-10-26 21:49:31 -07002486 }
2487 data := v.Args[0].Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002488 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07002489 v.Type = data.Type
2490 v.AddArg(data)
2491 return true
2492 }
Keith Randalla347ab72015-10-26 21:49:31 -07002493 return false
2494}
2495func rewriteValuegeneric_OpITab(v *Value, config *Config) bool {
2496 b := v.Block
2497 _ = b
2498 // match: (ITab (IMake itab _))
2499 // cond:
2500 // result: itab
Alexandru Moșoi05434472016-02-04 19:52:10 +01002501 for {
Keith Randalla347ab72015-10-26 21:49:31 -07002502 if v.Args[0].Op != OpIMake {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002503 break
Keith Randalla347ab72015-10-26 21:49:31 -07002504 }
2505 itab := v.Args[0].Args[0]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002506 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07002507 v.Type = itab.Type
2508 v.AddArg(itab)
2509 return true
2510 }
Keith Randalla347ab72015-10-26 21:49:31 -07002511 return false
2512}
2513func rewriteValuegeneric_OpIsInBounds(v *Value, config *Config) bool {
2514 b := v.Block
2515 _ = b
2516 // match: (IsInBounds (Const32 [c]) (Const32 [d]))
2517 // cond:
2518 // result: (ConstBool [b2i(inBounds32(c,d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002519 for {
Keith Randalla347ab72015-10-26 21:49:31 -07002520 if v.Args[0].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002521 break
Keith Randalla347ab72015-10-26 21:49:31 -07002522 }
2523 c := v.Args[0].AuxInt
2524 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002525 break
Keith Randalla347ab72015-10-26 21:49:31 -07002526 }
2527 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002528 v.reset(OpConstBool)
Keith Randalla347ab72015-10-26 21:49:31 -07002529 v.AuxInt = b2i(inBounds32(c, d))
2530 return true
2531 }
Keith Randalla347ab72015-10-26 21:49:31 -07002532 // match: (IsInBounds (Const64 [c]) (Const64 [d]))
2533 // cond:
2534 // result: (ConstBool [b2i(inBounds64(c,d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002535 for {
Keith Randalla347ab72015-10-26 21:49:31 -07002536 if v.Args[0].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002537 break
Keith Randalla347ab72015-10-26 21:49:31 -07002538 }
2539 c := v.Args[0].AuxInt
2540 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002541 break
Keith Randalla347ab72015-10-26 21:49:31 -07002542 }
2543 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002544 v.reset(OpConstBool)
Keith Randalla347ab72015-10-26 21:49:31 -07002545 v.AuxInt = b2i(inBounds64(c, d))
2546 return true
2547 }
Keith Randall582baae2015-11-02 21:28:13 -08002548 return false
2549}
2550func rewriteValuegeneric_OpIsSliceInBounds(v *Value, config *Config) bool {
2551 b := v.Block
2552 _ = b
2553 // match: (IsSliceInBounds (Const32 [c]) (Const32 [d]))
2554 // cond:
2555 // result: (ConstBool [b2i(sliceInBounds32(c,d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002556 for {
Keith Randall582baae2015-11-02 21:28:13 -08002557 if v.Args[0].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002558 break
Keith Randalla347ab72015-10-26 21:49:31 -07002559 }
2560 c := v.Args[0].AuxInt
Keith Randall582baae2015-11-02 21:28:13 -08002561 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002562 break
Keith Randalla347ab72015-10-26 21:49:31 -07002563 }
2564 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002565 v.reset(OpConstBool)
Keith Randall582baae2015-11-02 21:28:13 -08002566 v.AuxInt = b2i(sliceInBounds32(c, d))
Keith Randalla347ab72015-10-26 21:49:31 -07002567 return true
2568 }
Keith Randall582baae2015-11-02 21:28:13 -08002569 // match: (IsSliceInBounds (Const64 [c]) (Const64 [d]))
2570 // cond:
2571 // result: (ConstBool [b2i(sliceInBounds64(c,d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002572 for {
Keith Randall582baae2015-11-02 21:28:13 -08002573 if v.Args[0].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002574 break
Keith Randalla347ab72015-10-26 21:49:31 -07002575 }
2576 c := v.Args[0].AuxInt
Keith Randall582baae2015-11-02 21:28:13 -08002577 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002578 break
Keith Randalla347ab72015-10-26 21:49:31 -07002579 }
2580 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002581 v.reset(OpConstBool)
Keith Randall582baae2015-11-02 21:28:13 -08002582 v.AuxInt = b2i(sliceInBounds64(c, d))
Keith Randalla347ab72015-10-26 21:49:31 -07002583 return true
2584 }
Keith Randalla347ab72015-10-26 21:49:31 -07002585 return false
2586}
Todd Nealcdc36252015-10-27 17:46:53 -05002587func rewriteValuegeneric_OpLeq16(v *Value, config *Config) bool {
2588 b := v.Block
2589 _ = b
2590 // match: (Leq16 (Const16 [c]) (Const16 [d]))
2591 // cond:
2592 // result: (ConstBool [b2i(int16(c) <= int16(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002593 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002594 if v.Args[0].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002595 break
Todd Nealcdc36252015-10-27 17:46:53 -05002596 }
2597 c := v.Args[0].AuxInt
2598 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002599 break
Todd Nealcdc36252015-10-27 17:46:53 -05002600 }
2601 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002602 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002603 v.AuxInt = b2i(int16(c) <= int16(d))
2604 return true
2605 }
Todd Nealcdc36252015-10-27 17:46:53 -05002606 return false
2607}
2608func rewriteValuegeneric_OpLeq16U(v *Value, config *Config) bool {
2609 b := v.Block
2610 _ = b
2611 // match: (Leq16U (Const16 [c]) (Const16 [d]))
2612 // cond:
2613 // result: (ConstBool [b2i(uint16(c) <= uint16(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002614 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002615 if v.Args[0].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002616 break
Todd Nealcdc36252015-10-27 17:46:53 -05002617 }
2618 c := v.Args[0].AuxInt
2619 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002620 break
Todd Nealcdc36252015-10-27 17:46:53 -05002621 }
2622 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002623 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002624 v.AuxInt = b2i(uint16(c) <= uint16(d))
2625 return true
2626 }
Todd Nealcdc36252015-10-27 17:46:53 -05002627 return false
2628}
2629func rewriteValuegeneric_OpLeq32(v *Value, config *Config) bool {
2630 b := v.Block
2631 _ = b
2632 // match: (Leq32 (Const32 [c]) (Const32 [d]))
2633 // cond:
2634 // result: (ConstBool [b2i(int32(c) <= int32(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002635 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002636 if v.Args[0].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002637 break
Todd Nealcdc36252015-10-27 17:46:53 -05002638 }
2639 c := v.Args[0].AuxInt
2640 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002641 break
Todd Nealcdc36252015-10-27 17:46:53 -05002642 }
2643 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002644 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002645 v.AuxInt = b2i(int32(c) <= int32(d))
2646 return true
2647 }
Todd Nealcdc36252015-10-27 17:46:53 -05002648 return false
2649}
2650func rewriteValuegeneric_OpLeq32U(v *Value, config *Config) bool {
2651 b := v.Block
2652 _ = b
2653 // match: (Leq32U (Const32 [c]) (Const32 [d]))
2654 // cond:
2655 // result: (ConstBool [b2i(uint32(c) <= uint32(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002656 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002657 if v.Args[0].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002658 break
Todd Nealcdc36252015-10-27 17:46:53 -05002659 }
2660 c := v.Args[0].AuxInt
2661 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002662 break
Todd Nealcdc36252015-10-27 17:46:53 -05002663 }
2664 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002665 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002666 v.AuxInt = b2i(uint32(c) <= uint32(d))
2667 return true
2668 }
Todd Nealcdc36252015-10-27 17:46:53 -05002669 return false
2670}
2671func rewriteValuegeneric_OpLeq64(v *Value, config *Config) bool {
2672 b := v.Block
2673 _ = b
2674 // match: (Leq64 (Const64 [c]) (Const64 [d]))
2675 // cond:
2676 // result: (ConstBool [b2i(int64(c) <= int64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002677 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002678 if v.Args[0].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002679 break
Todd Nealcdc36252015-10-27 17:46:53 -05002680 }
2681 c := v.Args[0].AuxInt
2682 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002683 break
Todd Nealcdc36252015-10-27 17:46:53 -05002684 }
2685 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002686 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002687 v.AuxInt = b2i(int64(c) <= int64(d))
2688 return true
2689 }
Todd Nealcdc36252015-10-27 17:46:53 -05002690 return false
2691}
2692func rewriteValuegeneric_OpLeq64U(v *Value, config *Config) bool {
2693 b := v.Block
2694 _ = b
2695 // match: (Leq64U (Const64 [c]) (Const64 [d]))
2696 // cond:
2697 // result: (ConstBool [b2i(uint64(c) <= uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002698 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002699 if v.Args[0].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002700 break
Todd Nealcdc36252015-10-27 17:46:53 -05002701 }
2702 c := v.Args[0].AuxInt
2703 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002704 break
Todd Nealcdc36252015-10-27 17:46:53 -05002705 }
2706 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002707 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002708 v.AuxInt = b2i(uint64(c) <= uint64(d))
2709 return true
2710 }
Todd Nealcdc36252015-10-27 17:46:53 -05002711 return false
2712}
2713func rewriteValuegeneric_OpLeq8(v *Value, config *Config) bool {
2714 b := v.Block
2715 _ = b
2716 // match: (Leq8 (Const8 [c]) (Const8 [d]))
2717 // cond:
2718 // result: (ConstBool [b2i(int8(c) <= int8(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002719 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002720 if v.Args[0].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002721 break
Todd Nealcdc36252015-10-27 17:46:53 -05002722 }
2723 c := v.Args[0].AuxInt
2724 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002725 break
Todd Nealcdc36252015-10-27 17:46:53 -05002726 }
2727 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002728 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002729 v.AuxInt = b2i(int8(c) <= int8(d))
2730 return true
2731 }
Todd Nealcdc36252015-10-27 17:46:53 -05002732 return false
2733}
2734func rewriteValuegeneric_OpLeq8U(v *Value, config *Config) bool {
2735 b := v.Block
2736 _ = b
2737 // match: (Leq8U (Const8 [c]) (Const8 [d]))
2738 // cond:
2739 // result: (ConstBool [b2i(uint8(c) <= uint8(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002740 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002741 if v.Args[0].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002742 break
Todd Nealcdc36252015-10-27 17:46:53 -05002743 }
2744 c := v.Args[0].AuxInt
2745 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002746 break
Todd Nealcdc36252015-10-27 17:46:53 -05002747 }
2748 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002749 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002750 v.AuxInt = b2i(uint8(c) <= uint8(d))
2751 return true
2752 }
Todd Nealcdc36252015-10-27 17:46:53 -05002753 return false
2754}
2755func rewriteValuegeneric_OpLess16(v *Value, config *Config) bool {
2756 b := v.Block
2757 _ = b
2758 // match: (Less16 (Const16 [c]) (Const16 [d]))
2759 // cond:
2760 // result: (ConstBool [b2i(int16(c) < int16(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002761 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002762 if v.Args[0].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002763 break
Todd Nealcdc36252015-10-27 17:46:53 -05002764 }
2765 c := v.Args[0].AuxInt
2766 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002767 break
Todd Nealcdc36252015-10-27 17:46:53 -05002768 }
2769 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002770 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002771 v.AuxInt = b2i(int16(c) < int16(d))
2772 return true
2773 }
Todd Nealcdc36252015-10-27 17:46:53 -05002774 return false
2775}
2776func rewriteValuegeneric_OpLess16U(v *Value, config *Config) bool {
2777 b := v.Block
2778 _ = b
2779 // match: (Less16U (Const16 [c]) (Const16 [d]))
2780 // cond:
2781 // result: (ConstBool [b2i(uint16(c) < uint16(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002782 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002783 if v.Args[0].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002784 break
Todd Nealcdc36252015-10-27 17:46:53 -05002785 }
2786 c := v.Args[0].AuxInt
2787 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002788 break
Todd Nealcdc36252015-10-27 17:46:53 -05002789 }
2790 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002791 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002792 v.AuxInt = b2i(uint16(c) < uint16(d))
2793 return true
2794 }
Todd Nealcdc36252015-10-27 17:46:53 -05002795 return false
2796}
2797func rewriteValuegeneric_OpLess32(v *Value, config *Config) bool {
2798 b := v.Block
2799 _ = b
2800 // match: (Less32 (Const32 [c]) (Const32 [d]))
2801 // cond:
2802 // result: (ConstBool [b2i(int32(c) < int32(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002803 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002804 if v.Args[0].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002805 break
Todd Nealcdc36252015-10-27 17:46:53 -05002806 }
2807 c := v.Args[0].AuxInt
2808 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002809 break
Todd Nealcdc36252015-10-27 17:46:53 -05002810 }
2811 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002812 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002813 v.AuxInt = b2i(int32(c) < int32(d))
2814 return true
2815 }
Todd Nealcdc36252015-10-27 17:46:53 -05002816 return false
2817}
2818func rewriteValuegeneric_OpLess32U(v *Value, config *Config) bool {
2819 b := v.Block
2820 _ = b
2821 // match: (Less32U (Const32 [c]) (Const32 [d]))
2822 // cond:
2823 // result: (ConstBool [b2i(uint32(c) < uint32(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002824 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002825 if v.Args[0].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002826 break
Todd Nealcdc36252015-10-27 17:46:53 -05002827 }
2828 c := v.Args[0].AuxInt
2829 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002830 break
Todd Nealcdc36252015-10-27 17:46:53 -05002831 }
2832 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002833 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002834 v.AuxInt = b2i(uint32(c) < uint32(d))
2835 return true
2836 }
Todd Nealcdc36252015-10-27 17:46:53 -05002837 return false
2838}
2839func rewriteValuegeneric_OpLess64(v *Value, config *Config) bool {
2840 b := v.Block
2841 _ = b
2842 // match: (Less64 (Const64 [c]) (Const64 [d]))
2843 // cond:
2844 // result: (ConstBool [b2i(int64(c) < int64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002845 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002846 if v.Args[0].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002847 break
Todd Nealcdc36252015-10-27 17:46:53 -05002848 }
2849 c := v.Args[0].AuxInt
2850 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002851 break
Todd Nealcdc36252015-10-27 17:46:53 -05002852 }
2853 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002854 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002855 v.AuxInt = b2i(int64(c) < int64(d))
2856 return true
2857 }
Todd Nealcdc36252015-10-27 17:46:53 -05002858 return false
2859}
2860func rewriteValuegeneric_OpLess64U(v *Value, config *Config) bool {
2861 b := v.Block
2862 _ = b
2863 // match: (Less64U (Const64 [c]) (Const64 [d]))
2864 // cond:
2865 // result: (ConstBool [b2i(uint64(c) < uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002866 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002867 if v.Args[0].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002868 break
Todd Nealcdc36252015-10-27 17:46:53 -05002869 }
2870 c := v.Args[0].AuxInt
2871 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002872 break
Todd Nealcdc36252015-10-27 17:46:53 -05002873 }
2874 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002875 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002876 v.AuxInt = b2i(uint64(c) < uint64(d))
2877 return true
2878 }
Todd Nealcdc36252015-10-27 17:46:53 -05002879 return false
2880}
2881func rewriteValuegeneric_OpLess8(v *Value, config *Config) bool {
2882 b := v.Block
2883 _ = b
2884 // match: (Less8 (Const8 [c]) (Const8 [d]))
2885 // cond:
2886 // result: (ConstBool [b2i(int8(c) < int8(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002887 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002888 if v.Args[0].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002889 break
Todd Nealcdc36252015-10-27 17:46:53 -05002890 }
2891 c := v.Args[0].AuxInt
2892 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002893 break
Todd Nealcdc36252015-10-27 17:46:53 -05002894 }
2895 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002896 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002897 v.AuxInt = b2i(int8(c) < int8(d))
2898 return true
2899 }
Todd Nealcdc36252015-10-27 17:46:53 -05002900 return false
2901}
2902func rewriteValuegeneric_OpLess8U(v *Value, config *Config) bool {
2903 b := v.Block
2904 _ = b
2905 // match: (Less8U (Const8 [c]) (Const8 [d]))
2906 // cond:
2907 // result: (ConstBool [b2i(uint8(c) < uint8(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01002908 for {
Todd Nealcdc36252015-10-27 17:46:53 -05002909 if v.Args[0].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002910 break
Todd Nealcdc36252015-10-27 17:46:53 -05002911 }
2912 c := v.Args[0].AuxInt
2913 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002914 break
Todd Nealcdc36252015-10-27 17:46:53 -05002915 }
2916 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002917 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05002918 v.AuxInt = b2i(uint8(c) < uint8(d))
2919 return true
2920 }
Todd Nealcdc36252015-10-27 17:46:53 -05002921 return false
2922}
Keith Randalla347ab72015-10-26 21:49:31 -07002923func rewriteValuegeneric_OpLoad(v *Value, config *Config) bool {
2924 b := v.Block
2925 _ = b
Todd Neal9dc13342016-02-13 17:37:19 -06002926 // match: (Load <t1> p1 (Store [w] p2 x _))
2927 // cond: isSamePtr(p1,p2) && t1.Compare(x.Type)==CMPeq && w == t1.Size()
2928 // result: x
2929 for {
2930 t1 := v.Type
2931 p1 := v.Args[0]
2932 if v.Args[1].Op != OpStore {
2933 break
2934 }
2935 w := v.Args[1].AuxInt
2936 p2 := v.Args[1].Args[0]
2937 x := v.Args[1].Args[1]
2938 if !(isSamePtr(p1, p2) && t1.Compare(x.Type) == CMPeq && w == t1.Size()) {
2939 break
2940 }
2941 v.reset(OpCopy)
2942 v.Type = x.Type
2943 v.AddArg(x)
2944 return true
2945 }
Keith Randalla734bbc2016-01-11 21:05:33 -08002946 // match: (Load <t> _ _)
2947 // cond: t.IsStruct() && t.NumFields() == 0 && config.fe.CanSSA(t)
2948 // result: (StructMake0)
Alexandru Moșoi05434472016-02-04 19:52:10 +01002949 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08002950 t := v.Type
2951 if !(t.IsStruct() && t.NumFields() == 0 && config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002952 break
Keith Randalla734bbc2016-01-11 21:05:33 -08002953 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002954 v.reset(OpStructMake0)
Keith Randalla734bbc2016-01-11 21:05:33 -08002955 return true
2956 }
Keith Randalla734bbc2016-01-11 21:05:33 -08002957 // match: (Load <t> ptr mem)
2958 // cond: t.IsStruct() && t.NumFields() == 1 && config.fe.CanSSA(t)
2959 // result: (StructMake1 (Load <t.FieldType(0)> ptr mem))
Alexandru Moșoi05434472016-02-04 19:52:10 +01002960 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08002961 t := v.Type
2962 ptr := v.Args[0]
2963 mem := v.Args[1]
2964 if !(t.IsStruct() && t.NumFields() == 1 && config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002965 break
Keith Randalla734bbc2016-01-11 21:05:33 -08002966 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002967 v.reset(OpStructMake1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01002968 v0 := b.NewValue0(v.Line, OpLoad, t.FieldType(0))
Keith Randalla734bbc2016-01-11 21:05:33 -08002969 v0.AddArg(ptr)
2970 v0.AddArg(mem)
2971 v.AddArg(v0)
2972 return true
2973 }
Keith Randalla734bbc2016-01-11 21:05:33 -08002974 // match: (Load <t> ptr mem)
2975 // cond: t.IsStruct() && t.NumFields() == 2 && config.fe.CanSSA(t)
2976 // 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 +01002977 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08002978 t := v.Type
2979 ptr := v.Args[0]
2980 mem := v.Args[1]
2981 if !(t.IsStruct() && t.NumFields() == 2 && config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01002982 break
Keith Randalla734bbc2016-01-11 21:05:33 -08002983 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01002984 v.reset(OpStructMake2)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01002985 v0 := b.NewValue0(v.Line, OpLoad, t.FieldType(0))
Keith Randalla734bbc2016-01-11 21:05:33 -08002986 v0.AddArg(ptr)
2987 v0.AddArg(mem)
2988 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01002989 v1 := b.NewValue0(v.Line, OpLoad, t.FieldType(1))
2990 v2 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(1).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08002991 v2.AuxInt = t.FieldOff(1)
2992 v2.AddArg(ptr)
2993 v1.AddArg(v2)
2994 v1.AddArg(mem)
2995 v.AddArg(v1)
2996 return true
2997 }
Keith Randalla734bbc2016-01-11 21:05:33 -08002998 // match: (Load <t> ptr mem)
2999 // cond: t.IsStruct() && t.NumFields() == 3 && config.fe.CanSSA(t)
3000 // 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 +01003001 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08003002 t := v.Type
3003 ptr := v.Args[0]
3004 mem := v.Args[1]
3005 if !(t.IsStruct() && t.NumFields() == 3 && config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003006 break
Keith Randalla734bbc2016-01-11 21:05:33 -08003007 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003008 v.reset(OpStructMake3)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003009 v0 := b.NewValue0(v.Line, OpLoad, t.FieldType(0))
Keith Randalla734bbc2016-01-11 21:05:33 -08003010 v0.AddArg(ptr)
3011 v0.AddArg(mem)
3012 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003013 v1 := b.NewValue0(v.Line, OpLoad, t.FieldType(1))
3014 v2 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(1).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08003015 v2.AuxInt = t.FieldOff(1)
3016 v2.AddArg(ptr)
3017 v1.AddArg(v2)
3018 v1.AddArg(mem)
3019 v.AddArg(v1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003020 v3 := b.NewValue0(v.Line, OpLoad, t.FieldType(2))
3021 v4 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(2).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08003022 v4.AuxInt = t.FieldOff(2)
3023 v4.AddArg(ptr)
3024 v3.AddArg(v4)
3025 v3.AddArg(mem)
3026 v.AddArg(v3)
3027 return true
3028 }
Keith Randalla734bbc2016-01-11 21:05:33 -08003029 // match: (Load <t> ptr mem)
3030 // cond: t.IsStruct() && t.NumFields() == 4 && config.fe.CanSSA(t)
3031 // 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 +01003032 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08003033 t := v.Type
3034 ptr := v.Args[0]
3035 mem := v.Args[1]
3036 if !(t.IsStruct() && t.NumFields() == 4 && config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003037 break
Keith Randalla734bbc2016-01-11 21:05:33 -08003038 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003039 v.reset(OpStructMake4)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003040 v0 := b.NewValue0(v.Line, OpLoad, t.FieldType(0))
Keith Randalla734bbc2016-01-11 21:05:33 -08003041 v0.AddArg(ptr)
3042 v0.AddArg(mem)
3043 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003044 v1 := b.NewValue0(v.Line, OpLoad, t.FieldType(1))
3045 v2 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(1).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08003046 v2.AuxInt = t.FieldOff(1)
3047 v2.AddArg(ptr)
3048 v1.AddArg(v2)
3049 v1.AddArg(mem)
3050 v.AddArg(v1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003051 v3 := b.NewValue0(v.Line, OpLoad, t.FieldType(2))
3052 v4 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(2).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08003053 v4.AuxInt = t.FieldOff(2)
3054 v4.AddArg(ptr)
3055 v3.AddArg(v4)
3056 v3.AddArg(mem)
3057 v.AddArg(v3)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003058 v5 := b.NewValue0(v.Line, OpLoad, t.FieldType(3))
3059 v6 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(3).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08003060 v6.AuxInt = t.FieldOff(3)
3061 v6.AddArg(ptr)
3062 v5.AddArg(v6)
3063 v5.AddArg(mem)
3064 v.AddArg(v5)
3065 return true
3066 }
Keith Randalla347ab72015-10-26 21:49:31 -07003067 // match: (Load <t> ptr mem)
3068 // cond: t.IsComplex() && t.Size() == 8
3069 // result: (ComplexMake (Load <config.fe.TypeFloat32()> ptr mem) (Load <config.fe.TypeFloat32()> (OffPtr <config.fe.TypeFloat32().PtrTo()> [4] ptr) mem) )
Alexandru Moșoi05434472016-02-04 19:52:10 +01003070 for {
Keith Randalla347ab72015-10-26 21:49:31 -07003071 t := v.Type
3072 ptr := v.Args[0]
3073 mem := v.Args[1]
3074 if !(t.IsComplex() && t.Size() == 8) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003075 break
Keith Randalla347ab72015-10-26 21:49:31 -07003076 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003077 v.reset(OpComplexMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003078 v0 := b.NewValue0(v.Line, OpLoad, config.fe.TypeFloat32())
Keith Randalla347ab72015-10-26 21:49:31 -07003079 v0.AddArg(ptr)
3080 v0.AddArg(mem)
3081 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003082 v1 := b.NewValue0(v.Line, OpLoad, config.fe.TypeFloat32())
3083 v2 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeFloat32().PtrTo())
Keith Randalla347ab72015-10-26 21:49:31 -07003084 v2.AuxInt = 4
3085 v2.AddArg(ptr)
3086 v1.AddArg(v2)
3087 v1.AddArg(mem)
3088 v.AddArg(v1)
3089 return true
3090 }
Keith Randalla347ab72015-10-26 21:49:31 -07003091 // match: (Load <t> ptr mem)
3092 // cond: t.IsComplex() && t.Size() == 16
3093 // result: (ComplexMake (Load <config.fe.TypeFloat64()> ptr mem) (Load <config.fe.TypeFloat64()> (OffPtr <config.fe.TypeFloat64().PtrTo()> [8] ptr) mem) )
Alexandru Moșoi05434472016-02-04 19:52:10 +01003094 for {
Keith Randalla347ab72015-10-26 21:49:31 -07003095 t := v.Type
3096 ptr := v.Args[0]
3097 mem := v.Args[1]
3098 if !(t.IsComplex() && t.Size() == 16) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003099 break
Keith Randalla347ab72015-10-26 21:49:31 -07003100 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003101 v.reset(OpComplexMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003102 v0 := b.NewValue0(v.Line, OpLoad, config.fe.TypeFloat64())
Keith Randalla347ab72015-10-26 21:49:31 -07003103 v0.AddArg(ptr)
3104 v0.AddArg(mem)
3105 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003106 v1 := b.NewValue0(v.Line, OpLoad, config.fe.TypeFloat64())
3107 v2 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeFloat64().PtrTo())
Keith Randalla347ab72015-10-26 21:49:31 -07003108 v2.AuxInt = 8
3109 v2.AddArg(ptr)
3110 v1.AddArg(v2)
3111 v1.AddArg(mem)
3112 v.AddArg(v1)
3113 return true
3114 }
Keith Randalla347ab72015-10-26 21:49:31 -07003115 // match: (Load <t> ptr mem)
3116 // cond: t.IsString()
Keith Randall02f4d0a2015-11-02 08:10:26 -08003117 // result: (StringMake (Load <config.fe.TypeBytePtr()> ptr mem) (Load <config.fe.TypeInt()> (OffPtr <config.fe.TypeInt().PtrTo()> [config.PtrSize] ptr) mem))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003118 for {
Keith Randalla347ab72015-10-26 21:49:31 -07003119 t := v.Type
3120 ptr := v.Args[0]
3121 mem := v.Args[1]
3122 if !(t.IsString()) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003123 break
Keith Randalla347ab72015-10-26 21:49:31 -07003124 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003125 v.reset(OpStringMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003126 v0 := b.NewValue0(v.Line, OpLoad, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07003127 v0.AddArg(ptr)
3128 v0.AddArg(mem)
3129 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003130 v1 := b.NewValue0(v.Line, OpLoad, config.fe.TypeInt())
3131 v2 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeInt().PtrTo())
Keith Randalla347ab72015-10-26 21:49:31 -07003132 v2.AuxInt = config.PtrSize
3133 v2.AddArg(ptr)
3134 v1.AddArg(v2)
3135 v1.AddArg(mem)
3136 v.AddArg(v1)
3137 return true
3138 }
Keith Randalla347ab72015-10-26 21:49:31 -07003139 // match: (Load <t> ptr mem)
3140 // cond: t.IsSlice()
Keith Randall02f4d0a2015-11-02 08:10:26 -08003141 // result: (SliceMake (Load <config.fe.TypeBytePtr()> ptr mem) (Load <config.fe.TypeInt()> (OffPtr <config.fe.TypeInt().PtrTo()> [config.PtrSize] ptr) mem) (Load <config.fe.TypeInt()> (OffPtr <config.fe.TypeInt().PtrTo()> [2*config.PtrSize] ptr) mem))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003142 for {
Keith Randalla347ab72015-10-26 21:49:31 -07003143 t := v.Type
3144 ptr := v.Args[0]
3145 mem := v.Args[1]
3146 if !(t.IsSlice()) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003147 break
Keith Randalla347ab72015-10-26 21:49:31 -07003148 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003149 v.reset(OpSliceMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003150 v0 := b.NewValue0(v.Line, OpLoad, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07003151 v0.AddArg(ptr)
3152 v0.AddArg(mem)
3153 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003154 v1 := b.NewValue0(v.Line, OpLoad, config.fe.TypeInt())
3155 v2 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeInt().PtrTo())
Keith Randalla347ab72015-10-26 21:49:31 -07003156 v2.AuxInt = config.PtrSize
3157 v2.AddArg(ptr)
3158 v1.AddArg(v2)
3159 v1.AddArg(mem)
3160 v.AddArg(v1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003161 v3 := b.NewValue0(v.Line, OpLoad, config.fe.TypeInt())
3162 v4 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeInt().PtrTo())
Keith Randalla347ab72015-10-26 21:49:31 -07003163 v4.AuxInt = 2 * config.PtrSize
3164 v4.AddArg(ptr)
3165 v3.AddArg(v4)
3166 v3.AddArg(mem)
3167 v.AddArg(v3)
3168 return true
3169 }
Keith Randalla347ab72015-10-26 21:49:31 -07003170 // match: (Load <t> ptr mem)
3171 // cond: t.IsInterface()
3172 // result: (IMake (Load <config.fe.TypeBytePtr()> ptr mem) (Load <config.fe.TypeBytePtr()> (OffPtr <config.fe.TypeBytePtr().PtrTo()> [config.PtrSize] ptr) mem))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003173 for {
Keith Randalla347ab72015-10-26 21:49:31 -07003174 t := v.Type
3175 ptr := v.Args[0]
3176 mem := v.Args[1]
3177 if !(t.IsInterface()) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003178 break
Keith Randalla347ab72015-10-26 21:49:31 -07003179 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003180 v.reset(OpIMake)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003181 v0 := b.NewValue0(v.Line, OpLoad, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07003182 v0.AddArg(ptr)
3183 v0.AddArg(mem)
3184 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01003185 v1 := b.NewValue0(v.Line, OpLoad, config.fe.TypeBytePtr())
3186 v2 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeBytePtr().PtrTo())
Keith Randalla347ab72015-10-26 21:49:31 -07003187 v2.AuxInt = config.PtrSize
3188 v2.AddArg(ptr)
3189 v1.AddArg(v2)
3190 v1.AddArg(mem)
3191 v.AddArg(v1)
3192 return true
3193 }
Keith Randalla347ab72015-10-26 21:49:31 -07003194 return false
3195}
Todd Neal93a0b0f2016-02-03 06:21:24 -05003196func rewriteValuegeneric_OpLsh16x16(v *Value, config *Config) bool {
3197 b := v.Block
3198 _ = b
3199 // match: (Lsh16x16 <t> x (Const16 [c]))
3200 // cond:
3201 // result: (Lsh16x64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003202 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003203 t := v.Type
3204 x := v.Args[0]
3205 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003206 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003207 }
3208 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003209 v.reset(OpLsh16x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003210 v.AddArg(x)
3211 v0 := b.NewValue0(v.Line, OpConst64, t)
3212 v0.AuxInt = int64(uint16(c))
3213 v.AddArg(v0)
3214 return true
3215 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003216 return false
3217}
3218func rewriteValuegeneric_OpLsh16x32(v *Value, config *Config) bool {
3219 b := v.Block
3220 _ = b
3221 // match: (Lsh16x32 <t> x (Const32 [c]))
3222 // cond:
3223 // result: (Lsh16x64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003224 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003225 t := v.Type
3226 x := v.Args[0]
3227 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003228 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003229 }
3230 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003231 v.reset(OpLsh16x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003232 v.AddArg(x)
3233 v0 := b.NewValue0(v.Line, OpConst64, t)
3234 v0.AuxInt = int64(uint32(c))
3235 v.AddArg(v0)
3236 return true
3237 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003238 return false
3239}
3240func rewriteValuegeneric_OpLsh16x64(v *Value, config *Config) bool {
3241 b := v.Block
3242 _ = b
3243 // match: (Lsh16x64 (Const16 [c]) (Const64 [d]))
3244 // cond:
3245 // result: (Const16 [int64(int16(c) << uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003246 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003247 if v.Args[0].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003248 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003249 }
3250 c := v.Args[0].AuxInt
3251 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003252 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003253 }
3254 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003255 v.reset(OpConst16)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003256 v.AuxInt = int64(int16(c) << uint64(d))
3257 return true
3258 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01003259 // match: (Lsh16x64 (Const16 [0]) _)
3260 // cond:
3261 // result: (Const16 [0])
3262 for {
3263 if v.Args[0].Op != OpConst16 {
3264 break
3265 }
3266 if v.Args[0].AuxInt != 0 {
3267 break
3268 }
3269 v.reset(OpConst16)
3270 v.AuxInt = 0
3271 return true
3272 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003273 // match: (Lsh16x64 x (Const64 [0]))
3274 // cond:
3275 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01003276 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003277 x := v.Args[0]
3278 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003279 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003280 }
3281 if v.Args[1].AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003282 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003283 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003284 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003285 v.Type = x.Type
3286 v.AddArg(x)
3287 return true
3288 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003289 // match: (Lsh16x64 _ (Const64 [c]))
3290 // cond: uint64(c) >= 16
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01003291 // result: (Const16 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003292 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003293 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003294 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003295 }
3296 c := v.Args[1].AuxInt
3297 if !(uint64(c) >= 16) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003298 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003299 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01003300 v.reset(OpConst16)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003301 v.AuxInt = 0
3302 return true
3303 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003304 // match: (Lsh16x64 <t> (Lsh16x64 x (Const64 [c])) (Const64 [d]))
3305 // cond: !uaddOvf(c,d)
3306 // result: (Lsh16x64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003307 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003308 t := v.Type
3309 if v.Args[0].Op != OpLsh16x64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003310 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003311 }
3312 x := v.Args[0].Args[0]
3313 if v.Args[0].Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003314 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003315 }
3316 c := v.Args[0].Args[1].AuxInt
3317 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003318 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003319 }
3320 d := v.Args[1].AuxInt
3321 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003322 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003323 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003324 v.reset(OpLsh16x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003325 v.AddArg(x)
3326 v0 := b.NewValue0(v.Line, OpConst64, t)
3327 v0.AuxInt = c + d
3328 v.AddArg(v0)
3329 return true
3330 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003331 return false
3332}
3333func rewriteValuegeneric_OpLsh16x8(v *Value, config *Config) bool {
3334 b := v.Block
3335 _ = b
3336 // match: (Lsh16x8 <t> x (Const8 [c]))
3337 // cond:
3338 // result: (Lsh16x64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003339 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003340 t := v.Type
3341 x := v.Args[0]
3342 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003343 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003344 }
3345 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003346 v.reset(OpLsh16x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003347 v.AddArg(x)
3348 v0 := b.NewValue0(v.Line, OpConst64, t)
3349 v0.AuxInt = int64(uint8(c))
3350 v.AddArg(v0)
3351 return true
3352 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003353 return false
3354}
3355func rewriteValuegeneric_OpLsh32x16(v *Value, config *Config) bool {
3356 b := v.Block
3357 _ = b
3358 // match: (Lsh32x16 <t> x (Const16 [c]))
3359 // cond:
3360 // result: (Lsh32x64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003361 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003362 t := v.Type
3363 x := v.Args[0]
3364 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003365 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003366 }
3367 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003368 v.reset(OpLsh32x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003369 v.AddArg(x)
3370 v0 := b.NewValue0(v.Line, OpConst64, t)
3371 v0.AuxInt = int64(uint16(c))
3372 v.AddArg(v0)
3373 return true
3374 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003375 return false
3376}
3377func rewriteValuegeneric_OpLsh32x32(v *Value, config *Config) bool {
3378 b := v.Block
3379 _ = b
3380 // match: (Lsh32x32 <t> x (Const32 [c]))
3381 // cond:
3382 // result: (Lsh32x64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003383 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003384 t := v.Type
3385 x := v.Args[0]
3386 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003387 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003388 }
3389 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003390 v.reset(OpLsh32x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003391 v.AddArg(x)
3392 v0 := b.NewValue0(v.Line, OpConst64, t)
3393 v0.AuxInt = int64(uint32(c))
3394 v.AddArg(v0)
3395 return true
3396 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003397 return false
3398}
3399func rewriteValuegeneric_OpLsh32x64(v *Value, config *Config) bool {
3400 b := v.Block
3401 _ = b
3402 // match: (Lsh32x64 (Const32 [c]) (Const64 [d]))
3403 // cond:
3404 // result: (Const32 [int64(int32(c) << uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003405 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003406 if v.Args[0].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003407 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003408 }
3409 c := v.Args[0].AuxInt
3410 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003411 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003412 }
3413 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003414 v.reset(OpConst32)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003415 v.AuxInt = int64(int32(c) << uint64(d))
3416 return true
3417 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01003418 // match: (Lsh32x64 (Const32 [0]) _)
3419 // cond:
3420 // result: (Const32 [0])
3421 for {
3422 if v.Args[0].Op != OpConst32 {
3423 break
3424 }
3425 if v.Args[0].AuxInt != 0 {
3426 break
3427 }
3428 v.reset(OpConst32)
3429 v.AuxInt = 0
3430 return true
3431 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003432 // match: (Lsh32x64 x (Const64 [0]))
3433 // cond:
3434 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01003435 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003436 x := v.Args[0]
3437 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003438 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003439 }
3440 if v.Args[1].AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003441 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003442 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003443 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003444 v.Type = x.Type
3445 v.AddArg(x)
3446 return true
3447 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003448 // match: (Lsh32x64 _ (Const64 [c]))
3449 // cond: uint64(c) >= 32
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01003450 // result: (Const32 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003451 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003452 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003453 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003454 }
3455 c := v.Args[1].AuxInt
3456 if !(uint64(c) >= 32) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003457 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003458 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01003459 v.reset(OpConst32)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003460 v.AuxInt = 0
3461 return true
3462 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003463 // match: (Lsh32x64 <t> (Lsh32x64 x (Const64 [c])) (Const64 [d]))
3464 // cond: !uaddOvf(c,d)
3465 // result: (Lsh32x64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003466 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003467 t := v.Type
3468 if v.Args[0].Op != OpLsh32x64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003469 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003470 }
3471 x := v.Args[0].Args[0]
3472 if v.Args[0].Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003473 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003474 }
3475 c := v.Args[0].Args[1].AuxInt
3476 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003477 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003478 }
3479 d := v.Args[1].AuxInt
3480 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003481 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003482 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003483 v.reset(OpLsh32x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003484 v.AddArg(x)
3485 v0 := b.NewValue0(v.Line, OpConst64, t)
3486 v0.AuxInt = c + d
3487 v.AddArg(v0)
3488 return true
3489 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003490 return false
3491}
3492func rewriteValuegeneric_OpLsh32x8(v *Value, config *Config) bool {
3493 b := v.Block
3494 _ = b
3495 // match: (Lsh32x8 <t> x (Const8 [c]))
3496 // cond:
3497 // result: (Lsh32x64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003498 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003499 t := v.Type
3500 x := v.Args[0]
3501 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003502 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003503 }
3504 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003505 v.reset(OpLsh32x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003506 v.AddArg(x)
3507 v0 := b.NewValue0(v.Line, OpConst64, t)
3508 v0.AuxInt = int64(uint8(c))
3509 v.AddArg(v0)
3510 return true
3511 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003512 return false
3513}
3514func rewriteValuegeneric_OpLsh64x16(v *Value, config *Config) bool {
3515 b := v.Block
3516 _ = b
3517 // match: (Lsh64x16 <t> x (Const16 [c]))
3518 // cond:
3519 // result: (Lsh64x64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003520 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003521 t := v.Type
3522 x := v.Args[0]
3523 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003524 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003525 }
3526 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003527 v.reset(OpLsh64x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003528 v.AddArg(x)
3529 v0 := b.NewValue0(v.Line, OpConst64, t)
3530 v0.AuxInt = int64(uint16(c))
3531 v.AddArg(v0)
3532 return true
3533 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01003534 // match: (Lsh64x16 (Const64 [0]) _)
3535 // cond:
3536 // result: (Const64 [0])
3537 for {
3538 if v.Args[0].Op != OpConst64 {
3539 break
3540 }
3541 if v.Args[0].AuxInt != 0 {
3542 break
3543 }
3544 v.reset(OpConst64)
3545 v.AuxInt = 0
3546 return true
3547 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003548 return false
3549}
3550func rewriteValuegeneric_OpLsh64x32(v *Value, config *Config) bool {
3551 b := v.Block
3552 _ = b
3553 // match: (Lsh64x32 <t> x (Const32 [c]))
3554 // cond:
3555 // result: (Lsh64x64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003556 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003557 t := v.Type
3558 x := v.Args[0]
3559 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003560 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003561 }
3562 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003563 v.reset(OpLsh64x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003564 v.AddArg(x)
3565 v0 := b.NewValue0(v.Line, OpConst64, t)
3566 v0.AuxInt = int64(uint32(c))
3567 v.AddArg(v0)
3568 return true
3569 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01003570 // match: (Lsh64x32 (Const64 [0]) _)
3571 // cond:
3572 // result: (Const64 [0])
3573 for {
3574 if v.Args[0].Op != OpConst64 {
3575 break
3576 }
3577 if v.Args[0].AuxInt != 0 {
3578 break
3579 }
3580 v.reset(OpConst64)
3581 v.AuxInt = 0
3582 return true
3583 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003584 return false
3585}
3586func rewriteValuegeneric_OpLsh64x64(v *Value, config *Config) bool {
3587 b := v.Block
3588 _ = b
3589 // match: (Lsh64x64 (Const64 [c]) (Const64 [d]))
3590 // cond:
3591 // result: (Const64 [c << uint64(d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003592 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003593 if v.Args[0].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003594 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003595 }
3596 c := v.Args[0].AuxInt
3597 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003598 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003599 }
3600 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003601 v.reset(OpConst64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003602 v.AuxInt = c << uint64(d)
3603 return true
3604 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01003605 // match: (Lsh64x64 (Const64 [0]) _)
3606 // cond:
3607 // result: (Const64 [0])
3608 for {
3609 if v.Args[0].Op != OpConst64 {
3610 break
3611 }
3612 if v.Args[0].AuxInt != 0 {
3613 break
3614 }
3615 v.reset(OpConst64)
3616 v.AuxInt = 0
3617 return true
3618 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003619 // match: (Lsh64x64 x (Const64 [0]))
3620 // cond:
3621 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01003622 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003623 x := v.Args[0]
3624 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003625 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003626 }
3627 if v.Args[1].AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003628 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003629 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003630 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003631 v.Type = x.Type
3632 v.AddArg(x)
3633 return true
3634 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01003635 // match: (Lsh64x64 (Const64 [0]) _)
3636 // cond:
3637 // result: (Const64 [0])
3638 for {
3639 if v.Args[0].Op != OpConst64 {
3640 break
3641 }
3642 if v.Args[0].AuxInt != 0 {
3643 break
3644 }
3645 v.reset(OpConst64)
3646 v.AuxInt = 0
3647 return true
3648 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003649 // match: (Lsh64x64 _ (Const64 [c]))
3650 // cond: uint64(c) >= 64
3651 // result: (Const64 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003652 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003653 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003654 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003655 }
3656 c := v.Args[1].AuxInt
3657 if !(uint64(c) >= 64) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003658 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003659 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003660 v.reset(OpConst64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003661 v.AuxInt = 0
3662 return true
3663 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003664 // match: (Lsh64x64 <t> (Lsh64x64 x (Const64 [c])) (Const64 [d]))
3665 // cond: !uaddOvf(c,d)
3666 // result: (Lsh64x64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003667 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003668 t := v.Type
3669 if v.Args[0].Op != OpLsh64x64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003670 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003671 }
3672 x := v.Args[0].Args[0]
3673 if v.Args[0].Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003674 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003675 }
3676 c := v.Args[0].Args[1].AuxInt
3677 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003678 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003679 }
3680 d := v.Args[1].AuxInt
3681 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003682 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003683 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003684 v.reset(OpLsh64x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003685 v.AddArg(x)
3686 v0 := b.NewValue0(v.Line, OpConst64, t)
3687 v0.AuxInt = c + d
3688 v.AddArg(v0)
3689 return true
3690 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003691 return false
3692}
3693func rewriteValuegeneric_OpLsh64x8(v *Value, config *Config) bool {
3694 b := v.Block
3695 _ = b
3696 // match: (Lsh64x8 <t> x (Const8 [c]))
3697 // cond:
3698 // result: (Lsh64x64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003699 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003700 t := v.Type
3701 x := v.Args[0]
3702 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003703 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003704 }
3705 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003706 v.reset(OpLsh64x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003707 v.AddArg(x)
3708 v0 := b.NewValue0(v.Line, OpConst64, t)
3709 v0.AuxInt = int64(uint8(c))
3710 v.AddArg(v0)
3711 return true
3712 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01003713 // match: (Lsh64x8 (Const64 [0]) _)
3714 // cond:
3715 // result: (Const64 [0])
3716 for {
3717 if v.Args[0].Op != OpConst64 {
3718 break
3719 }
3720 if v.Args[0].AuxInt != 0 {
3721 break
3722 }
3723 v.reset(OpConst64)
3724 v.AuxInt = 0
3725 return true
3726 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003727 return false
3728}
3729func rewriteValuegeneric_OpLsh8x16(v *Value, config *Config) bool {
3730 b := v.Block
3731 _ = b
3732 // match: (Lsh8x16 <t> x (Const16 [c]))
3733 // cond:
3734 // result: (Lsh8x64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003735 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003736 t := v.Type
3737 x := v.Args[0]
3738 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003739 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003740 }
3741 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003742 v.reset(OpLsh8x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003743 v.AddArg(x)
3744 v0 := b.NewValue0(v.Line, OpConst64, t)
3745 v0.AuxInt = int64(uint16(c))
3746 v.AddArg(v0)
3747 return true
3748 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003749 return false
3750}
3751func rewriteValuegeneric_OpLsh8x32(v *Value, config *Config) bool {
3752 b := v.Block
3753 _ = b
3754 // match: (Lsh8x32 <t> x (Const32 [c]))
3755 // cond:
3756 // result: (Lsh8x64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003757 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003758 t := v.Type
3759 x := v.Args[0]
3760 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003761 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003762 }
3763 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003764 v.reset(OpLsh8x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003765 v.AddArg(x)
3766 v0 := b.NewValue0(v.Line, OpConst64, t)
3767 v0.AuxInt = int64(uint32(c))
3768 v.AddArg(v0)
3769 return true
3770 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003771 return false
3772}
3773func rewriteValuegeneric_OpLsh8x64(v *Value, config *Config) bool {
3774 b := v.Block
3775 _ = b
3776 // match: (Lsh8x64 (Const8 [c]) (Const64 [d]))
3777 // cond:
3778 // result: (Const8 [int64(int8(c) << uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003779 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003780 if v.Args[0].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003781 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003782 }
3783 c := v.Args[0].AuxInt
3784 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003785 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003786 }
3787 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003788 v.reset(OpConst8)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003789 v.AuxInt = int64(int8(c) << uint64(d))
3790 return true
3791 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01003792 // match: (Lsh8x64 (Const8 [0]) _)
3793 // cond:
3794 // result: (Const8 [0])
3795 for {
3796 if v.Args[0].Op != OpConst8 {
3797 break
3798 }
3799 if v.Args[0].AuxInt != 0 {
3800 break
3801 }
3802 v.reset(OpConst8)
3803 v.AuxInt = 0
3804 return true
3805 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003806 // match: (Lsh8x64 x (Const64 [0]))
3807 // cond:
3808 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01003809 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003810 x := v.Args[0]
3811 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003812 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003813 }
3814 if v.Args[1].AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003815 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003816 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003817 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003818 v.Type = x.Type
3819 v.AddArg(x)
3820 return true
3821 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003822 // match: (Lsh8x64 _ (Const64 [c]))
3823 // cond: uint64(c) >= 8
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01003824 // result: (Const8 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003825 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003826 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003827 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003828 }
3829 c := v.Args[1].AuxInt
3830 if !(uint64(c) >= 8) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003831 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003832 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01003833 v.reset(OpConst8)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003834 v.AuxInt = 0
3835 return true
3836 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003837 // match: (Lsh8x64 <t> (Lsh8x64 x (Const64 [c])) (Const64 [d]))
3838 // cond: !uaddOvf(c,d)
3839 // result: (Lsh8x64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003840 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003841 t := v.Type
3842 if v.Args[0].Op != OpLsh8x64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003843 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003844 }
3845 x := v.Args[0].Args[0]
3846 if v.Args[0].Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003847 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003848 }
3849 c := v.Args[0].Args[1].AuxInt
3850 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003851 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003852 }
3853 d := v.Args[1].AuxInt
3854 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003855 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003856 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003857 v.reset(OpLsh8x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003858 v.AddArg(x)
3859 v0 := b.NewValue0(v.Line, OpConst64, t)
3860 v0.AuxInt = c + d
3861 v.AddArg(v0)
3862 return true
3863 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003864 return false
3865}
3866func rewriteValuegeneric_OpLsh8x8(v *Value, config *Config) bool {
3867 b := v.Block
3868 _ = b
3869 // match: (Lsh8x8 <t> x (Const8 [c]))
3870 // cond:
3871 // result: (Lsh8x64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01003872 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05003873 t := v.Type
3874 x := v.Args[0]
3875 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003876 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05003877 }
3878 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003879 v.reset(OpLsh8x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05003880 v.AddArg(x)
3881 v0 := b.NewValue0(v.Line, OpConst64, t)
3882 v0.AuxInt = int64(uint8(c))
3883 v.AddArg(v0)
3884 return true
3885 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05003886 return false
3887}
Keith Randalla3055af2016-02-05 20:26:18 -08003888func rewriteValuegeneric_OpMod64(v *Value, config *Config) bool {
3889 b := v.Block
3890 _ = b
3891 // match: (Mod64 <t> x (Const64 [c]))
3892 // cond: smagic64ok(c)
3893 // result: (Sub64 x (Mul64 <t> (Div64 <t> x (Const64 <t> [c])) (Const64 <t> [c])))
3894 for {
3895 t := v.Type
3896 x := v.Args[0]
3897 if v.Args[1].Op != OpConst64 {
3898 break
3899 }
3900 c := v.Args[1].AuxInt
3901 if !(smagic64ok(c)) {
3902 break
3903 }
3904 v.reset(OpSub64)
3905 v.AddArg(x)
3906 v0 := b.NewValue0(v.Line, OpMul64, t)
3907 v1 := b.NewValue0(v.Line, OpDiv64, t)
3908 v1.AddArg(x)
3909 v2 := b.NewValue0(v.Line, OpConst64, t)
3910 v2.AuxInt = c
3911 v1.AddArg(v2)
3912 v0.AddArg(v1)
3913 v3 := b.NewValue0(v.Line, OpConst64, t)
3914 v3.AuxInt = c
3915 v0.AddArg(v3)
3916 v.AddArg(v0)
3917 return true
3918 }
3919 return false
3920}
3921func rewriteValuegeneric_OpMod64u(v *Value, config *Config) bool {
3922 b := v.Block
3923 _ = b
3924 // match: (Mod64u <t> x (Const64 [c]))
3925 // cond: umagic64ok(c)
3926 // result: (Sub64 x (Mul64 <t> (Div64u <t> x (Const64 <t> [c])) (Const64 <t> [c])))
3927 for {
3928 t := v.Type
3929 x := v.Args[0]
3930 if v.Args[1].Op != OpConst64 {
3931 break
3932 }
3933 c := v.Args[1].AuxInt
3934 if !(umagic64ok(c)) {
3935 break
3936 }
3937 v.reset(OpSub64)
3938 v.AddArg(x)
3939 v0 := b.NewValue0(v.Line, OpMul64, t)
3940 v1 := b.NewValue0(v.Line, OpDiv64u, t)
3941 v1.AddArg(x)
3942 v2 := b.NewValue0(v.Line, OpConst64, t)
3943 v2.AuxInt = c
3944 v1.AddArg(v2)
3945 v0.AddArg(v1)
3946 v3 := b.NewValue0(v.Line, OpConst64, t)
3947 v3.AuxInt = c
3948 v0.AddArg(v3)
3949 v.AddArg(v0)
3950 return true
3951 }
3952 return false
3953}
Keith Randall582baae2015-11-02 21:28:13 -08003954func rewriteValuegeneric_OpMul16(v *Value, config *Config) bool {
3955 b := v.Block
3956 _ = b
3957 // match: (Mul16 (Const16 [c]) (Const16 [d]))
3958 // cond:
3959 // result: (Const16 [c*d])
Alexandru Moșoi05434472016-02-04 19:52:10 +01003960 for {
Keith Randall582baae2015-11-02 21:28:13 -08003961 if v.Args[0].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003962 break
Keith Randall582baae2015-11-02 21:28:13 -08003963 }
3964 c := v.Args[0].AuxInt
3965 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01003966 break
Keith Randall582baae2015-11-02 21:28:13 -08003967 }
3968 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01003969 v.reset(OpConst16)
Keith Randall582baae2015-11-02 21:28:13 -08003970 v.AuxInt = c * d
3971 return true
3972 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01003973 // match: (Mul16 x (Const16 <t> [c]))
3974 // cond: x.Op != OpConst16
3975 // result: (Mul16 (Const16 <t> [c]) x)
3976 for {
3977 x := v.Args[0]
3978 if v.Args[1].Op != OpConst16 {
3979 break
3980 }
3981 t := v.Args[1].Type
3982 c := v.Args[1].AuxInt
3983 if !(x.Op != OpConst16) {
3984 break
3985 }
3986 v.reset(OpMul16)
3987 v0 := b.NewValue0(v.Line, OpConst16, t)
3988 v0.AuxInt = c
3989 v.AddArg(v0)
3990 v.AddArg(x)
3991 return true
3992 }
3993 // match: (Mul16 (Const16 [0]) _)
3994 // cond:
3995 // result: (Const16 [0])
3996 for {
3997 if v.Args[0].Op != OpConst16 {
3998 break
3999 }
4000 if v.Args[0].AuxInt != 0 {
4001 break
4002 }
4003 v.reset(OpConst16)
4004 v.AuxInt = 0
4005 return true
4006 }
Keith Randall582baae2015-11-02 21:28:13 -08004007 return false
4008}
4009func rewriteValuegeneric_OpMul32(v *Value, config *Config) bool {
4010 b := v.Block
4011 _ = b
4012 // match: (Mul32 (Const32 [c]) (Const32 [d]))
4013 // cond:
4014 // result: (Const32 [c*d])
Alexandru Moșoi05434472016-02-04 19:52:10 +01004015 for {
Keith Randall582baae2015-11-02 21:28:13 -08004016 if v.Args[0].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004017 break
Keith Randall582baae2015-11-02 21:28:13 -08004018 }
4019 c := v.Args[0].AuxInt
4020 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004021 break
Keith Randall582baae2015-11-02 21:28:13 -08004022 }
4023 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004024 v.reset(OpConst32)
Keith Randall582baae2015-11-02 21:28:13 -08004025 v.AuxInt = c * d
4026 return true
4027 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01004028 // match: (Mul32 x (Const32 <t> [c]))
4029 // cond: x.Op != OpConst32
4030 // result: (Mul32 (Const32 <t> [c]) x)
4031 for {
4032 x := v.Args[0]
4033 if v.Args[1].Op != OpConst32 {
4034 break
4035 }
4036 t := v.Args[1].Type
4037 c := v.Args[1].AuxInt
4038 if !(x.Op != OpConst32) {
4039 break
4040 }
4041 v.reset(OpMul32)
4042 v0 := b.NewValue0(v.Line, OpConst32, t)
4043 v0.AuxInt = c
4044 v.AddArg(v0)
4045 v.AddArg(x)
4046 return true
4047 }
Alexandru Moșoi1f6e9e32016-03-01 13:39:47 +01004048 // match: (Mul32 (Const32 <t> [c]) (Add32 <t> (Const32 <t> [d]) x))
4049 // cond:
4050 // result: (Add32 (Const32 <t> [c*d]) (Mul32 <t> (Const32 <t> [c]) x))
4051 for {
4052 if v.Args[0].Op != OpConst32 {
4053 break
4054 }
4055 t := v.Args[0].Type
4056 c := v.Args[0].AuxInt
4057 if v.Args[1].Op != OpAdd32 {
4058 break
4059 }
4060 if v.Args[1].Type != v.Args[0].Type {
4061 break
4062 }
4063 if v.Args[1].Args[0].Op != OpConst32 {
4064 break
4065 }
4066 if v.Args[1].Args[0].Type != v.Args[0].Type {
4067 break
4068 }
4069 d := v.Args[1].Args[0].AuxInt
4070 x := v.Args[1].Args[1]
4071 v.reset(OpAdd32)
4072 v0 := b.NewValue0(v.Line, OpConst32, t)
4073 v0.AuxInt = c * d
4074 v.AddArg(v0)
4075 v1 := b.NewValue0(v.Line, OpMul32, t)
4076 v2 := b.NewValue0(v.Line, OpConst32, t)
4077 v2.AuxInt = c
4078 v1.AddArg(v2)
4079 v1.AddArg(x)
4080 v.AddArg(v1)
4081 return true
4082 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01004083 // match: (Mul32 (Const32 [0]) _)
4084 // cond:
4085 // result: (Const32 [0])
4086 for {
4087 if v.Args[0].Op != OpConst32 {
4088 break
4089 }
4090 if v.Args[0].AuxInt != 0 {
4091 break
4092 }
4093 v.reset(OpConst32)
4094 v.AuxInt = 0
4095 return true
4096 }
Keith Randall582baae2015-11-02 21:28:13 -08004097 return false
4098}
Keith Randalla347ab72015-10-26 21:49:31 -07004099func rewriteValuegeneric_OpMul64(v *Value, config *Config) bool {
4100 b := v.Block
4101 _ = b
4102 // match: (Mul64 (Const64 [c]) (Const64 [d]))
4103 // cond:
4104 // result: (Const64 [c*d])
Alexandru Moșoi05434472016-02-04 19:52:10 +01004105 for {
Keith Randalla347ab72015-10-26 21:49:31 -07004106 if v.Args[0].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004107 break
Keith Randalla347ab72015-10-26 21:49:31 -07004108 }
4109 c := v.Args[0].AuxInt
4110 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004111 break
Keith Randalla347ab72015-10-26 21:49:31 -07004112 }
4113 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004114 v.reset(OpConst64)
Keith Randalla347ab72015-10-26 21:49:31 -07004115 v.AuxInt = c * d
4116 return true
4117 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01004118 // match: (Mul64 x (Const64 <t> [c]))
4119 // cond: x.Op != OpConst64
4120 // result: (Mul64 (Const64 <t> [c]) x)
4121 for {
4122 x := v.Args[0]
4123 if v.Args[1].Op != OpConst64 {
4124 break
4125 }
4126 t := v.Args[1].Type
4127 c := v.Args[1].AuxInt
4128 if !(x.Op != OpConst64) {
4129 break
4130 }
4131 v.reset(OpMul64)
4132 v0 := b.NewValue0(v.Line, OpConst64, t)
4133 v0.AuxInt = c
4134 v.AddArg(v0)
4135 v.AddArg(x)
4136 return true
4137 }
Alexandru Moșoi1f6e9e32016-03-01 13:39:47 +01004138 // match: (Mul64 (Const64 <t> [c]) (Add64 <t> (Const64 <t> [d]) x))
4139 // cond:
4140 // result: (Add64 (Const64 <t> [c*d]) (Mul64 <t> (Const64 <t> [c]) x))
4141 for {
4142 if v.Args[0].Op != OpConst64 {
4143 break
4144 }
4145 t := v.Args[0].Type
4146 c := v.Args[0].AuxInt
4147 if v.Args[1].Op != OpAdd64 {
4148 break
4149 }
4150 if v.Args[1].Type != v.Args[0].Type {
4151 break
4152 }
4153 if v.Args[1].Args[0].Op != OpConst64 {
4154 break
4155 }
4156 if v.Args[1].Args[0].Type != v.Args[0].Type {
4157 break
4158 }
4159 d := v.Args[1].Args[0].AuxInt
4160 x := v.Args[1].Args[1]
4161 v.reset(OpAdd64)
4162 v0 := b.NewValue0(v.Line, OpConst64, t)
4163 v0.AuxInt = c * d
4164 v.AddArg(v0)
4165 v1 := b.NewValue0(v.Line, OpMul64, t)
4166 v2 := b.NewValue0(v.Line, OpConst64, t)
4167 v2.AuxInt = c
4168 v1.AddArg(v2)
4169 v1.AddArg(x)
4170 v.AddArg(v1)
4171 return true
4172 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01004173 // match: (Mul64 (Const64 [0]) _)
4174 // cond:
4175 // result: (Const64 [0])
4176 for {
4177 if v.Args[0].Op != OpConst64 {
4178 break
4179 }
4180 if v.Args[0].AuxInt != 0 {
4181 break
4182 }
4183 v.reset(OpConst64)
4184 v.AuxInt = 0
4185 return true
4186 }
Keith Randalla347ab72015-10-26 21:49:31 -07004187 return false
4188}
Keith Randall582baae2015-11-02 21:28:13 -08004189func rewriteValuegeneric_OpMul8(v *Value, config *Config) bool {
Keith Randalla347ab72015-10-26 21:49:31 -07004190 b := v.Block
4191 _ = b
Keith Randall582baae2015-11-02 21:28:13 -08004192 // match: (Mul8 (Const8 [c]) (Const8 [d]))
Keith Randalla347ab72015-10-26 21:49:31 -07004193 // cond:
Keith Randall582baae2015-11-02 21:28:13 -08004194 // result: (Const8 [c*d])
Alexandru Moșoi05434472016-02-04 19:52:10 +01004195 for {
Keith Randall582baae2015-11-02 21:28:13 -08004196 if v.Args[0].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004197 break
Keith Randalla347ab72015-10-26 21:49:31 -07004198 }
4199 c := v.Args[0].AuxInt
Keith Randall582baae2015-11-02 21:28:13 -08004200 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004201 break
Keith Randalla347ab72015-10-26 21:49:31 -07004202 }
4203 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004204 v.reset(OpConst8)
Keith Randalla347ab72015-10-26 21:49:31 -07004205 v.AuxInt = c * d
4206 return true
4207 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01004208 // match: (Mul8 x (Const8 <t> [c]))
4209 // cond: x.Op != OpConst8
4210 // result: (Mul8 (Const8 <t> [c]) x)
4211 for {
4212 x := v.Args[0]
4213 if v.Args[1].Op != OpConst8 {
4214 break
4215 }
4216 t := v.Args[1].Type
4217 c := v.Args[1].AuxInt
4218 if !(x.Op != OpConst8) {
4219 break
4220 }
4221 v.reset(OpMul8)
4222 v0 := b.NewValue0(v.Line, OpConst8, t)
4223 v0.AuxInt = c
4224 v.AddArg(v0)
4225 v.AddArg(x)
4226 return true
4227 }
4228 // match: (Mul8 (Const8 [0]) _)
4229 // cond:
4230 // result: (Const8 [0])
4231 for {
4232 if v.Args[0].Op != OpConst8 {
4233 break
4234 }
4235 if v.Args[0].AuxInt != 0 {
4236 break
4237 }
4238 v.reset(OpConst8)
4239 v.AuxInt = 0
4240 return true
4241 }
Keith Randalla347ab72015-10-26 21:49:31 -07004242 return false
4243}
Alexandru Moșoi964dda92016-02-08 18:55:56 +01004244func rewriteValuegeneric_OpNeg16(v *Value, config *Config) bool {
4245 b := v.Block
4246 _ = b
4247 // match: (Neg16 (Const16 [c]))
4248 // cond:
4249 // result: (Const16 [-c])
4250 for {
4251 if v.Args[0].Op != OpConst16 {
4252 break
4253 }
4254 c := v.Args[0].AuxInt
4255 v.reset(OpConst16)
4256 v.AuxInt = -c
4257 return true
4258 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01004259 // match: (Neg16 (Sub16 x y))
4260 // cond:
4261 // result: (Sub16 y x)
4262 for {
4263 if v.Args[0].Op != OpSub16 {
4264 break
4265 }
4266 x := v.Args[0].Args[0]
4267 y := v.Args[0].Args[1]
4268 v.reset(OpSub16)
4269 v.AddArg(y)
4270 v.AddArg(x)
4271 return true
4272 }
Alexandru Moșoi964dda92016-02-08 18:55:56 +01004273 return false
4274}
4275func rewriteValuegeneric_OpNeg32(v *Value, config *Config) bool {
4276 b := v.Block
4277 _ = b
4278 // match: (Neg32 (Const32 [c]))
4279 // cond:
4280 // result: (Const32 [-c])
4281 for {
4282 if v.Args[0].Op != OpConst32 {
4283 break
4284 }
4285 c := v.Args[0].AuxInt
4286 v.reset(OpConst32)
4287 v.AuxInt = -c
4288 return true
4289 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01004290 // match: (Neg32 (Sub32 x y))
4291 // cond:
4292 // result: (Sub32 y x)
4293 for {
4294 if v.Args[0].Op != OpSub32 {
4295 break
4296 }
4297 x := v.Args[0].Args[0]
4298 y := v.Args[0].Args[1]
4299 v.reset(OpSub32)
4300 v.AddArg(y)
4301 v.AddArg(x)
4302 return true
4303 }
Alexandru Moșoi964dda92016-02-08 18:55:56 +01004304 return false
4305}
4306func rewriteValuegeneric_OpNeg64(v *Value, config *Config) bool {
4307 b := v.Block
4308 _ = b
4309 // match: (Neg64 (Const64 [c]))
4310 // cond:
4311 // result: (Const64 [-c])
4312 for {
4313 if v.Args[0].Op != OpConst64 {
4314 break
4315 }
4316 c := v.Args[0].AuxInt
4317 v.reset(OpConst64)
4318 v.AuxInt = -c
4319 return true
4320 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01004321 // match: (Neg64 (Sub64 x y))
4322 // cond:
4323 // result: (Sub64 y x)
4324 for {
4325 if v.Args[0].Op != OpSub64 {
4326 break
4327 }
4328 x := v.Args[0].Args[0]
4329 y := v.Args[0].Args[1]
4330 v.reset(OpSub64)
4331 v.AddArg(y)
4332 v.AddArg(x)
4333 return true
4334 }
Alexandru Moșoi964dda92016-02-08 18:55:56 +01004335 return false
4336}
4337func rewriteValuegeneric_OpNeg8(v *Value, config *Config) bool {
4338 b := v.Block
4339 _ = b
4340 // match: (Neg8 (Const8 [c]))
4341 // cond:
4342 // result: (Const8 [-c])
4343 for {
4344 if v.Args[0].Op != OpConst8 {
4345 break
4346 }
4347 c := v.Args[0].AuxInt
4348 v.reset(OpConst8)
4349 v.AuxInt = -c
4350 return true
4351 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01004352 // match: (Neg8 (Sub8 x y))
4353 // cond:
4354 // result: (Sub8 y x)
4355 for {
4356 if v.Args[0].Op != OpSub8 {
4357 break
4358 }
4359 x := v.Args[0].Args[0]
4360 y := v.Args[0].Args[1]
4361 v.reset(OpSub8)
4362 v.AddArg(y)
4363 v.AddArg(x)
4364 return true
4365 }
Alexandru Moșoi964dda92016-02-08 18:55:56 +01004366 return false
4367}
Keith Randalla347ab72015-10-26 21:49:31 -07004368func rewriteValuegeneric_OpNeq16(v *Value, config *Config) bool {
4369 b := v.Block
4370 _ = b
4371 // match: (Neq16 x x)
4372 // cond:
4373 // result: (ConstBool [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01004374 for {
Keith Randalla347ab72015-10-26 21:49:31 -07004375 x := v.Args[0]
4376 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004377 break
Keith Randalla347ab72015-10-26 21:49:31 -07004378 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004379 v.reset(OpConstBool)
Keith Randalla347ab72015-10-26 21:49:31 -07004380 v.AuxInt = 0
4381 return true
4382 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004383 // match: (Neq16 (Const16 <t> [c]) (Add16 (Const16 <t> [d]) x))
4384 // cond:
4385 // result: (Neq16 (Const16 <t> [c-d]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01004386 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004387 if v.Args[0].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004388 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004389 }
4390 t := v.Args[0].Type
4391 c := v.Args[0].AuxInt
4392 if v.Args[1].Op != OpAdd16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004393 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004394 }
4395 if v.Args[1].Args[0].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004396 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004397 }
4398 if v.Args[1].Args[0].Type != v.Args[0].Type {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004399 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004400 }
4401 d := v.Args[1].Args[0].AuxInt
4402 x := v.Args[1].Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004403 v.reset(OpNeq16)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004404 v0 := b.NewValue0(v.Line, OpConst16, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004405 v0.AuxInt = c - d
4406 v.AddArg(v0)
4407 v.AddArg(x)
4408 return true
4409 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004410 // match: (Neq16 x (Const16 <t> [c]))
4411 // cond: x.Op != OpConst16
4412 // result: (Neq16 (Const16 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01004413 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004414 x := v.Args[0]
4415 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004416 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004417 }
4418 t := v.Args[1].Type
4419 c := v.Args[1].AuxInt
4420 if !(x.Op != OpConst16) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004421 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004422 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004423 v.reset(OpNeq16)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004424 v0 := b.NewValue0(v.Line, OpConst16, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004425 v0.AuxInt = c
4426 v.AddArg(v0)
4427 v.AddArg(x)
4428 return true
4429 }
Todd Nealcdc36252015-10-27 17:46:53 -05004430 // match: (Neq16 (Const16 [c]) (Const16 [d]))
4431 // cond:
4432 // result: (ConstBool [b2i(int16(c) != int16(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01004433 for {
Todd Nealcdc36252015-10-27 17:46:53 -05004434 if v.Args[0].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004435 break
Todd Nealcdc36252015-10-27 17:46:53 -05004436 }
4437 c := v.Args[0].AuxInt
4438 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004439 break
Todd Nealcdc36252015-10-27 17:46:53 -05004440 }
4441 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004442 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05004443 v.AuxInt = b2i(int16(c) != int16(d))
4444 return true
4445 }
Keith Randalla347ab72015-10-26 21:49:31 -07004446 return false
4447}
4448func rewriteValuegeneric_OpNeq32(v *Value, config *Config) bool {
4449 b := v.Block
4450 _ = b
4451 // match: (Neq32 x x)
4452 // cond:
4453 // result: (ConstBool [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01004454 for {
Keith Randalla347ab72015-10-26 21:49:31 -07004455 x := v.Args[0]
4456 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004457 break
Keith Randalla347ab72015-10-26 21:49:31 -07004458 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004459 v.reset(OpConstBool)
Keith Randalla347ab72015-10-26 21:49:31 -07004460 v.AuxInt = 0
4461 return true
4462 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004463 // match: (Neq32 (Const32 <t> [c]) (Add32 (Const32 <t> [d]) x))
4464 // cond:
4465 // result: (Neq32 (Const32 <t> [c-d]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01004466 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004467 if v.Args[0].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004468 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004469 }
4470 t := v.Args[0].Type
4471 c := v.Args[0].AuxInt
4472 if v.Args[1].Op != OpAdd32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004473 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004474 }
4475 if v.Args[1].Args[0].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004476 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004477 }
4478 if v.Args[1].Args[0].Type != v.Args[0].Type {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004479 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004480 }
4481 d := v.Args[1].Args[0].AuxInt
4482 x := v.Args[1].Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004483 v.reset(OpNeq32)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004484 v0 := b.NewValue0(v.Line, OpConst32, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004485 v0.AuxInt = c - d
4486 v.AddArg(v0)
4487 v.AddArg(x)
4488 return true
4489 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004490 // match: (Neq32 x (Const32 <t> [c]))
4491 // cond: x.Op != OpConst32
4492 // result: (Neq32 (Const32 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01004493 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004494 x := v.Args[0]
4495 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004496 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004497 }
4498 t := v.Args[1].Type
4499 c := v.Args[1].AuxInt
4500 if !(x.Op != OpConst32) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004501 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004502 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004503 v.reset(OpNeq32)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004504 v0 := b.NewValue0(v.Line, OpConst32, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004505 v0.AuxInt = c
4506 v.AddArg(v0)
4507 v.AddArg(x)
4508 return true
4509 }
Todd Nealcdc36252015-10-27 17:46:53 -05004510 // match: (Neq32 (Const32 [c]) (Const32 [d]))
4511 // cond:
4512 // result: (ConstBool [b2i(int32(c) != int32(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01004513 for {
Todd Nealcdc36252015-10-27 17:46:53 -05004514 if v.Args[0].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004515 break
Todd Nealcdc36252015-10-27 17:46:53 -05004516 }
4517 c := v.Args[0].AuxInt
4518 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004519 break
Todd Nealcdc36252015-10-27 17:46:53 -05004520 }
4521 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004522 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05004523 v.AuxInt = b2i(int32(c) != int32(d))
4524 return true
4525 }
Keith Randalla347ab72015-10-26 21:49:31 -07004526 return false
4527}
4528func rewriteValuegeneric_OpNeq64(v *Value, config *Config) bool {
4529 b := v.Block
4530 _ = b
4531 // match: (Neq64 x x)
4532 // cond:
4533 // result: (ConstBool [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01004534 for {
Keith Randalla347ab72015-10-26 21:49:31 -07004535 x := v.Args[0]
4536 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004537 break
Keith Randalla347ab72015-10-26 21:49:31 -07004538 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004539 v.reset(OpConstBool)
Keith Randalla347ab72015-10-26 21:49:31 -07004540 v.AuxInt = 0
4541 return true
4542 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004543 // match: (Neq64 (Const64 <t> [c]) (Add64 (Const64 <t> [d]) x))
4544 // cond:
4545 // result: (Neq64 (Const64 <t> [c-d]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01004546 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004547 if v.Args[0].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004548 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004549 }
4550 t := v.Args[0].Type
4551 c := v.Args[0].AuxInt
4552 if v.Args[1].Op != OpAdd64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004553 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004554 }
4555 if v.Args[1].Args[0].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004556 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004557 }
4558 if v.Args[1].Args[0].Type != v.Args[0].Type {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004559 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004560 }
4561 d := v.Args[1].Args[0].AuxInt
4562 x := v.Args[1].Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004563 v.reset(OpNeq64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004564 v0 := b.NewValue0(v.Line, OpConst64, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004565 v0.AuxInt = c - d
4566 v.AddArg(v0)
4567 v.AddArg(x)
4568 return true
4569 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004570 // match: (Neq64 x (Const64 <t> [c]))
4571 // cond: x.Op != OpConst64
4572 // result: (Neq64 (Const64 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01004573 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004574 x := v.Args[0]
4575 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004576 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004577 }
4578 t := v.Args[1].Type
4579 c := v.Args[1].AuxInt
4580 if !(x.Op != OpConst64) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004581 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004582 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004583 v.reset(OpNeq64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004584 v0 := b.NewValue0(v.Line, OpConst64, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004585 v0.AuxInt = c
4586 v.AddArg(v0)
4587 v.AddArg(x)
4588 return true
4589 }
Todd Nealcdc36252015-10-27 17:46:53 -05004590 // match: (Neq64 (Const64 [c]) (Const64 [d]))
4591 // cond:
4592 // result: (ConstBool [b2i(int64(c) != int64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01004593 for {
Todd Nealcdc36252015-10-27 17:46:53 -05004594 if v.Args[0].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004595 break
Todd Nealcdc36252015-10-27 17:46:53 -05004596 }
4597 c := v.Args[0].AuxInt
4598 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004599 break
Todd Nealcdc36252015-10-27 17:46:53 -05004600 }
4601 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004602 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05004603 v.AuxInt = b2i(int64(c) != int64(d))
4604 return true
4605 }
Keith Randalla347ab72015-10-26 21:49:31 -07004606 return false
4607}
4608func rewriteValuegeneric_OpNeq8(v *Value, config *Config) bool {
4609 b := v.Block
4610 _ = b
4611 // match: (Neq8 x x)
4612 // cond:
4613 // result: (ConstBool [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01004614 for {
Keith Randalla347ab72015-10-26 21:49:31 -07004615 x := v.Args[0]
4616 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004617 break
Keith Randalla347ab72015-10-26 21:49:31 -07004618 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004619 v.reset(OpConstBool)
Keith Randalla347ab72015-10-26 21:49:31 -07004620 v.AuxInt = 0
4621 return true
4622 }
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +01004623 // match: (Neq8 (ConstBool [c]) (ConstBool [d]))
4624 // cond:
4625 // result: (ConstBool [b2i((int8(c) != 0) != (int8(d) != 0))])
4626 for {
4627 if v.Args[0].Op != OpConstBool {
4628 break
4629 }
4630 c := v.Args[0].AuxInt
4631 if v.Args[1].Op != OpConstBool {
4632 break
4633 }
4634 d := v.Args[1].AuxInt
4635 v.reset(OpConstBool)
4636 v.AuxInt = b2i((int8(c) != 0) != (int8(d) != 0))
4637 return true
4638 }
4639 // match: (Neq8 (ConstBool [0]) x)
4640 // cond:
4641 // result: x
4642 for {
4643 if v.Args[0].Op != OpConstBool {
4644 break
4645 }
4646 if v.Args[0].AuxInt != 0 {
4647 break
4648 }
4649 x := v.Args[1]
4650 v.reset(OpCopy)
4651 v.Type = x.Type
4652 v.AddArg(x)
4653 return true
4654 }
4655 // match: (Neq8 (ConstBool [1]) x)
4656 // cond:
4657 // result: (Not x)
4658 for {
4659 if v.Args[0].Op != OpConstBool {
4660 break
4661 }
4662 if v.Args[0].AuxInt != 1 {
4663 break
4664 }
4665 x := v.Args[1]
4666 v.reset(OpNot)
4667 v.AddArg(x)
4668 return true
4669 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004670 // match: (Neq8 (Const8 <t> [c]) (Add8 (Const8 <t> [d]) x))
4671 // cond:
4672 // result: (Neq8 (Const8 <t> [c-d]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01004673 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004674 if v.Args[0].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004675 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004676 }
4677 t := v.Args[0].Type
4678 c := v.Args[0].AuxInt
4679 if v.Args[1].Op != OpAdd8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004680 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004681 }
4682 if v.Args[1].Args[0].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004683 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004684 }
4685 if v.Args[1].Args[0].Type != v.Args[0].Type {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004686 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004687 }
4688 d := v.Args[1].Args[0].AuxInt
4689 x := v.Args[1].Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004690 v.reset(OpNeq8)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004691 v0 := b.NewValue0(v.Line, OpConst8, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004692 v0.AuxInt = c - d
4693 v.AddArg(v0)
4694 v.AddArg(x)
4695 return true
4696 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004697 // match: (Neq8 x (Const8 <t> [c]))
4698 // cond: x.Op != OpConst8
4699 // result: (Neq8 (Const8 <t> [c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01004700 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004701 x := v.Args[0]
4702 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004703 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004704 }
4705 t := v.Args[1].Type
4706 c := v.Args[1].AuxInt
4707 if !(x.Op != OpConst8) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004708 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004709 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004710 v.reset(OpNeq8)
Todd Neal93a0b0f2016-02-03 06:21:24 -05004711 v0 := b.NewValue0(v.Line, OpConst8, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01004712 v0.AuxInt = c
4713 v.AddArg(v0)
4714 v.AddArg(x)
4715 return true
4716 }
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +01004717 // match: (Neq8 x (ConstBool <t> [c]))
4718 // cond: x.Op != OpConstBool
4719 // result: (Neq8 (ConstBool <t> [c]) x)
4720 for {
4721 x := v.Args[0]
4722 if v.Args[1].Op != OpConstBool {
4723 break
4724 }
4725 t := v.Args[1].Type
4726 c := v.Args[1].AuxInt
4727 if !(x.Op != OpConstBool) {
4728 break
4729 }
4730 v.reset(OpNeq8)
4731 v0 := b.NewValue0(v.Line, OpConstBool, t)
4732 v0.AuxInt = c
4733 v.AddArg(v0)
4734 v.AddArg(x)
4735 return true
4736 }
Todd Nealcdc36252015-10-27 17:46:53 -05004737 // match: (Neq8 (Const8 [c]) (Const8 [d]))
4738 // cond:
4739 // result: (ConstBool [b2i(int8(c) != int8(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01004740 for {
Todd Nealcdc36252015-10-27 17:46:53 -05004741 if v.Args[0].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004742 break
Todd Nealcdc36252015-10-27 17:46:53 -05004743 }
4744 c := v.Args[0].AuxInt
4745 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004746 break
Todd Nealcdc36252015-10-27 17:46:53 -05004747 }
4748 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004749 v.reset(OpConstBool)
Todd Nealcdc36252015-10-27 17:46:53 -05004750 v.AuxInt = b2i(int8(c) != int8(d))
4751 return true
4752 }
Keith Randalla347ab72015-10-26 21:49:31 -07004753 return false
4754}
4755func rewriteValuegeneric_OpNeqInter(v *Value, config *Config) bool {
4756 b := v.Block
4757 _ = b
4758 // match: (NeqInter x y)
4759 // cond:
4760 // result: (NeqPtr (ITab x) (ITab y))
Alexandru Moșoi05434472016-02-04 19:52:10 +01004761 for {
Keith Randalla347ab72015-10-26 21:49:31 -07004762 x := v.Args[0]
4763 y := v.Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004764 v.reset(OpNeqPtr)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01004765 v0 := b.NewValue0(v.Line, OpITab, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07004766 v0.AddArg(x)
Keith Randalla347ab72015-10-26 21:49:31 -07004767 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01004768 v1 := b.NewValue0(v.Line, OpITab, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07004769 v1.AddArg(y)
Keith Randalla347ab72015-10-26 21:49:31 -07004770 v.AddArg(v1)
4771 return true
4772 }
Keith Randalla347ab72015-10-26 21:49:31 -07004773 return false
4774}
4775func rewriteValuegeneric_OpNeqPtr(v *Value, config *Config) bool {
4776 b := v.Block
4777 _ = b
4778 // match: (NeqPtr p (ConstNil))
4779 // cond:
4780 // result: (IsNonNil p)
Alexandru Moșoi05434472016-02-04 19:52:10 +01004781 for {
Keith Randalla347ab72015-10-26 21:49:31 -07004782 p := v.Args[0]
4783 if v.Args[1].Op != OpConstNil {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004784 break
Keith Randalla347ab72015-10-26 21:49:31 -07004785 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004786 v.reset(OpIsNonNil)
Keith Randalla347ab72015-10-26 21:49:31 -07004787 v.AddArg(p)
4788 return true
4789 }
Keith Randalla347ab72015-10-26 21:49:31 -07004790 // match: (NeqPtr (ConstNil) p)
4791 // cond:
4792 // result: (IsNonNil p)
Alexandru Moșoi05434472016-02-04 19:52:10 +01004793 for {
Keith Randalla347ab72015-10-26 21:49:31 -07004794 if v.Args[0].Op != OpConstNil {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004795 break
Keith Randalla347ab72015-10-26 21:49:31 -07004796 }
4797 p := v.Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004798 v.reset(OpIsNonNil)
Keith Randalla347ab72015-10-26 21:49:31 -07004799 v.AddArg(p)
4800 return true
4801 }
Keith Randalla347ab72015-10-26 21:49:31 -07004802 return false
4803}
4804func rewriteValuegeneric_OpNeqSlice(v *Value, config *Config) bool {
4805 b := v.Block
4806 _ = b
4807 // match: (NeqSlice x y)
4808 // cond:
4809 // result: (NeqPtr (SlicePtr x) (SlicePtr y))
Alexandru Moșoi05434472016-02-04 19:52:10 +01004810 for {
Keith Randalla347ab72015-10-26 21:49:31 -07004811 x := v.Args[0]
4812 y := v.Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004813 v.reset(OpNeqPtr)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01004814 v0 := b.NewValue0(v.Line, OpSlicePtr, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07004815 v0.AddArg(x)
Keith Randalla347ab72015-10-26 21:49:31 -07004816 v.AddArg(v0)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01004817 v1 := b.NewValue0(v.Line, OpSlicePtr, config.fe.TypeBytePtr())
Keith Randalla347ab72015-10-26 21:49:31 -07004818 v1.AddArg(y)
Keith Randalla347ab72015-10-26 21:49:31 -07004819 v.AddArg(v1)
4820 return true
4821 }
Keith Randalla347ab72015-10-26 21:49:31 -07004822 return false
4823}
4824func rewriteValuegeneric_OpOr16(v *Value, config *Config) bool {
4825 b := v.Block
4826 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01004827 // match: (Or16 x (Const16 <t> [c]))
4828 // cond: x.Op != OpConst16
4829 // result: (Or16 (Const16 <t> [c]) x)
4830 for {
4831 x := v.Args[0]
4832 if v.Args[1].Op != OpConst16 {
4833 break
4834 }
4835 t := v.Args[1].Type
4836 c := v.Args[1].AuxInt
4837 if !(x.Op != OpConst16) {
4838 break
4839 }
4840 v.reset(OpOr16)
4841 v0 := b.NewValue0(v.Line, OpConst16, t)
4842 v0.AuxInt = c
4843 v.AddArg(v0)
4844 v.AddArg(x)
4845 return true
4846 }
Keith Randalla347ab72015-10-26 21:49:31 -07004847 // match: (Or16 x x)
4848 // cond:
4849 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01004850 for {
Keith Randalla347ab72015-10-26 21:49:31 -07004851 x := v.Args[0]
4852 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004853 break
Keith Randalla347ab72015-10-26 21:49:31 -07004854 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004855 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07004856 v.Type = x.Type
4857 v.AddArg(x)
4858 return true
4859 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01004860 // match: (Or16 (Const16 [0]) x)
4861 // cond:
4862 // result: x
4863 for {
4864 if v.Args[0].Op != OpConst16 {
4865 break
4866 }
4867 if v.Args[0].AuxInt != 0 {
4868 break
4869 }
4870 x := v.Args[1]
4871 v.reset(OpCopy)
4872 v.Type = x.Type
4873 v.AddArg(x)
4874 return true
4875 }
4876 // match: (Or16 (Const16 [-1]) _)
4877 // cond:
4878 // result: (Const16 [-1])
4879 for {
4880 if v.Args[0].Op != OpConst16 {
4881 break
4882 }
4883 if v.Args[0].AuxInt != -1 {
4884 break
4885 }
4886 v.reset(OpConst16)
4887 v.AuxInt = -1
4888 return true
4889 }
Keith Randalla347ab72015-10-26 21:49:31 -07004890 return false
4891}
4892func rewriteValuegeneric_OpOr32(v *Value, config *Config) bool {
4893 b := v.Block
4894 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01004895 // match: (Or32 x (Const32 <t> [c]))
4896 // cond: x.Op != OpConst32
4897 // result: (Or32 (Const32 <t> [c]) x)
4898 for {
4899 x := v.Args[0]
4900 if v.Args[1].Op != OpConst32 {
4901 break
4902 }
4903 t := v.Args[1].Type
4904 c := v.Args[1].AuxInt
4905 if !(x.Op != OpConst32) {
4906 break
4907 }
4908 v.reset(OpOr32)
4909 v0 := b.NewValue0(v.Line, OpConst32, t)
4910 v0.AuxInt = c
4911 v.AddArg(v0)
4912 v.AddArg(x)
4913 return true
4914 }
Keith Randalla347ab72015-10-26 21:49:31 -07004915 // match: (Or32 x x)
4916 // cond:
4917 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01004918 for {
Keith Randalla347ab72015-10-26 21:49:31 -07004919 x := v.Args[0]
4920 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004921 break
Keith Randalla347ab72015-10-26 21:49:31 -07004922 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004923 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07004924 v.Type = x.Type
4925 v.AddArg(x)
4926 return true
4927 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01004928 // match: (Or32 (Const32 [0]) x)
4929 // cond:
4930 // result: x
4931 for {
4932 if v.Args[0].Op != OpConst32 {
4933 break
4934 }
4935 if v.Args[0].AuxInt != 0 {
4936 break
4937 }
4938 x := v.Args[1]
4939 v.reset(OpCopy)
4940 v.Type = x.Type
4941 v.AddArg(x)
4942 return true
4943 }
4944 // match: (Or32 (Const32 [-1]) _)
4945 // cond:
4946 // result: (Const32 [-1])
4947 for {
4948 if v.Args[0].Op != OpConst32 {
4949 break
4950 }
4951 if v.Args[0].AuxInt != -1 {
4952 break
4953 }
4954 v.reset(OpConst32)
4955 v.AuxInt = -1
4956 return true
4957 }
Keith Randalla347ab72015-10-26 21:49:31 -07004958 return false
4959}
4960func rewriteValuegeneric_OpOr64(v *Value, config *Config) bool {
4961 b := v.Block
4962 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01004963 // match: (Or64 x (Const64 <t> [c]))
4964 // cond: x.Op != OpConst64
4965 // result: (Or64 (Const64 <t> [c]) x)
4966 for {
4967 x := v.Args[0]
4968 if v.Args[1].Op != OpConst64 {
4969 break
4970 }
4971 t := v.Args[1].Type
4972 c := v.Args[1].AuxInt
4973 if !(x.Op != OpConst64) {
4974 break
4975 }
4976 v.reset(OpOr64)
4977 v0 := b.NewValue0(v.Line, OpConst64, t)
4978 v0.AuxInt = c
4979 v.AddArg(v0)
4980 v.AddArg(x)
4981 return true
4982 }
Keith Randalla347ab72015-10-26 21:49:31 -07004983 // match: (Or64 x x)
4984 // cond:
4985 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01004986 for {
Keith Randalla347ab72015-10-26 21:49:31 -07004987 x := v.Args[0]
4988 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01004989 break
Keith Randalla347ab72015-10-26 21:49:31 -07004990 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01004991 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07004992 v.Type = x.Type
4993 v.AddArg(x)
4994 return true
4995 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01004996 // match: (Or64 (Const64 [0]) x)
4997 // cond:
4998 // result: x
4999 for {
5000 if v.Args[0].Op != OpConst64 {
5001 break
5002 }
5003 if v.Args[0].AuxInt != 0 {
5004 break
5005 }
5006 x := v.Args[1]
5007 v.reset(OpCopy)
5008 v.Type = x.Type
5009 v.AddArg(x)
5010 return true
5011 }
5012 // match: (Or64 (Const64 [-1]) _)
5013 // cond:
5014 // result: (Const64 [-1])
5015 for {
5016 if v.Args[0].Op != OpConst64 {
5017 break
5018 }
5019 if v.Args[0].AuxInt != -1 {
5020 break
5021 }
5022 v.reset(OpConst64)
5023 v.AuxInt = -1
5024 return true
5025 }
Keith Randalla347ab72015-10-26 21:49:31 -07005026 return false
5027}
5028func rewriteValuegeneric_OpOr8(v *Value, config *Config) bool {
5029 b := v.Block
5030 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005031 // match: (Or8 x (Const8 <t> [c]))
5032 // cond: x.Op != OpConst8
5033 // result: (Or8 (Const8 <t> [c]) x)
5034 for {
5035 x := v.Args[0]
5036 if v.Args[1].Op != OpConst8 {
5037 break
5038 }
5039 t := v.Args[1].Type
5040 c := v.Args[1].AuxInt
5041 if !(x.Op != OpConst8) {
5042 break
5043 }
5044 v.reset(OpOr8)
5045 v0 := b.NewValue0(v.Line, OpConst8, t)
5046 v0.AuxInt = c
5047 v.AddArg(v0)
5048 v.AddArg(x)
5049 return true
5050 }
Keith Randalla347ab72015-10-26 21:49:31 -07005051 // match: (Or8 x x)
5052 // cond:
5053 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01005054 for {
Keith Randalla347ab72015-10-26 21:49:31 -07005055 x := v.Args[0]
5056 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005057 break
Keith Randalla347ab72015-10-26 21:49:31 -07005058 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005059 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07005060 v.Type = x.Type
5061 v.AddArg(x)
5062 return true
5063 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005064 // match: (Or8 (Const8 [0]) x)
5065 // cond:
5066 // result: x
5067 for {
5068 if v.Args[0].Op != OpConst8 {
5069 break
5070 }
5071 if v.Args[0].AuxInt != 0 {
5072 break
5073 }
5074 x := v.Args[1]
5075 v.reset(OpCopy)
5076 v.Type = x.Type
5077 v.AddArg(x)
5078 return true
5079 }
5080 // match: (Or8 (Const8 [-1]) _)
5081 // cond:
5082 // result: (Const8 [-1])
5083 for {
5084 if v.Args[0].Op != OpConst8 {
5085 break
5086 }
5087 if v.Args[0].AuxInt != -1 {
5088 break
5089 }
5090 v.reset(OpConst8)
5091 v.AuxInt = -1
5092 return true
5093 }
Keith Randalla347ab72015-10-26 21:49:31 -07005094 return false
5095}
Alexandru Moșoid0d04d22016-02-09 19:46:26 +01005096func rewriteValuegeneric_OpPhi(v *Value, config *Config) bool {
5097 b := v.Block
5098 _ = b
5099 // match: (Phi (Const8 [c]) (Const8 [d]))
5100 // cond: int8(c) == int8(d)
5101 // result: (Const8 [c])
5102 for {
5103 if v.Args[0].Op != OpConst8 {
5104 break
5105 }
5106 c := v.Args[0].AuxInt
5107 if v.Args[1].Op != OpConst8 {
5108 break
5109 }
5110 d := v.Args[1].AuxInt
5111 if len(v.Args) != 2 {
5112 break
5113 }
5114 if !(int8(c) == int8(d)) {
5115 break
5116 }
5117 v.reset(OpConst8)
5118 v.AuxInt = c
5119 return true
5120 }
5121 // match: (Phi (Const16 [c]) (Const16 [d]))
5122 // cond: int16(c) == int16(d)
5123 // result: (Const16 [c])
5124 for {
5125 if v.Args[0].Op != OpConst16 {
5126 break
5127 }
5128 c := v.Args[0].AuxInt
5129 if v.Args[1].Op != OpConst16 {
5130 break
5131 }
5132 d := v.Args[1].AuxInt
5133 if len(v.Args) != 2 {
5134 break
5135 }
5136 if !(int16(c) == int16(d)) {
5137 break
5138 }
5139 v.reset(OpConst16)
5140 v.AuxInt = c
5141 return true
5142 }
5143 // match: (Phi (Const32 [c]) (Const32 [d]))
5144 // cond: int32(c) == int32(d)
5145 // result: (Const32 [c])
5146 for {
5147 if v.Args[0].Op != OpConst32 {
5148 break
5149 }
5150 c := v.Args[0].AuxInt
5151 if v.Args[1].Op != OpConst32 {
5152 break
5153 }
5154 d := v.Args[1].AuxInt
5155 if len(v.Args) != 2 {
5156 break
5157 }
5158 if !(int32(c) == int32(d)) {
5159 break
5160 }
5161 v.reset(OpConst32)
5162 v.AuxInt = c
5163 return true
5164 }
5165 // match: (Phi (Const64 [c]) (Const64 [c]))
5166 // cond:
5167 // result: (Const64 [c])
5168 for {
5169 if v.Args[0].Op != OpConst64 {
5170 break
5171 }
5172 c := v.Args[0].AuxInt
5173 if v.Args[1].Op != OpConst64 {
5174 break
5175 }
5176 if v.Args[1].AuxInt != v.Args[0].AuxInt {
5177 break
5178 }
5179 if len(v.Args) != 2 {
5180 break
5181 }
5182 v.reset(OpConst64)
5183 v.AuxInt = c
5184 return true
5185 }
5186 return false
5187}
Keith Randalla347ab72015-10-26 21:49:31 -07005188func rewriteValuegeneric_OpPtrIndex(v *Value, config *Config) bool {
5189 b := v.Block
5190 _ = b
5191 // match: (PtrIndex <t> ptr idx)
Keith Randall582baae2015-11-02 21:28:13 -08005192 // cond: config.PtrSize == 4
5193 // result: (AddPtr ptr (Mul32 <config.fe.TypeInt()> idx (Const32 <config.fe.TypeInt()> [t.Elem().Size()])))
Alexandru Moșoi05434472016-02-04 19:52:10 +01005194 for {
Keith Randalla347ab72015-10-26 21:49:31 -07005195 t := v.Type
5196 ptr := v.Args[0]
5197 idx := v.Args[1]
Keith Randall582baae2015-11-02 21:28:13 -08005198 if !(config.PtrSize == 4) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005199 break
Keith Randall582baae2015-11-02 21:28:13 -08005200 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005201 v.reset(OpAddPtr)
Keith Randalla347ab72015-10-26 21:49:31 -07005202 v.AddArg(ptr)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01005203 v0 := b.NewValue0(v.Line, OpMul32, config.fe.TypeInt())
Keith Randalla347ab72015-10-26 21:49:31 -07005204 v0.AddArg(idx)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01005205 v1 := b.NewValue0(v.Line, OpConst32, config.fe.TypeInt())
Keith Randalla347ab72015-10-26 21:49:31 -07005206 v1.AuxInt = t.Elem().Size()
Keith Randalla347ab72015-10-26 21:49:31 -07005207 v0.AddArg(v1)
Keith Randalla347ab72015-10-26 21:49:31 -07005208 v.AddArg(v0)
5209 return true
5210 }
Keith Randall582baae2015-11-02 21:28:13 -08005211 // match: (PtrIndex <t> ptr idx)
5212 // cond: config.PtrSize == 8
5213 // result: (AddPtr ptr (Mul64 <config.fe.TypeInt()> idx (Const64 <config.fe.TypeInt()> [t.Elem().Size()])))
Alexandru Moșoi05434472016-02-04 19:52:10 +01005214 for {
Keith Randall582baae2015-11-02 21:28:13 -08005215 t := v.Type
5216 ptr := v.Args[0]
5217 idx := v.Args[1]
5218 if !(config.PtrSize == 8) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005219 break
Keith Randall582baae2015-11-02 21:28:13 -08005220 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005221 v.reset(OpAddPtr)
Keith Randall582baae2015-11-02 21:28:13 -08005222 v.AddArg(ptr)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01005223 v0 := b.NewValue0(v.Line, OpMul64, config.fe.TypeInt())
Keith Randall582baae2015-11-02 21:28:13 -08005224 v0.AddArg(idx)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01005225 v1 := b.NewValue0(v.Line, OpConst64, config.fe.TypeInt())
Keith Randall582baae2015-11-02 21:28:13 -08005226 v1.AuxInt = t.Elem().Size()
5227 v0.AddArg(v1)
5228 v.AddArg(v0)
5229 return true
5230 }
Keith Randalla347ab72015-10-26 21:49:31 -07005231 return false
5232}
Todd Neal93a0b0f2016-02-03 06:21:24 -05005233func rewriteValuegeneric_OpRsh16Ux16(v *Value, config *Config) bool {
5234 b := v.Block
5235 _ = b
5236 // match: (Rsh16Ux16 <t> x (Const16 [c]))
5237 // cond:
5238 // result: (Rsh16Ux64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01005239 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005240 t := v.Type
5241 x := v.Args[0]
5242 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005243 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005244 }
5245 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005246 v.reset(OpRsh16Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005247 v.AddArg(x)
5248 v0 := b.NewValue0(v.Line, OpConst64, t)
5249 v0.AuxInt = int64(uint16(c))
5250 v.AddArg(v0)
5251 return true
5252 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005253 return false
5254}
5255func rewriteValuegeneric_OpRsh16Ux32(v *Value, config *Config) bool {
5256 b := v.Block
5257 _ = b
5258 // match: (Rsh16Ux32 <t> x (Const32 [c]))
5259 // cond:
5260 // result: (Rsh16Ux64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01005261 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005262 t := v.Type
5263 x := v.Args[0]
5264 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005265 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005266 }
5267 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005268 v.reset(OpRsh16Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005269 v.AddArg(x)
5270 v0 := b.NewValue0(v.Line, OpConst64, t)
5271 v0.AuxInt = int64(uint32(c))
5272 v.AddArg(v0)
5273 return true
5274 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005275 return false
5276}
5277func rewriteValuegeneric_OpRsh16Ux64(v *Value, config *Config) bool {
5278 b := v.Block
5279 _ = b
5280 // match: (Rsh16Ux64 (Const16 [c]) (Const64 [d]))
5281 // cond:
5282 // result: (Const16 [int64(uint16(c) >> uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01005283 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005284 if v.Args[0].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005285 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005286 }
5287 c := v.Args[0].AuxInt
5288 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005289 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005290 }
5291 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005292 v.reset(OpConst16)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005293 v.AuxInt = int64(uint16(c) >> uint64(d))
5294 return true
5295 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01005296 // match: (Rsh16Ux64 (Const16 [0]) _)
5297 // cond:
5298 // result: (Const16 [0])
5299 for {
5300 if v.Args[0].Op != OpConst16 {
5301 break
5302 }
5303 if v.Args[0].AuxInt != 0 {
5304 break
5305 }
5306 v.reset(OpConst16)
5307 v.AuxInt = 0
5308 return true
5309 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005310 // match: (Rsh16Ux64 x (Const64 [0]))
5311 // cond:
5312 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01005313 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005314 x := v.Args[0]
5315 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005316 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005317 }
5318 if v.Args[1].AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005319 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005320 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005321 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005322 v.Type = x.Type
5323 v.AddArg(x)
5324 return true
5325 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005326 // match: (Rsh16Ux64 _ (Const64 [c]))
5327 // cond: uint64(c) >= 16
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01005328 // result: (Const16 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01005329 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005330 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005331 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005332 }
5333 c := v.Args[1].AuxInt
5334 if !(uint64(c) >= 16) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005335 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005336 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01005337 v.reset(OpConst16)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005338 v.AuxInt = 0
5339 return true
5340 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005341 // match: (Rsh16Ux64 <t> (Rsh16Ux64 x (Const64 [c])) (Const64 [d]))
5342 // cond: !uaddOvf(c,d)
5343 // result: (Rsh16Ux64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01005344 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005345 t := v.Type
5346 if v.Args[0].Op != OpRsh16Ux64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005347 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005348 }
5349 x := v.Args[0].Args[0]
5350 if v.Args[0].Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005351 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005352 }
5353 c := v.Args[0].Args[1].AuxInt
5354 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005355 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005356 }
5357 d := v.Args[1].AuxInt
5358 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005359 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005360 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005361 v.reset(OpRsh16Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005362 v.AddArg(x)
5363 v0 := b.NewValue0(v.Line, OpConst64, t)
5364 v0.AuxInt = c + d
5365 v.AddArg(v0)
5366 return true
5367 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005368 return false
5369}
5370func rewriteValuegeneric_OpRsh16Ux8(v *Value, config *Config) bool {
5371 b := v.Block
5372 _ = b
5373 // match: (Rsh16Ux8 <t> x (Const8 [c]))
5374 // cond:
5375 // result: (Rsh16Ux64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01005376 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005377 t := v.Type
5378 x := v.Args[0]
5379 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005380 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005381 }
5382 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005383 v.reset(OpRsh16Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005384 v.AddArg(x)
5385 v0 := b.NewValue0(v.Line, OpConst64, t)
5386 v0.AuxInt = int64(uint8(c))
5387 v.AddArg(v0)
5388 return true
5389 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005390 return false
5391}
5392func rewriteValuegeneric_OpRsh16x16(v *Value, config *Config) bool {
5393 b := v.Block
5394 _ = b
5395 // match: (Rsh16x16 <t> x (Const16 [c]))
5396 // cond:
5397 // result: (Rsh16x64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01005398 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005399 t := v.Type
5400 x := v.Args[0]
5401 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005402 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005403 }
5404 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005405 v.reset(OpRsh16x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005406 v.AddArg(x)
5407 v0 := b.NewValue0(v.Line, OpConst64, t)
5408 v0.AuxInt = int64(uint16(c))
5409 v.AddArg(v0)
5410 return true
5411 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005412 return false
5413}
5414func rewriteValuegeneric_OpRsh16x32(v *Value, config *Config) bool {
5415 b := v.Block
5416 _ = b
5417 // match: (Rsh16x32 <t> x (Const32 [c]))
5418 // cond:
5419 // result: (Rsh16x64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01005420 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005421 t := v.Type
5422 x := v.Args[0]
5423 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005424 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005425 }
5426 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005427 v.reset(OpRsh16x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005428 v.AddArg(x)
5429 v0 := b.NewValue0(v.Line, OpConst64, t)
5430 v0.AuxInt = int64(uint32(c))
5431 v.AddArg(v0)
5432 return true
5433 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005434 return false
5435}
5436func rewriteValuegeneric_OpRsh16x64(v *Value, config *Config) bool {
5437 b := v.Block
5438 _ = b
5439 // match: (Rsh16x64 (Const16 [c]) (Const64 [d]))
5440 // cond:
5441 // result: (Const16 [int64(int16(c) >> uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01005442 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005443 if v.Args[0].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005444 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005445 }
5446 c := v.Args[0].AuxInt
5447 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005448 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005449 }
5450 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005451 v.reset(OpConst16)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005452 v.AuxInt = int64(int16(c) >> uint64(d))
5453 return true
5454 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01005455 // match: (Rsh16x64 (Const16 [0]) _)
5456 // cond:
5457 // result: (Const16 [0])
5458 for {
5459 if v.Args[0].Op != OpConst16 {
5460 break
5461 }
5462 if v.Args[0].AuxInt != 0 {
5463 break
5464 }
5465 v.reset(OpConst16)
5466 v.AuxInt = 0
5467 return true
5468 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005469 // match: (Rsh16x64 x (Const64 [0]))
5470 // cond:
5471 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01005472 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005473 x := v.Args[0]
5474 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005475 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005476 }
5477 if v.Args[1].AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005478 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005479 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005480 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005481 v.Type = x.Type
5482 v.AddArg(x)
5483 return true
5484 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005485 // match: (Rsh16x64 <t> (Rsh16x64 x (Const64 [c])) (Const64 [d]))
5486 // cond: !uaddOvf(c,d)
5487 // result: (Rsh16x64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01005488 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005489 t := v.Type
5490 if v.Args[0].Op != OpRsh16x64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005491 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005492 }
5493 x := v.Args[0].Args[0]
5494 if v.Args[0].Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005495 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005496 }
5497 c := v.Args[0].Args[1].AuxInt
5498 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005499 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005500 }
5501 d := v.Args[1].AuxInt
5502 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005503 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005504 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005505 v.reset(OpRsh16x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005506 v.AddArg(x)
5507 v0 := b.NewValue0(v.Line, OpConst64, t)
5508 v0.AuxInt = c + d
5509 v.AddArg(v0)
5510 return true
5511 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005512 return false
5513}
5514func rewriteValuegeneric_OpRsh16x8(v *Value, config *Config) bool {
5515 b := v.Block
5516 _ = b
5517 // match: (Rsh16x8 <t> x (Const8 [c]))
5518 // cond:
5519 // result: (Rsh16x64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01005520 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005521 t := v.Type
5522 x := v.Args[0]
5523 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005524 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005525 }
5526 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005527 v.reset(OpRsh16x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005528 v.AddArg(x)
5529 v0 := b.NewValue0(v.Line, OpConst64, t)
5530 v0.AuxInt = int64(uint8(c))
5531 v.AddArg(v0)
5532 return true
5533 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005534 return false
5535}
5536func rewriteValuegeneric_OpRsh32Ux16(v *Value, config *Config) bool {
5537 b := v.Block
5538 _ = b
5539 // match: (Rsh32Ux16 <t> x (Const16 [c]))
5540 // cond:
5541 // result: (Rsh32Ux64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01005542 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005543 t := v.Type
5544 x := v.Args[0]
5545 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005546 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005547 }
5548 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005549 v.reset(OpRsh32Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005550 v.AddArg(x)
5551 v0 := b.NewValue0(v.Line, OpConst64, t)
5552 v0.AuxInt = int64(uint16(c))
5553 v.AddArg(v0)
5554 return true
5555 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005556 return false
5557}
5558func rewriteValuegeneric_OpRsh32Ux32(v *Value, config *Config) bool {
5559 b := v.Block
5560 _ = b
5561 // match: (Rsh32Ux32 <t> x (Const32 [c]))
5562 // cond:
5563 // result: (Rsh32Ux64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01005564 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005565 t := v.Type
5566 x := v.Args[0]
5567 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005568 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005569 }
5570 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005571 v.reset(OpRsh32Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005572 v.AddArg(x)
5573 v0 := b.NewValue0(v.Line, OpConst64, t)
5574 v0.AuxInt = int64(uint32(c))
5575 v.AddArg(v0)
5576 return true
5577 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005578 return false
5579}
5580func rewriteValuegeneric_OpRsh32Ux64(v *Value, config *Config) bool {
5581 b := v.Block
5582 _ = b
5583 // match: (Rsh32Ux64 (Const32 [c]) (Const64 [d]))
5584 // cond:
5585 // result: (Const32 [int64(uint32(c) >> uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01005586 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005587 if v.Args[0].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005588 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005589 }
5590 c := v.Args[0].AuxInt
5591 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005592 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005593 }
5594 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005595 v.reset(OpConst32)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005596 v.AuxInt = int64(uint32(c) >> uint64(d))
5597 return true
5598 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01005599 // match: (Rsh32Ux64 (Const32 [0]) _)
5600 // cond:
5601 // result: (Const32 [0])
5602 for {
5603 if v.Args[0].Op != OpConst32 {
5604 break
5605 }
5606 if v.Args[0].AuxInt != 0 {
5607 break
5608 }
5609 v.reset(OpConst32)
5610 v.AuxInt = 0
5611 return true
5612 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005613 // match: (Rsh32Ux64 x (Const64 [0]))
5614 // cond:
5615 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01005616 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005617 x := v.Args[0]
5618 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005619 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005620 }
5621 if v.Args[1].AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005622 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005623 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005624 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005625 v.Type = x.Type
5626 v.AddArg(x)
5627 return true
5628 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005629 // match: (Rsh32Ux64 _ (Const64 [c]))
5630 // cond: uint64(c) >= 32
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01005631 // result: (Const32 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01005632 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005633 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005634 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005635 }
5636 c := v.Args[1].AuxInt
5637 if !(uint64(c) >= 32) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005638 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005639 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01005640 v.reset(OpConst32)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005641 v.AuxInt = 0
5642 return true
5643 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005644 // match: (Rsh32Ux64 <t> (Rsh32Ux64 x (Const64 [c])) (Const64 [d]))
5645 // cond: !uaddOvf(c,d)
5646 // result: (Rsh32Ux64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01005647 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005648 t := v.Type
5649 if v.Args[0].Op != OpRsh32Ux64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005650 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005651 }
5652 x := v.Args[0].Args[0]
5653 if v.Args[0].Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005654 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005655 }
5656 c := v.Args[0].Args[1].AuxInt
5657 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005658 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005659 }
5660 d := v.Args[1].AuxInt
5661 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005662 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005663 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005664 v.reset(OpRsh32Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005665 v.AddArg(x)
5666 v0 := b.NewValue0(v.Line, OpConst64, t)
5667 v0.AuxInt = c + d
5668 v.AddArg(v0)
5669 return true
5670 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005671 return false
5672}
5673func rewriteValuegeneric_OpRsh32Ux8(v *Value, config *Config) bool {
5674 b := v.Block
5675 _ = b
5676 // match: (Rsh32Ux8 <t> x (Const8 [c]))
5677 // cond:
5678 // result: (Rsh32Ux64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01005679 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005680 t := v.Type
5681 x := v.Args[0]
5682 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005683 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005684 }
5685 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005686 v.reset(OpRsh32Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005687 v.AddArg(x)
5688 v0 := b.NewValue0(v.Line, OpConst64, t)
5689 v0.AuxInt = int64(uint8(c))
5690 v.AddArg(v0)
5691 return true
5692 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005693 return false
5694}
5695func rewriteValuegeneric_OpRsh32x16(v *Value, config *Config) bool {
5696 b := v.Block
5697 _ = b
5698 // match: (Rsh32x16 <t> x (Const16 [c]))
5699 // cond:
5700 // result: (Rsh32x64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01005701 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005702 t := v.Type
5703 x := v.Args[0]
5704 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005705 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005706 }
5707 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005708 v.reset(OpRsh32x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005709 v.AddArg(x)
5710 v0 := b.NewValue0(v.Line, OpConst64, t)
5711 v0.AuxInt = int64(uint16(c))
5712 v.AddArg(v0)
5713 return true
5714 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005715 return false
5716}
5717func rewriteValuegeneric_OpRsh32x32(v *Value, config *Config) bool {
5718 b := v.Block
5719 _ = b
5720 // match: (Rsh32x32 <t> x (Const32 [c]))
5721 // cond:
5722 // result: (Rsh32x64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01005723 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005724 t := v.Type
5725 x := v.Args[0]
5726 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005727 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005728 }
5729 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005730 v.reset(OpRsh32x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005731 v.AddArg(x)
5732 v0 := b.NewValue0(v.Line, OpConst64, t)
5733 v0.AuxInt = int64(uint32(c))
5734 v.AddArg(v0)
5735 return true
5736 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005737 return false
5738}
5739func rewriteValuegeneric_OpRsh32x64(v *Value, config *Config) bool {
5740 b := v.Block
5741 _ = b
5742 // match: (Rsh32x64 (Const32 [c]) (Const64 [d]))
5743 // cond:
5744 // result: (Const32 [int64(int32(c) >> uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01005745 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005746 if v.Args[0].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005747 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005748 }
5749 c := v.Args[0].AuxInt
5750 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005751 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005752 }
5753 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005754 v.reset(OpConst32)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005755 v.AuxInt = int64(int32(c) >> uint64(d))
5756 return true
5757 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01005758 // match: (Rsh32x64 (Const32 [0]) _)
5759 // cond:
5760 // result: (Const32 [0])
5761 for {
5762 if v.Args[0].Op != OpConst32 {
5763 break
5764 }
5765 if v.Args[0].AuxInt != 0 {
5766 break
5767 }
5768 v.reset(OpConst32)
5769 v.AuxInt = 0
5770 return true
5771 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005772 // match: (Rsh32x64 x (Const64 [0]))
5773 // cond:
5774 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01005775 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005776 x := v.Args[0]
5777 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005778 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005779 }
5780 if v.Args[1].AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005781 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005782 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005783 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005784 v.Type = x.Type
5785 v.AddArg(x)
5786 return true
5787 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005788 // match: (Rsh32x64 <t> (Rsh32x64 x (Const64 [c])) (Const64 [d]))
5789 // cond: !uaddOvf(c,d)
5790 // result: (Rsh32x64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01005791 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005792 t := v.Type
5793 if v.Args[0].Op != OpRsh32x64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005794 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005795 }
5796 x := v.Args[0].Args[0]
5797 if v.Args[0].Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005798 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005799 }
5800 c := v.Args[0].Args[1].AuxInt
5801 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005802 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005803 }
5804 d := v.Args[1].AuxInt
5805 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005806 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005807 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005808 v.reset(OpRsh32x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005809 v.AddArg(x)
5810 v0 := b.NewValue0(v.Line, OpConst64, t)
5811 v0.AuxInt = c + d
5812 v.AddArg(v0)
5813 return true
5814 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005815 return false
5816}
5817func rewriteValuegeneric_OpRsh32x8(v *Value, config *Config) bool {
5818 b := v.Block
5819 _ = b
5820 // match: (Rsh32x8 <t> x (Const8 [c]))
5821 // cond:
5822 // result: (Rsh32x64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01005823 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005824 t := v.Type
5825 x := v.Args[0]
5826 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005827 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005828 }
5829 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005830 v.reset(OpRsh32x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005831 v.AddArg(x)
5832 v0 := b.NewValue0(v.Line, OpConst64, t)
5833 v0.AuxInt = int64(uint8(c))
5834 v.AddArg(v0)
5835 return true
5836 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005837 return false
5838}
5839func rewriteValuegeneric_OpRsh64Ux16(v *Value, config *Config) bool {
5840 b := v.Block
5841 _ = b
5842 // match: (Rsh64Ux16 <t> x (Const16 [c]))
5843 // cond:
5844 // result: (Rsh64Ux64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01005845 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005846 t := v.Type
5847 x := v.Args[0]
5848 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005849 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005850 }
5851 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005852 v.reset(OpRsh64Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005853 v.AddArg(x)
5854 v0 := b.NewValue0(v.Line, OpConst64, t)
5855 v0.AuxInt = int64(uint16(c))
5856 v.AddArg(v0)
5857 return true
5858 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005859 // match: (Rsh64Ux16 (Const64 [0]) _)
5860 // cond:
5861 // result: (Const64 [0])
5862 for {
5863 if v.Args[0].Op != OpConst64 {
5864 break
5865 }
5866 if v.Args[0].AuxInt != 0 {
5867 break
5868 }
5869 v.reset(OpConst64)
5870 v.AuxInt = 0
5871 return true
5872 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005873 return false
5874}
5875func rewriteValuegeneric_OpRsh64Ux32(v *Value, config *Config) bool {
5876 b := v.Block
5877 _ = b
5878 // match: (Rsh64Ux32 <t> x (Const32 [c]))
5879 // cond:
5880 // result: (Rsh64Ux64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01005881 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005882 t := v.Type
5883 x := v.Args[0]
5884 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005885 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005886 }
5887 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005888 v.reset(OpRsh64Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005889 v.AddArg(x)
5890 v0 := b.NewValue0(v.Line, OpConst64, t)
5891 v0.AuxInt = int64(uint32(c))
5892 v.AddArg(v0)
5893 return true
5894 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005895 // match: (Rsh64Ux32 (Const64 [0]) _)
5896 // cond:
5897 // result: (Const64 [0])
5898 for {
5899 if v.Args[0].Op != OpConst64 {
5900 break
5901 }
5902 if v.Args[0].AuxInt != 0 {
5903 break
5904 }
5905 v.reset(OpConst64)
5906 v.AuxInt = 0
5907 return true
5908 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005909 return false
5910}
5911func rewriteValuegeneric_OpRsh64Ux64(v *Value, config *Config) bool {
5912 b := v.Block
5913 _ = b
5914 // match: (Rsh64Ux64 (Const64 [c]) (Const64 [d]))
5915 // cond:
5916 // result: (Const64 [int64(uint64(c) >> uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01005917 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005918 if v.Args[0].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005919 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005920 }
5921 c := v.Args[0].AuxInt
5922 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005923 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005924 }
5925 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005926 v.reset(OpConst64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005927 v.AuxInt = int64(uint64(c) >> uint64(d))
5928 return true
5929 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01005930 // match: (Rsh64Ux64 (Const64 [0]) _)
5931 // cond:
5932 // result: (Const64 [0])
5933 for {
5934 if v.Args[0].Op != OpConst64 {
5935 break
5936 }
5937 if v.Args[0].AuxInt != 0 {
5938 break
5939 }
5940 v.reset(OpConst64)
5941 v.AuxInt = 0
5942 return true
5943 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005944 // match: (Rsh64Ux64 x (Const64 [0]))
5945 // cond:
5946 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01005947 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005948 x := v.Args[0]
5949 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005950 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005951 }
5952 if v.Args[1].AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005953 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005954 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005955 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005956 v.Type = x.Type
5957 v.AddArg(x)
5958 return true
5959 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01005960 // match: (Rsh64Ux64 (Const64 [0]) _)
5961 // cond:
5962 // result: (Const64 [0])
5963 for {
5964 if v.Args[0].Op != OpConst64 {
5965 break
5966 }
5967 if v.Args[0].AuxInt != 0 {
5968 break
5969 }
5970 v.reset(OpConst64)
5971 v.AuxInt = 0
5972 return true
5973 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005974 // match: (Rsh64Ux64 _ (Const64 [c]))
5975 // cond: uint64(c) >= 64
5976 // result: (Const64 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01005977 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005978 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005979 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005980 }
5981 c := v.Args[1].AuxInt
5982 if !(uint64(c) >= 64) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005983 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005984 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01005985 v.reset(OpConst64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05005986 v.AuxInt = 0
5987 return true
5988 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05005989 // match: (Rsh64Ux64 <t> (Rsh64Ux64 x (Const64 [c])) (Const64 [d]))
5990 // cond: !uaddOvf(c,d)
5991 // result: (Rsh64Ux64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01005992 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05005993 t := v.Type
5994 if v.Args[0].Op != OpRsh64Ux64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005995 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05005996 }
5997 x := v.Args[0].Args[0]
5998 if v.Args[0].Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01005999 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006000 }
6001 c := v.Args[0].Args[1].AuxInt
6002 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006003 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006004 }
6005 d := v.Args[1].AuxInt
6006 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006007 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006008 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006009 v.reset(OpRsh64Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006010 v.AddArg(x)
6011 v0 := b.NewValue0(v.Line, OpConst64, t)
6012 v0.AuxInt = c + d
6013 v.AddArg(v0)
6014 return true
6015 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05006016 return false
6017}
6018func rewriteValuegeneric_OpRsh64Ux8(v *Value, config *Config) bool {
6019 b := v.Block
6020 _ = b
6021 // match: (Rsh64Ux8 <t> x (Const8 [c]))
6022 // cond:
6023 // result: (Rsh64Ux64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01006024 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05006025 t := v.Type
6026 x := v.Args[0]
6027 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006028 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006029 }
6030 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006031 v.reset(OpRsh64Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006032 v.AddArg(x)
6033 v0 := b.NewValue0(v.Line, OpConst64, t)
6034 v0.AuxInt = int64(uint8(c))
6035 v.AddArg(v0)
6036 return true
6037 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01006038 // match: (Rsh64Ux8 (Const64 [0]) _)
6039 // cond:
6040 // result: (Const64 [0])
6041 for {
6042 if v.Args[0].Op != OpConst64 {
6043 break
6044 }
6045 if v.Args[0].AuxInt != 0 {
6046 break
6047 }
6048 v.reset(OpConst64)
6049 v.AuxInt = 0
6050 return true
6051 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05006052 return false
6053}
6054func rewriteValuegeneric_OpRsh64x16(v *Value, config *Config) bool {
6055 b := v.Block
6056 _ = b
6057 // match: (Rsh64x16 <t> x (Const16 [c]))
6058 // cond:
6059 // result: (Rsh64x64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01006060 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05006061 t := v.Type
6062 x := v.Args[0]
6063 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006064 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006065 }
6066 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006067 v.reset(OpRsh64x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006068 v.AddArg(x)
6069 v0 := b.NewValue0(v.Line, OpConst64, t)
6070 v0.AuxInt = int64(uint16(c))
6071 v.AddArg(v0)
6072 return true
6073 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01006074 // match: (Rsh64x16 (Const64 [0]) _)
6075 // cond:
6076 // result: (Const64 [0])
6077 for {
6078 if v.Args[0].Op != OpConst64 {
6079 break
6080 }
6081 if v.Args[0].AuxInt != 0 {
6082 break
6083 }
6084 v.reset(OpConst64)
6085 v.AuxInt = 0
6086 return true
6087 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05006088 return false
6089}
6090func rewriteValuegeneric_OpRsh64x32(v *Value, config *Config) bool {
6091 b := v.Block
6092 _ = b
6093 // match: (Rsh64x32 <t> x (Const32 [c]))
6094 // cond:
6095 // result: (Rsh64x64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01006096 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05006097 t := v.Type
6098 x := v.Args[0]
6099 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006100 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006101 }
6102 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006103 v.reset(OpRsh64x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006104 v.AddArg(x)
6105 v0 := b.NewValue0(v.Line, OpConst64, t)
6106 v0.AuxInt = int64(uint32(c))
6107 v.AddArg(v0)
6108 return true
6109 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01006110 // match: (Rsh64x32 (Const64 [0]) _)
6111 // cond:
6112 // result: (Const64 [0])
6113 for {
6114 if v.Args[0].Op != OpConst64 {
6115 break
6116 }
6117 if v.Args[0].AuxInt != 0 {
6118 break
6119 }
6120 v.reset(OpConst64)
6121 v.AuxInt = 0
6122 return true
6123 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05006124 return false
6125}
6126func rewriteValuegeneric_OpRsh64x64(v *Value, config *Config) bool {
6127 b := v.Block
6128 _ = b
6129 // match: (Rsh64x64 (Const64 [c]) (Const64 [d]))
6130 // cond:
6131 // result: (Const64 [c >> uint64(d)])
Alexandru Moșoi05434472016-02-04 19:52:10 +01006132 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05006133 if v.Args[0].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006134 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006135 }
6136 c := v.Args[0].AuxInt
6137 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006138 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006139 }
6140 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006141 v.reset(OpConst64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006142 v.AuxInt = c >> uint64(d)
6143 return true
6144 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01006145 // match: (Rsh64x64 (Const64 [0]) _)
6146 // cond:
6147 // result: (Const64 [0])
6148 for {
6149 if v.Args[0].Op != OpConst64 {
6150 break
6151 }
6152 if v.Args[0].AuxInt != 0 {
6153 break
6154 }
6155 v.reset(OpConst64)
6156 v.AuxInt = 0
6157 return true
6158 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05006159 // match: (Rsh64x64 x (Const64 [0]))
6160 // cond:
6161 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01006162 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05006163 x := v.Args[0]
6164 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006165 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006166 }
6167 if v.Args[1].AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006168 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006169 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006170 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006171 v.Type = x.Type
6172 v.AddArg(x)
6173 return true
6174 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01006175 // match: (Rsh64x64 (Const64 [0]) _)
6176 // cond:
6177 // result: (Const64 [0])
6178 for {
6179 if v.Args[0].Op != OpConst64 {
6180 break
6181 }
6182 if v.Args[0].AuxInt != 0 {
6183 break
6184 }
6185 v.reset(OpConst64)
6186 v.AuxInt = 0
6187 return true
6188 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05006189 // match: (Rsh64x64 <t> (Rsh64x64 x (Const64 [c])) (Const64 [d]))
6190 // cond: !uaddOvf(c,d)
6191 // result: (Rsh64x64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01006192 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05006193 t := v.Type
6194 if v.Args[0].Op != OpRsh64x64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006195 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006196 }
6197 x := v.Args[0].Args[0]
6198 if v.Args[0].Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006199 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006200 }
6201 c := v.Args[0].Args[1].AuxInt
6202 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006203 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006204 }
6205 d := v.Args[1].AuxInt
6206 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006207 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006208 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006209 v.reset(OpRsh64x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006210 v.AddArg(x)
6211 v0 := b.NewValue0(v.Line, OpConst64, t)
6212 v0.AuxInt = c + d
6213 v.AddArg(v0)
6214 return true
6215 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05006216 return false
6217}
6218func rewriteValuegeneric_OpRsh64x8(v *Value, config *Config) bool {
6219 b := v.Block
6220 _ = b
6221 // match: (Rsh64x8 <t> x (Const8 [c]))
6222 // cond:
6223 // result: (Rsh64x64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01006224 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05006225 t := v.Type
6226 x := v.Args[0]
6227 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006228 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006229 }
6230 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006231 v.reset(OpRsh64x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006232 v.AddArg(x)
6233 v0 := b.NewValue0(v.Line, OpConst64, t)
6234 v0.AuxInt = int64(uint8(c))
6235 v.AddArg(v0)
6236 return true
6237 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01006238 // match: (Rsh64x8 (Const64 [0]) _)
6239 // cond:
6240 // result: (Const64 [0])
6241 for {
6242 if v.Args[0].Op != OpConst64 {
6243 break
6244 }
6245 if v.Args[0].AuxInt != 0 {
6246 break
6247 }
6248 v.reset(OpConst64)
6249 v.AuxInt = 0
6250 return true
6251 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05006252 return false
6253}
6254func rewriteValuegeneric_OpRsh8Ux16(v *Value, config *Config) bool {
6255 b := v.Block
6256 _ = b
6257 // match: (Rsh8Ux16 <t> x (Const16 [c]))
6258 // cond:
6259 // result: (Rsh8Ux64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01006260 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05006261 t := v.Type
6262 x := v.Args[0]
6263 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006264 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006265 }
6266 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006267 v.reset(OpRsh8Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006268 v.AddArg(x)
6269 v0 := b.NewValue0(v.Line, OpConst64, t)
6270 v0.AuxInt = int64(uint16(c))
6271 v.AddArg(v0)
6272 return true
6273 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05006274 return false
6275}
6276func rewriteValuegeneric_OpRsh8Ux32(v *Value, config *Config) bool {
6277 b := v.Block
6278 _ = b
6279 // match: (Rsh8Ux32 <t> x (Const32 [c]))
6280 // cond:
6281 // result: (Rsh8Ux64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01006282 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05006283 t := v.Type
6284 x := v.Args[0]
6285 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006286 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006287 }
6288 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006289 v.reset(OpRsh8Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006290 v.AddArg(x)
6291 v0 := b.NewValue0(v.Line, OpConst64, t)
6292 v0.AuxInt = int64(uint32(c))
6293 v.AddArg(v0)
6294 return true
6295 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05006296 return false
6297}
6298func rewriteValuegeneric_OpRsh8Ux64(v *Value, config *Config) bool {
6299 b := v.Block
6300 _ = b
6301 // match: (Rsh8Ux64 (Const8 [c]) (Const64 [d]))
6302 // cond:
6303 // result: (Const8 [int64(uint8(c) >> uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01006304 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05006305 if v.Args[0].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006306 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006307 }
6308 c := v.Args[0].AuxInt
6309 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006310 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006311 }
6312 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006313 v.reset(OpConst8)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006314 v.AuxInt = int64(uint8(c) >> uint64(d))
6315 return true
6316 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01006317 // match: (Rsh8Ux64 (Const8 [0]) _)
6318 // cond:
6319 // result: (Const8 [0])
6320 for {
6321 if v.Args[0].Op != OpConst8 {
6322 break
6323 }
6324 if v.Args[0].AuxInt != 0 {
6325 break
6326 }
6327 v.reset(OpConst8)
6328 v.AuxInt = 0
6329 return true
6330 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05006331 // match: (Rsh8Ux64 x (Const64 [0]))
6332 // cond:
6333 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01006334 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05006335 x := v.Args[0]
6336 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006337 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006338 }
6339 if v.Args[1].AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006340 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006341 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006342 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006343 v.Type = x.Type
6344 v.AddArg(x)
6345 return true
6346 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05006347 // match: (Rsh8Ux64 _ (Const64 [c]))
6348 // cond: uint64(c) >= 8
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01006349 // result: (Const8 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01006350 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05006351 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006352 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006353 }
6354 c := v.Args[1].AuxInt
6355 if !(uint64(c) >= 8) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006356 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006357 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01006358 v.reset(OpConst8)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006359 v.AuxInt = 0
6360 return true
6361 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05006362 // match: (Rsh8Ux64 <t> (Rsh8Ux64 x (Const64 [c])) (Const64 [d]))
6363 // cond: !uaddOvf(c,d)
6364 // result: (Rsh8Ux64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01006365 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05006366 t := v.Type
6367 if v.Args[0].Op != OpRsh8Ux64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006368 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006369 }
6370 x := v.Args[0].Args[0]
6371 if v.Args[0].Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006372 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006373 }
6374 c := v.Args[0].Args[1].AuxInt
6375 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006376 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006377 }
6378 d := v.Args[1].AuxInt
6379 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006380 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006381 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006382 v.reset(OpRsh8Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006383 v.AddArg(x)
6384 v0 := b.NewValue0(v.Line, OpConst64, t)
6385 v0.AuxInt = c + d
6386 v.AddArg(v0)
6387 return true
6388 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05006389 return false
6390}
6391func rewriteValuegeneric_OpRsh8Ux8(v *Value, config *Config) bool {
6392 b := v.Block
6393 _ = b
6394 // match: (Rsh8Ux8 <t> x (Const8 [c]))
6395 // cond:
6396 // result: (Rsh8Ux64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01006397 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05006398 t := v.Type
6399 x := v.Args[0]
6400 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006401 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006402 }
6403 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006404 v.reset(OpRsh8Ux64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006405 v.AddArg(x)
6406 v0 := b.NewValue0(v.Line, OpConst64, t)
6407 v0.AuxInt = int64(uint8(c))
6408 v.AddArg(v0)
6409 return true
6410 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05006411 return false
6412}
6413func rewriteValuegeneric_OpRsh8x16(v *Value, config *Config) bool {
6414 b := v.Block
6415 _ = b
6416 // match: (Rsh8x16 <t> x (Const16 [c]))
6417 // cond:
6418 // result: (Rsh8x64 x (Const64 <t> [int64(uint16(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01006419 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05006420 t := v.Type
6421 x := v.Args[0]
6422 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006423 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006424 }
6425 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006426 v.reset(OpRsh8x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006427 v.AddArg(x)
6428 v0 := b.NewValue0(v.Line, OpConst64, t)
6429 v0.AuxInt = int64(uint16(c))
6430 v.AddArg(v0)
6431 return true
6432 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05006433 return false
6434}
6435func rewriteValuegeneric_OpRsh8x32(v *Value, config *Config) bool {
6436 b := v.Block
6437 _ = b
6438 // match: (Rsh8x32 <t> x (Const32 [c]))
6439 // cond:
6440 // result: (Rsh8x64 x (Const64 <t> [int64(uint32(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01006441 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05006442 t := v.Type
6443 x := v.Args[0]
6444 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006445 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006446 }
6447 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006448 v.reset(OpRsh8x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006449 v.AddArg(x)
6450 v0 := b.NewValue0(v.Line, OpConst64, t)
6451 v0.AuxInt = int64(uint32(c))
6452 v.AddArg(v0)
6453 return true
6454 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05006455 return false
6456}
6457func rewriteValuegeneric_OpRsh8x64(v *Value, config *Config) bool {
6458 b := v.Block
6459 _ = b
6460 // match: (Rsh8x64 (Const8 [c]) (Const64 [d]))
6461 // cond:
6462 // result: (Const8 [int64(int8(c) >> uint64(d))])
Alexandru Moșoi05434472016-02-04 19:52:10 +01006463 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05006464 if v.Args[0].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006465 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006466 }
6467 c := v.Args[0].AuxInt
6468 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006469 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006470 }
6471 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006472 v.reset(OpConst8)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006473 v.AuxInt = int64(int8(c) >> uint64(d))
6474 return true
6475 }
Alexandru Moșoibc1fb322016-02-17 14:08:36 +01006476 // match: (Rsh8x64 (Const8 [0]) _)
6477 // cond:
6478 // result: (Const8 [0])
6479 for {
6480 if v.Args[0].Op != OpConst8 {
6481 break
6482 }
6483 if v.Args[0].AuxInt != 0 {
6484 break
6485 }
6486 v.reset(OpConst8)
6487 v.AuxInt = 0
6488 return true
6489 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05006490 // match: (Rsh8x64 x (Const64 [0]))
6491 // cond:
6492 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01006493 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05006494 x := v.Args[0]
6495 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006496 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006497 }
6498 if v.Args[1].AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006499 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006500 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006501 v.reset(OpCopy)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006502 v.Type = x.Type
6503 v.AddArg(x)
6504 return true
6505 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05006506 // match: (Rsh8x64 <t> (Rsh8x64 x (Const64 [c])) (Const64 [d]))
6507 // cond: !uaddOvf(c,d)
6508 // result: (Rsh8x64 x (Const64 <t> [c+d]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01006509 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05006510 t := v.Type
6511 if v.Args[0].Op != OpRsh8x64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006512 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006513 }
6514 x := v.Args[0].Args[0]
6515 if v.Args[0].Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006516 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006517 }
6518 c := v.Args[0].Args[1].AuxInt
6519 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006520 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006521 }
6522 d := v.Args[1].AuxInt
6523 if !(!uaddOvf(c, d)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006524 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006525 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006526 v.reset(OpRsh8x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006527 v.AddArg(x)
6528 v0 := b.NewValue0(v.Line, OpConst64, t)
6529 v0.AuxInt = c + d
6530 v.AddArg(v0)
6531 return true
6532 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05006533 return false
6534}
6535func rewriteValuegeneric_OpRsh8x8(v *Value, config *Config) bool {
6536 b := v.Block
6537 _ = b
6538 // match: (Rsh8x8 <t> x (Const8 [c]))
6539 // cond:
6540 // result: (Rsh8x64 x (Const64 <t> [int64(uint8(c))]))
Alexandru Moșoi05434472016-02-04 19:52:10 +01006541 for {
Todd Neal93a0b0f2016-02-03 06:21:24 -05006542 t := v.Type
6543 x := v.Args[0]
6544 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006545 break
Todd Neal93a0b0f2016-02-03 06:21:24 -05006546 }
6547 c := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006548 v.reset(OpRsh8x64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05006549 v.AddArg(x)
6550 v0 := b.NewValue0(v.Line, OpConst64, t)
6551 v0.AuxInt = int64(uint8(c))
6552 v.AddArg(v0)
6553 return true
6554 }
Todd Neal93a0b0f2016-02-03 06:21:24 -05006555 return false
6556}
Keith Randalla347ab72015-10-26 21:49:31 -07006557func rewriteValuegeneric_OpSliceCap(v *Value, config *Config) bool {
6558 b := v.Block
6559 _ = b
6560 // match: (SliceCap (SliceMake _ _ cap))
6561 // cond:
6562 // result: cap
Alexandru Moșoi05434472016-02-04 19:52:10 +01006563 for {
Keith Randalla347ab72015-10-26 21:49:31 -07006564 if v.Args[0].Op != OpSliceMake {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006565 break
Keith Randalla347ab72015-10-26 21:49:31 -07006566 }
6567 cap := v.Args[0].Args[2]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006568 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07006569 v.Type = cap.Type
6570 v.AddArg(cap)
6571 return true
6572 }
Keith Randalla347ab72015-10-26 21:49:31 -07006573 return false
6574}
6575func rewriteValuegeneric_OpSliceLen(v *Value, config *Config) bool {
6576 b := v.Block
6577 _ = b
6578 // match: (SliceLen (SliceMake _ len _))
6579 // cond:
6580 // result: len
Alexandru Moșoi05434472016-02-04 19:52:10 +01006581 for {
Keith Randalla347ab72015-10-26 21:49:31 -07006582 if v.Args[0].Op != OpSliceMake {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006583 break
Keith Randalla347ab72015-10-26 21:49:31 -07006584 }
6585 len := v.Args[0].Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006586 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07006587 v.Type = len.Type
6588 v.AddArg(len)
6589 return true
6590 }
Keith Randalla347ab72015-10-26 21:49:31 -07006591 return false
6592}
6593func rewriteValuegeneric_OpSlicePtr(v *Value, config *Config) bool {
6594 b := v.Block
6595 _ = b
6596 // match: (SlicePtr (SliceMake ptr _ _ ))
6597 // cond:
6598 // result: ptr
Alexandru Moșoi05434472016-02-04 19:52:10 +01006599 for {
Keith Randalla347ab72015-10-26 21:49:31 -07006600 if v.Args[0].Op != OpSliceMake {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006601 break
Keith Randalla347ab72015-10-26 21:49:31 -07006602 }
6603 ptr := v.Args[0].Args[0]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006604 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07006605 v.Type = ptr.Type
6606 v.AddArg(ptr)
6607 return true
6608 }
Keith Randalla347ab72015-10-26 21:49:31 -07006609 return false
6610}
6611func rewriteValuegeneric_OpStore(v *Value, config *Config) bool {
6612 b := v.Block
6613 _ = b
Keith Randalla734bbc2016-01-11 21:05:33 -08006614 // match: (Store _ (StructMake0) mem)
6615 // cond:
6616 // result: mem
Alexandru Moșoi05434472016-02-04 19:52:10 +01006617 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08006618 if v.Args[1].Op != OpStructMake0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006619 break
Keith Randalla734bbc2016-01-11 21:05:33 -08006620 }
6621 mem := v.Args[2]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006622 v.reset(OpCopy)
Keith Randalla734bbc2016-01-11 21:05:33 -08006623 v.Type = mem.Type
6624 v.AddArg(mem)
6625 return true
6626 }
Keith Randalla734bbc2016-01-11 21:05:33 -08006627 // match: (Store dst (StructMake1 <t> f0) mem)
6628 // cond:
6629 // result: (Store [t.FieldType(0).Size()] dst f0 mem)
Alexandru Moșoi05434472016-02-04 19:52:10 +01006630 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08006631 dst := v.Args[0]
6632 if v.Args[1].Op != OpStructMake1 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006633 break
Keith Randalla734bbc2016-01-11 21:05:33 -08006634 }
6635 t := v.Args[1].Type
6636 f0 := v.Args[1].Args[0]
6637 mem := v.Args[2]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006638 v.reset(OpStore)
Keith Randalla734bbc2016-01-11 21:05:33 -08006639 v.AuxInt = t.FieldType(0).Size()
6640 v.AddArg(dst)
6641 v.AddArg(f0)
6642 v.AddArg(mem)
6643 return true
6644 }
Keith Randalla734bbc2016-01-11 21:05:33 -08006645 // match: (Store dst (StructMake2 <t> f0 f1) mem)
6646 // cond:
6647 // 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 +01006648 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08006649 dst := v.Args[0]
6650 if v.Args[1].Op != OpStructMake2 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006651 break
Keith Randalla734bbc2016-01-11 21:05:33 -08006652 }
6653 t := v.Args[1].Type
6654 f0 := v.Args[1].Args[0]
6655 f1 := v.Args[1].Args[1]
6656 mem := v.Args[2]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006657 v.reset(OpStore)
Keith Randalla734bbc2016-01-11 21:05:33 -08006658 v.AuxInt = t.FieldType(1).Size()
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006659 v0 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(1).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08006660 v0.AuxInt = t.FieldOff(1)
6661 v0.AddArg(dst)
6662 v.AddArg(v0)
6663 v.AddArg(f1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006664 v1 := b.NewValue0(v.Line, OpStore, TypeMem)
Keith Randalla734bbc2016-01-11 21:05:33 -08006665 v1.AuxInt = t.FieldType(0).Size()
6666 v1.AddArg(dst)
6667 v1.AddArg(f0)
6668 v1.AddArg(mem)
Keith Randalla734bbc2016-01-11 21:05:33 -08006669 v.AddArg(v1)
6670 return true
6671 }
Keith Randalla734bbc2016-01-11 21:05:33 -08006672 // match: (Store dst (StructMake3 <t> f0 f1 f2) mem)
6673 // cond:
6674 // 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 +01006675 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08006676 dst := v.Args[0]
6677 if v.Args[1].Op != OpStructMake3 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006678 break
Keith Randalla734bbc2016-01-11 21:05:33 -08006679 }
6680 t := v.Args[1].Type
6681 f0 := v.Args[1].Args[0]
6682 f1 := v.Args[1].Args[1]
6683 f2 := v.Args[1].Args[2]
6684 mem := v.Args[2]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006685 v.reset(OpStore)
Keith Randalla734bbc2016-01-11 21:05:33 -08006686 v.AuxInt = t.FieldType(2).Size()
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006687 v0 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(2).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08006688 v0.AuxInt = t.FieldOff(2)
6689 v0.AddArg(dst)
6690 v.AddArg(v0)
6691 v.AddArg(f2)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006692 v1 := b.NewValue0(v.Line, OpStore, TypeMem)
Keith Randalla734bbc2016-01-11 21:05:33 -08006693 v1.AuxInt = t.FieldType(1).Size()
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006694 v2 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(1).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08006695 v2.AuxInt = t.FieldOff(1)
6696 v2.AddArg(dst)
6697 v1.AddArg(v2)
6698 v1.AddArg(f1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006699 v3 := b.NewValue0(v.Line, OpStore, TypeMem)
Keith Randalla734bbc2016-01-11 21:05:33 -08006700 v3.AuxInt = t.FieldType(0).Size()
6701 v3.AddArg(dst)
6702 v3.AddArg(f0)
6703 v3.AddArg(mem)
Keith Randalla734bbc2016-01-11 21:05:33 -08006704 v1.AddArg(v3)
Keith Randalla734bbc2016-01-11 21:05:33 -08006705 v.AddArg(v1)
6706 return true
6707 }
Keith Randalla734bbc2016-01-11 21:05:33 -08006708 // match: (Store dst (StructMake4 <t> f0 f1 f2 f3) mem)
6709 // cond:
6710 // 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 +01006711 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08006712 dst := v.Args[0]
6713 if v.Args[1].Op != OpStructMake4 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006714 break
Keith Randalla734bbc2016-01-11 21:05:33 -08006715 }
6716 t := v.Args[1].Type
6717 f0 := v.Args[1].Args[0]
6718 f1 := v.Args[1].Args[1]
6719 f2 := v.Args[1].Args[2]
6720 f3 := v.Args[1].Args[3]
6721 mem := v.Args[2]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006722 v.reset(OpStore)
Keith Randalla734bbc2016-01-11 21:05:33 -08006723 v.AuxInt = t.FieldType(3).Size()
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006724 v0 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(3).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08006725 v0.AuxInt = t.FieldOff(3)
6726 v0.AddArg(dst)
6727 v.AddArg(v0)
6728 v.AddArg(f3)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006729 v1 := b.NewValue0(v.Line, OpStore, TypeMem)
Keith Randalla734bbc2016-01-11 21:05:33 -08006730 v1.AuxInt = t.FieldType(2).Size()
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006731 v2 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(2).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08006732 v2.AuxInt = t.FieldOff(2)
6733 v2.AddArg(dst)
6734 v1.AddArg(v2)
6735 v1.AddArg(f2)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006736 v3 := b.NewValue0(v.Line, OpStore, TypeMem)
Keith Randalla734bbc2016-01-11 21:05:33 -08006737 v3.AuxInt = t.FieldType(1).Size()
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006738 v4 := b.NewValue0(v.Line, OpOffPtr, t.FieldType(1).PtrTo())
Keith Randalla734bbc2016-01-11 21:05:33 -08006739 v4.AuxInt = t.FieldOff(1)
6740 v4.AddArg(dst)
6741 v3.AddArg(v4)
6742 v3.AddArg(f1)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006743 v5 := b.NewValue0(v.Line, OpStore, TypeMem)
Keith Randalla734bbc2016-01-11 21:05:33 -08006744 v5.AuxInt = t.FieldType(0).Size()
6745 v5.AddArg(dst)
6746 v5.AddArg(f0)
6747 v5.AddArg(mem)
Keith Randalla734bbc2016-01-11 21:05:33 -08006748 v3.AddArg(v5)
Keith Randalla734bbc2016-01-11 21:05:33 -08006749 v1.AddArg(v3)
Keith Randalla734bbc2016-01-11 21:05:33 -08006750 v.AddArg(v1)
6751 return true
6752 }
Keith Randalla347ab72015-10-26 21:49:31 -07006753 // match: (Store [8] dst (ComplexMake real imag) mem)
6754 // cond:
6755 // result: (Store [4] (OffPtr <config.fe.TypeFloat32().PtrTo()> [4] dst) imag (Store [4] dst real mem))
Alexandru Moșoi05434472016-02-04 19:52:10 +01006756 for {
Keith Randalla347ab72015-10-26 21:49:31 -07006757 if v.AuxInt != 8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006758 break
Keith Randalla347ab72015-10-26 21:49:31 -07006759 }
6760 dst := v.Args[0]
6761 if v.Args[1].Op != OpComplexMake {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006762 break
Keith Randalla347ab72015-10-26 21:49:31 -07006763 }
6764 real := v.Args[1].Args[0]
6765 imag := v.Args[1].Args[1]
6766 mem := v.Args[2]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006767 v.reset(OpStore)
Keith Randalla347ab72015-10-26 21:49:31 -07006768 v.AuxInt = 4
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006769 v0 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeFloat32().PtrTo())
Keith Randalla347ab72015-10-26 21:49:31 -07006770 v0.AuxInt = 4
6771 v0.AddArg(dst)
6772 v.AddArg(v0)
6773 v.AddArg(imag)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006774 v1 := b.NewValue0(v.Line, OpStore, TypeMem)
Keith Randalla347ab72015-10-26 21:49:31 -07006775 v1.AuxInt = 4
6776 v1.AddArg(dst)
6777 v1.AddArg(real)
6778 v1.AddArg(mem)
Keith Randalla347ab72015-10-26 21:49:31 -07006779 v.AddArg(v1)
6780 return true
6781 }
Keith Randalla347ab72015-10-26 21:49:31 -07006782 // match: (Store [16] dst (ComplexMake real imag) mem)
6783 // cond:
6784 // result: (Store [8] (OffPtr <config.fe.TypeFloat64().PtrTo()> [8] dst) imag (Store [8] dst real mem))
Alexandru Moșoi05434472016-02-04 19:52:10 +01006785 for {
Keith Randalla347ab72015-10-26 21:49:31 -07006786 if v.AuxInt != 16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006787 break
Keith Randalla347ab72015-10-26 21:49:31 -07006788 }
6789 dst := v.Args[0]
6790 if v.Args[1].Op != OpComplexMake {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006791 break
Keith Randalla347ab72015-10-26 21:49:31 -07006792 }
6793 real := v.Args[1].Args[0]
6794 imag := v.Args[1].Args[1]
6795 mem := v.Args[2]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006796 v.reset(OpStore)
Keith Randalla347ab72015-10-26 21:49:31 -07006797 v.AuxInt = 8
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006798 v0 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeFloat64().PtrTo())
Keith Randalla347ab72015-10-26 21:49:31 -07006799 v0.AuxInt = 8
6800 v0.AddArg(dst)
6801 v.AddArg(v0)
6802 v.AddArg(imag)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006803 v1 := b.NewValue0(v.Line, OpStore, TypeMem)
Keith Randalla347ab72015-10-26 21:49:31 -07006804 v1.AuxInt = 8
6805 v1.AddArg(dst)
6806 v1.AddArg(real)
6807 v1.AddArg(mem)
Keith Randalla347ab72015-10-26 21:49:31 -07006808 v.AddArg(v1)
6809 return true
6810 }
Keith Randalla347ab72015-10-26 21:49:31 -07006811 // match: (Store [2*config.PtrSize] dst (StringMake ptr len) mem)
6812 // cond:
Keith Randall02f4d0a2015-11-02 08:10:26 -08006813 // result: (Store [config.PtrSize] (OffPtr <config.fe.TypeInt().PtrTo()> [config.PtrSize] dst) len (Store [config.PtrSize] dst ptr mem))
Alexandru Moșoi05434472016-02-04 19:52:10 +01006814 for {
Keith Randalla347ab72015-10-26 21:49:31 -07006815 if v.AuxInt != 2*config.PtrSize {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006816 break
Keith Randalla347ab72015-10-26 21:49:31 -07006817 }
6818 dst := v.Args[0]
6819 if v.Args[1].Op != OpStringMake {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006820 break
Keith Randalla347ab72015-10-26 21:49:31 -07006821 }
6822 ptr := v.Args[1].Args[0]
6823 len := v.Args[1].Args[1]
6824 mem := v.Args[2]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006825 v.reset(OpStore)
Keith Randalla347ab72015-10-26 21:49:31 -07006826 v.AuxInt = config.PtrSize
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006827 v0 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeInt().PtrTo())
Keith Randalla347ab72015-10-26 21:49:31 -07006828 v0.AuxInt = config.PtrSize
6829 v0.AddArg(dst)
6830 v.AddArg(v0)
6831 v.AddArg(len)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006832 v1 := b.NewValue0(v.Line, OpStore, TypeMem)
Keith Randalla347ab72015-10-26 21:49:31 -07006833 v1.AuxInt = config.PtrSize
6834 v1.AddArg(dst)
6835 v1.AddArg(ptr)
6836 v1.AddArg(mem)
Keith Randalla347ab72015-10-26 21:49:31 -07006837 v.AddArg(v1)
6838 return true
6839 }
Keith Randalla347ab72015-10-26 21:49:31 -07006840 // match: (Store [3*config.PtrSize] dst (SliceMake ptr len cap) mem)
6841 // cond:
Keith Randall02f4d0a2015-11-02 08:10:26 -08006842 // result: (Store [config.PtrSize] (OffPtr <config.fe.TypeInt().PtrTo()> [2*config.PtrSize] dst) cap (Store [config.PtrSize] (OffPtr <config.fe.TypeInt().PtrTo()> [config.PtrSize] dst) len (Store [config.PtrSize] dst ptr mem)))
Alexandru Moșoi05434472016-02-04 19:52:10 +01006843 for {
Keith Randalla347ab72015-10-26 21:49:31 -07006844 if v.AuxInt != 3*config.PtrSize {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006845 break
Keith Randalla347ab72015-10-26 21:49:31 -07006846 }
6847 dst := v.Args[0]
6848 if v.Args[1].Op != OpSliceMake {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006849 break
Keith Randalla347ab72015-10-26 21:49:31 -07006850 }
6851 ptr := v.Args[1].Args[0]
6852 len := v.Args[1].Args[1]
6853 cap := v.Args[1].Args[2]
6854 mem := v.Args[2]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006855 v.reset(OpStore)
Keith Randalla347ab72015-10-26 21:49:31 -07006856 v.AuxInt = config.PtrSize
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006857 v0 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeInt().PtrTo())
Keith Randalla347ab72015-10-26 21:49:31 -07006858 v0.AuxInt = 2 * config.PtrSize
6859 v0.AddArg(dst)
6860 v.AddArg(v0)
6861 v.AddArg(cap)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006862 v1 := b.NewValue0(v.Line, OpStore, TypeMem)
Keith Randalla347ab72015-10-26 21:49:31 -07006863 v1.AuxInt = config.PtrSize
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006864 v2 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeInt().PtrTo())
Keith Randalla347ab72015-10-26 21:49:31 -07006865 v2.AuxInt = config.PtrSize
6866 v2.AddArg(dst)
6867 v1.AddArg(v2)
6868 v1.AddArg(len)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006869 v3 := b.NewValue0(v.Line, OpStore, TypeMem)
Keith Randalla347ab72015-10-26 21:49:31 -07006870 v3.AuxInt = config.PtrSize
6871 v3.AddArg(dst)
6872 v3.AddArg(ptr)
6873 v3.AddArg(mem)
Keith Randalla347ab72015-10-26 21:49:31 -07006874 v1.AddArg(v3)
Keith Randalla347ab72015-10-26 21:49:31 -07006875 v.AddArg(v1)
6876 return true
6877 }
Keith Randalla347ab72015-10-26 21:49:31 -07006878 // match: (Store [2*config.PtrSize] dst (IMake itab data) mem)
6879 // cond:
6880 // result: (Store [config.PtrSize] (OffPtr <config.fe.TypeBytePtr().PtrTo()> [config.PtrSize] dst) data (Store [config.PtrSize] dst itab mem))
Alexandru Moșoi05434472016-02-04 19:52:10 +01006881 for {
Keith Randalla347ab72015-10-26 21:49:31 -07006882 if v.AuxInt != 2*config.PtrSize {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006883 break
Keith Randalla347ab72015-10-26 21:49:31 -07006884 }
6885 dst := v.Args[0]
6886 if v.Args[1].Op != OpIMake {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006887 break
Keith Randalla347ab72015-10-26 21:49:31 -07006888 }
6889 itab := v.Args[1].Args[0]
6890 data := v.Args[1].Args[1]
6891 mem := v.Args[2]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006892 v.reset(OpStore)
Keith Randalla347ab72015-10-26 21:49:31 -07006893 v.AuxInt = config.PtrSize
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006894 v0 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeBytePtr().PtrTo())
Keith Randalla347ab72015-10-26 21:49:31 -07006895 v0.AuxInt = config.PtrSize
6896 v0.AddArg(dst)
6897 v.AddArg(v0)
6898 v.AddArg(data)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006899 v1 := b.NewValue0(v.Line, OpStore, TypeMem)
Keith Randalla347ab72015-10-26 21:49:31 -07006900 v1.AuxInt = config.PtrSize
6901 v1.AddArg(dst)
6902 v1.AddArg(itab)
6903 v1.AddArg(mem)
Keith Randalla347ab72015-10-26 21:49:31 -07006904 v.AddArg(v1)
6905 return true
6906 }
Keith Randalla347ab72015-10-26 21:49:31 -07006907 // match: (Store [size] dst (Load <t> src mem) mem)
6908 // cond: !config.fe.CanSSA(t)
6909 // result: (Move [size] dst src mem)
Alexandru Moșoi05434472016-02-04 19:52:10 +01006910 for {
Keith Randalla347ab72015-10-26 21:49:31 -07006911 size := v.AuxInt
6912 dst := v.Args[0]
6913 if v.Args[1].Op != OpLoad {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006914 break
Keith Randalla347ab72015-10-26 21:49:31 -07006915 }
6916 t := v.Args[1].Type
6917 src := v.Args[1].Args[0]
6918 mem := v.Args[1].Args[1]
6919 if v.Args[2] != mem {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006920 break
Keith Randalla347ab72015-10-26 21:49:31 -07006921 }
6922 if !(!config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006923 break
Keith Randalla347ab72015-10-26 21:49:31 -07006924 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006925 v.reset(OpMove)
Keith Randalla347ab72015-10-26 21:49:31 -07006926 v.AuxInt = size
6927 v.AddArg(dst)
6928 v.AddArg(src)
6929 v.AddArg(mem)
6930 return true
6931 }
Keith Randalla347ab72015-10-26 21:49:31 -07006932 // match: (Store [size] dst (Load <t> src mem) (VarDef {x} mem))
6933 // cond: !config.fe.CanSSA(t)
6934 // result: (Move [size] dst src (VarDef {x} mem))
Alexandru Moșoi05434472016-02-04 19:52:10 +01006935 for {
Keith Randalla347ab72015-10-26 21:49:31 -07006936 size := v.AuxInt
6937 dst := v.Args[0]
6938 if v.Args[1].Op != OpLoad {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006939 break
Keith Randalla347ab72015-10-26 21:49:31 -07006940 }
6941 t := v.Args[1].Type
6942 src := v.Args[1].Args[0]
6943 mem := v.Args[1].Args[1]
6944 if v.Args[2].Op != OpVarDef {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006945 break
Keith Randalla347ab72015-10-26 21:49:31 -07006946 }
6947 x := v.Args[2].Aux
6948 if v.Args[2].Args[0] != mem {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006949 break
Keith Randalla347ab72015-10-26 21:49:31 -07006950 }
6951 if !(!config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006952 break
Keith Randalla347ab72015-10-26 21:49:31 -07006953 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006954 v.reset(OpMove)
Keith Randalla347ab72015-10-26 21:49:31 -07006955 v.AuxInt = size
6956 v.AddArg(dst)
6957 v.AddArg(src)
Alexandru Moșoi606a11f2016-02-03 20:50:12 +01006958 v0 := b.NewValue0(v.Line, OpVarDef, TypeMem)
Keith Randalla347ab72015-10-26 21:49:31 -07006959 v0.Aux = x
6960 v0.AddArg(mem)
Keith Randalla347ab72015-10-26 21:49:31 -07006961 v.AddArg(v0)
6962 return true
6963 }
Keith Randalla347ab72015-10-26 21:49:31 -07006964 return false
6965}
6966func rewriteValuegeneric_OpStringLen(v *Value, config *Config) bool {
6967 b := v.Block
6968 _ = b
6969 // match: (StringLen (StringMake _ len))
6970 // cond:
6971 // result: len
Alexandru Moșoi05434472016-02-04 19:52:10 +01006972 for {
Keith Randalla347ab72015-10-26 21:49:31 -07006973 if v.Args[0].Op != OpStringMake {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006974 break
Keith Randalla347ab72015-10-26 21:49:31 -07006975 }
6976 len := v.Args[0].Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006977 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07006978 v.Type = len.Type
6979 v.AddArg(len)
6980 return true
6981 }
Keith Randalla347ab72015-10-26 21:49:31 -07006982 return false
6983}
6984func rewriteValuegeneric_OpStringPtr(v *Value, config *Config) bool {
6985 b := v.Block
6986 _ = b
6987 // match: (StringPtr (StringMake ptr _))
6988 // cond:
6989 // result: ptr
Alexandru Moșoi05434472016-02-04 19:52:10 +01006990 for {
Keith Randalla347ab72015-10-26 21:49:31 -07006991 if v.Args[0].Op != OpStringMake {
Alexandru Moșoi05434472016-02-04 19:52:10 +01006992 break
Keith Randalla347ab72015-10-26 21:49:31 -07006993 }
6994 ptr := v.Args[0].Args[0]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01006995 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07006996 v.Type = ptr.Type
6997 v.AddArg(ptr)
6998 return true
6999 }
Keith Randalla347ab72015-10-26 21:49:31 -07007000 return false
7001}
7002func rewriteValuegeneric_OpStructSelect(v *Value, config *Config) bool {
7003 b := v.Block
7004 _ = b
Keith Randalla734bbc2016-01-11 21:05:33 -08007005 // match: (StructSelect (StructMake1 x))
Keith Randalla347ab72015-10-26 21:49:31 -07007006 // cond:
Keith Randalla734bbc2016-01-11 21:05:33 -08007007 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01007008 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08007009 if v.Args[0].Op != OpStructMake1 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007010 break
Keith Randalla347ab72015-10-26 21:49:31 -07007011 }
Keith Randalla734bbc2016-01-11 21:05:33 -08007012 x := v.Args[0].Args[0]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007013 v.reset(OpCopy)
Keith Randalla734bbc2016-01-11 21:05:33 -08007014 v.Type = x.Type
7015 v.AddArg(x)
7016 return true
7017 }
Keith Randalla734bbc2016-01-11 21:05:33 -08007018 // match: (StructSelect [0] (StructMake2 x _))
7019 // cond:
7020 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01007021 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08007022 if v.AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007023 break
Keith Randalla734bbc2016-01-11 21:05:33 -08007024 }
7025 if v.Args[0].Op != OpStructMake2 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007026 break
Keith Randalla734bbc2016-01-11 21:05:33 -08007027 }
7028 x := v.Args[0].Args[0]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007029 v.reset(OpCopy)
Keith Randalla734bbc2016-01-11 21:05:33 -08007030 v.Type = x.Type
7031 v.AddArg(x)
7032 return true
7033 }
Keith Randalla734bbc2016-01-11 21:05:33 -08007034 // match: (StructSelect [1] (StructMake2 _ x))
7035 // cond:
7036 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01007037 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08007038 if v.AuxInt != 1 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007039 break
Keith Randalla734bbc2016-01-11 21:05:33 -08007040 }
7041 if v.Args[0].Op != OpStructMake2 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007042 break
Keith Randalla734bbc2016-01-11 21:05:33 -08007043 }
7044 x := v.Args[0].Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007045 v.reset(OpCopy)
Keith Randalla734bbc2016-01-11 21:05:33 -08007046 v.Type = x.Type
7047 v.AddArg(x)
7048 return true
7049 }
Keith Randalla734bbc2016-01-11 21:05:33 -08007050 // match: (StructSelect [0] (StructMake3 x _ _))
7051 // cond:
7052 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01007053 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08007054 if v.AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007055 break
Keith Randalla734bbc2016-01-11 21:05:33 -08007056 }
7057 if v.Args[0].Op != OpStructMake3 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007058 break
Keith Randalla734bbc2016-01-11 21:05:33 -08007059 }
7060 x := v.Args[0].Args[0]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007061 v.reset(OpCopy)
Keith Randalla734bbc2016-01-11 21:05:33 -08007062 v.Type = x.Type
7063 v.AddArg(x)
7064 return true
7065 }
Keith Randalla734bbc2016-01-11 21:05:33 -08007066 // match: (StructSelect [1] (StructMake3 _ x _))
7067 // cond:
7068 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01007069 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08007070 if v.AuxInt != 1 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007071 break
Keith Randalla734bbc2016-01-11 21:05:33 -08007072 }
7073 if v.Args[0].Op != OpStructMake3 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007074 break
Keith Randalla734bbc2016-01-11 21:05:33 -08007075 }
7076 x := v.Args[0].Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007077 v.reset(OpCopy)
Keith Randalla734bbc2016-01-11 21:05:33 -08007078 v.Type = x.Type
7079 v.AddArg(x)
7080 return true
7081 }
Keith Randalla734bbc2016-01-11 21:05:33 -08007082 // match: (StructSelect [2] (StructMake3 _ _ x))
7083 // cond:
7084 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01007085 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08007086 if v.AuxInt != 2 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007087 break
Keith Randalla734bbc2016-01-11 21:05:33 -08007088 }
7089 if v.Args[0].Op != OpStructMake3 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007090 break
Keith Randalla734bbc2016-01-11 21:05:33 -08007091 }
7092 x := v.Args[0].Args[2]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007093 v.reset(OpCopy)
Keith Randalla734bbc2016-01-11 21:05:33 -08007094 v.Type = x.Type
7095 v.AddArg(x)
7096 return true
7097 }
Keith Randalla734bbc2016-01-11 21:05:33 -08007098 // match: (StructSelect [0] (StructMake4 x _ _ _))
7099 // cond:
7100 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01007101 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08007102 if v.AuxInt != 0 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007103 break
Keith Randalla734bbc2016-01-11 21:05:33 -08007104 }
7105 if v.Args[0].Op != OpStructMake4 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007106 break
Keith Randalla734bbc2016-01-11 21:05:33 -08007107 }
7108 x := v.Args[0].Args[0]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007109 v.reset(OpCopy)
Keith Randalla734bbc2016-01-11 21:05:33 -08007110 v.Type = x.Type
7111 v.AddArg(x)
7112 return true
7113 }
Keith Randalla734bbc2016-01-11 21:05:33 -08007114 // match: (StructSelect [1] (StructMake4 _ x _ _))
7115 // cond:
7116 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01007117 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08007118 if v.AuxInt != 1 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007119 break
Keith Randalla734bbc2016-01-11 21:05:33 -08007120 }
7121 if v.Args[0].Op != OpStructMake4 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007122 break
Keith Randalla734bbc2016-01-11 21:05:33 -08007123 }
7124 x := v.Args[0].Args[1]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007125 v.reset(OpCopy)
Keith Randalla734bbc2016-01-11 21:05:33 -08007126 v.Type = x.Type
7127 v.AddArg(x)
7128 return true
7129 }
Keith Randalla734bbc2016-01-11 21:05:33 -08007130 // match: (StructSelect [2] (StructMake4 _ _ x _))
7131 // cond:
7132 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01007133 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08007134 if v.AuxInt != 2 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007135 break
Keith Randalla734bbc2016-01-11 21:05:33 -08007136 }
7137 if v.Args[0].Op != OpStructMake4 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007138 break
Keith Randalla734bbc2016-01-11 21:05:33 -08007139 }
7140 x := v.Args[0].Args[2]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007141 v.reset(OpCopy)
Keith Randalla734bbc2016-01-11 21:05:33 -08007142 v.Type = x.Type
7143 v.AddArg(x)
7144 return true
7145 }
Keith Randalla734bbc2016-01-11 21:05:33 -08007146 // match: (StructSelect [3] (StructMake4 _ _ _ x))
7147 // cond:
7148 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01007149 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08007150 if v.AuxInt != 3 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007151 break
Keith Randalla734bbc2016-01-11 21:05:33 -08007152 }
7153 if v.Args[0].Op != OpStructMake4 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007154 break
Keith Randalla734bbc2016-01-11 21:05:33 -08007155 }
7156 x := v.Args[0].Args[3]
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007157 v.reset(OpCopy)
Keith Randalla734bbc2016-01-11 21:05:33 -08007158 v.Type = x.Type
7159 v.AddArg(x)
7160 return true
7161 }
Keith Randalla734bbc2016-01-11 21:05:33 -08007162 // match: (StructSelect [i] (Load <t> ptr mem))
7163 // cond: !config.fe.CanSSA(t)
7164 // result: @v.Args[0].Block (Load <v.Type> (OffPtr <v.Type.PtrTo()> [t.FieldOff(i)] ptr) mem)
Alexandru Moșoi05434472016-02-04 19:52:10 +01007165 for {
Keith Randalla734bbc2016-01-11 21:05:33 -08007166 i := v.AuxInt
7167 if v.Args[0].Op != OpLoad {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007168 break
Keith Randalla734bbc2016-01-11 21:05:33 -08007169 }
7170 t := v.Args[0].Type
Keith Randalla347ab72015-10-26 21:49:31 -07007171 ptr := v.Args[0].Args[0]
7172 mem := v.Args[0].Args[1]
Keith Randalla734bbc2016-01-11 21:05:33 -08007173 if !(!config.fe.CanSSA(t)) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007174 break
Keith Randalla734bbc2016-01-11 21:05:33 -08007175 }
Keith Randalled737fd2016-02-24 10:29:27 -08007176 b = v.Args[0].Block
7177 v0 := b.NewValue0(v.Line, OpLoad, v.Type)
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007178 v.reset(OpCopy)
Keith Randalla347ab72015-10-26 21:49:31 -07007179 v.AddArg(v0)
Keith Randalled737fd2016-02-24 10:29:27 -08007180 v1 := b.NewValue0(v.Line, OpOffPtr, v.Type.PtrTo())
7181 v.reset(OpCopy)
7182 v.AddArg(v1)
Keith Randalla734bbc2016-01-11 21:05:33 -08007183 v1.AuxInt = t.FieldOff(i)
Keith Randalla347ab72015-10-26 21:49:31 -07007184 v1.AddArg(ptr)
7185 v0.AddArg(v1)
7186 v0.AddArg(mem)
7187 return true
7188 }
Keith Randalla347ab72015-10-26 21:49:31 -07007189 return false
7190}
7191func rewriteValuegeneric_OpSub16(v *Value, config *Config) bool {
7192 b := v.Block
7193 _ = b
Keith Randall582baae2015-11-02 21:28:13 -08007194 // match: (Sub16 (Const16 [c]) (Const16 [d]))
7195 // cond:
7196 // result: (Const16 [c-d])
Alexandru Moșoi05434472016-02-04 19:52:10 +01007197 for {
Keith Randall582baae2015-11-02 21:28:13 -08007198 if v.Args[0].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007199 break
Keith Randall582baae2015-11-02 21:28:13 -08007200 }
7201 c := v.Args[0].AuxInt
7202 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007203 break
Keith Randall582baae2015-11-02 21:28:13 -08007204 }
7205 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007206 v.reset(OpConst16)
Keith Randall582baae2015-11-02 21:28:13 -08007207 v.AuxInt = c - d
7208 return true
7209 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01007210 // match: (Sub16 x (Const16 <t> [c]))
7211 // cond: x.Op != OpConst16
7212 // result: (Add16 (Const16 <t> [-c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01007213 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01007214 x := v.Args[0]
7215 if v.Args[1].Op != OpConst16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007216 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01007217 }
7218 t := v.Args[1].Type
7219 c := v.Args[1].AuxInt
7220 if !(x.Op != OpConst16) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007221 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01007222 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007223 v.reset(OpAdd16)
Todd Neal93a0b0f2016-02-03 06:21:24 -05007224 v0 := b.NewValue0(v.Line, OpConst16, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01007225 v0.AuxInt = -c
7226 v.AddArg(v0)
7227 v.AddArg(x)
7228 return true
7229 }
Keith Randalla347ab72015-10-26 21:49:31 -07007230 // match: (Sub16 x x)
7231 // cond:
7232 // result: (Const16 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01007233 for {
Keith Randalla347ab72015-10-26 21:49:31 -07007234 x := v.Args[0]
7235 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007236 break
Keith Randalla347ab72015-10-26 21:49:31 -07007237 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007238 v.reset(OpConst16)
Keith Randalla347ab72015-10-26 21:49:31 -07007239 v.AuxInt = 0
7240 return true
7241 }
Keith Randall170589e2015-11-09 20:54:34 -08007242 // match: (Sub16 (Add16 x y) x)
7243 // cond:
7244 // result: y
Alexandru Moșoi05434472016-02-04 19:52:10 +01007245 for {
Keith Randall170589e2015-11-09 20:54:34 -08007246 if v.Args[0].Op != OpAdd16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007247 break
Keith Randall170589e2015-11-09 20:54:34 -08007248 }
7249 x := v.Args[0].Args[0]
7250 y := v.Args[0].Args[1]
7251 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007252 break
Keith Randall170589e2015-11-09 20:54:34 -08007253 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007254 v.reset(OpCopy)
Keith Randall170589e2015-11-09 20:54:34 -08007255 v.Type = y.Type
7256 v.AddArg(y)
7257 return true
7258 }
Keith Randall170589e2015-11-09 20:54:34 -08007259 // match: (Sub16 (Add16 x y) y)
7260 // cond:
7261 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01007262 for {
Keith Randall170589e2015-11-09 20:54:34 -08007263 if v.Args[0].Op != OpAdd16 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007264 break
Keith Randall170589e2015-11-09 20:54:34 -08007265 }
7266 x := v.Args[0].Args[0]
7267 y := v.Args[0].Args[1]
7268 if v.Args[1] != y {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007269 break
Keith Randall170589e2015-11-09 20:54:34 -08007270 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007271 v.reset(OpCopy)
Keith Randall170589e2015-11-09 20:54:34 -08007272 v.Type = x.Type
7273 v.AddArg(x)
7274 return true
7275 }
Keith Randalla347ab72015-10-26 21:49:31 -07007276 return false
7277}
7278func rewriteValuegeneric_OpSub32(v *Value, config *Config) bool {
7279 b := v.Block
7280 _ = b
Keith Randall582baae2015-11-02 21:28:13 -08007281 // match: (Sub32 (Const32 [c]) (Const32 [d]))
7282 // cond:
7283 // result: (Const32 [c-d])
Alexandru Moșoi05434472016-02-04 19:52:10 +01007284 for {
Keith Randall582baae2015-11-02 21:28:13 -08007285 if v.Args[0].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007286 break
Keith Randall582baae2015-11-02 21:28:13 -08007287 }
7288 c := v.Args[0].AuxInt
7289 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007290 break
Keith Randall582baae2015-11-02 21:28:13 -08007291 }
7292 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007293 v.reset(OpConst32)
Keith Randall582baae2015-11-02 21:28:13 -08007294 v.AuxInt = c - d
7295 return true
7296 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01007297 // match: (Sub32 x (Const32 <t> [c]))
7298 // cond: x.Op != OpConst32
7299 // result: (Add32 (Const32 <t> [-c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01007300 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01007301 x := v.Args[0]
7302 if v.Args[1].Op != OpConst32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007303 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01007304 }
7305 t := v.Args[1].Type
7306 c := v.Args[1].AuxInt
7307 if !(x.Op != OpConst32) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007308 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01007309 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007310 v.reset(OpAdd32)
Todd Neal93a0b0f2016-02-03 06:21:24 -05007311 v0 := b.NewValue0(v.Line, OpConst32, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01007312 v0.AuxInt = -c
7313 v.AddArg(v0)
7314 v.AddArg(x)
7315 return true
7316 }
Keith Randalla347ab72015-10-26 21:49:31 -07007317 // match: (Sub32 x x)
7318 // cond:
7319 // result: (Const32 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01007320 for {
Keith Randalla347ab72015-10-26 21:49:31 -07007321 x := v.Args[0]
7322 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007323 break
Keith Randalla347ab72015-10-26 21:49:31 -07007324 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007325 v.reset(OpConst32)
Keith Randalla347ab72015-10-26 21:49:31 -07007326 v.AuxInt = 0
7327 return true
7328 }
Keith Randall170589e2015-11-09 20:54:34 -08007329 // match: (Sub32 (Add32 x y) x)
7330 // cond:
7331 // result: y
Alexandru Moșoi05434472016-02-04 19:52:10 +01007332 for {
Keith Randall170589e2015-11-09 20:54:34 -08007333 if v.Args[0].Op != OpAdd32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007334 break
Keith Randall170589e2015-11-09 20:54:34 -08007335 }
7336 x := v.Args[0].Args[0]
7337 y := v.Args[0].Args[1]
7338 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007339 break
Keith Randall170589e2015-11-09 20:54:34 -08007340 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007341 v.reset(OpCopy)
Keith Randall170589e2015-11-09 20:54:34 -08007342 v.Type = y.Type
7343 v.AddArg(y)
7344 return true
7345 }
Keith Randall170589e2015-11-09 20:54:34 -08007346 // match: (Sub32 (Add32 x y) y)
7347 // cond:
7348 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01007349 for {
Keith Randall170589e2015-11-09 20:54:34 -08007350 if v.Args[0].Op != OpAdd32 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007351 break
Keith Randall170589e2015-11-09 20:54:34 -08007352 }
7353 x := v.Args[0].Args[0]
7354 y := v.Args[0].Args[1]
7355 if v.Args[1] != y {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007356 break
Keith Randall170589e2015-11-09 20:54:34 -08007357 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007358 v.reset(OpCopy)
Keith Randall170589e2015-11-09 20:54:34 -08007359 v.Type = x.Type
7360 v.AddArg(x)
7361 return true
7362 }
Keith Randalla347ab72015-10-26 21:49:31 -07007363 return false
7364}
7365func rewriteValuegeneric_OpSub64(v *Value, config *Config) bool {
7366 b := v.Block
7367 _ = b
Keith Randall582baae2015-11-02 21:28:13 -08007368 // match: (Sub64 (Const64 [c]) (Const64 [d]))
7369 // cond:
7370 // result: (Const64 [c-d])
Alexandru Moșoi05434472016-02-04 19:52:10 +01007371 for {
Keith Randall582baae2015-11-02 21:28:13 -08007372 if v.Args[0].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007373 break
Keith Randall582baae2015-11-02 21:28:13 -08007374 }
7375 c := v.Args[0].AuxInt
7376 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007377 break
Keith Randall582baae2015-11-02 21:28:13 -08007378 }
7379 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007380 v.reset(OpConst64)
Keith Randall582baae2015-11-02 21:28:13 -08007381 v.AuxInt = c - d
7382 return true
7383 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01007384 // match: (Sub64 x (Const64 <t> [c]))
7385 // cond: x.Op != OpConst64
7386 // result: (Add64 (Const64 <t> [-c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01007387 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01007388 x := v.Args[0]
7389 if v.Args[1].Op != OpConst64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007390 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01007391 }
7392 t := v.Args[1].Type
7393 c := v.Args[1].AuxInt
7394 if !(x.Op != OpConst64) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007395 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01007396 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007397 v.reset(OpAdd64)
Todd Neal93a0b0f2016-02-03 06:21:24 -05007398 v0 := b.NewValue0(v.Line, OpConst64, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01007399 v0.AuxInt = -c
7400 v.AddArg(v0)
7401 v.AddArg(x)
7402 return true
7403 }
Keith Randalla347ab72015-10-26 21:49:31 -07007404 // match: (Sub64 x x)
7405 // cond:
7406 // result: (Const64 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01007407 for {
Keith Randalla347ab72015-10-26 21:49:31 -07007408 x := v.Args[0]
7409 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007410 break
Keith Randalla347ab72015-10-26 21:49:31 -07007411 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007412 v.reset(OpConst64)
Keith Randalla347ab72015-10-26 21:49:31 -07007413 v.AuxInt = 0
7414 return true
7415 }
Keith Randall170589e2015-11-09 20:54:34 -08007416 // match: (Sub64 (Add64 x y) x)
7417 // cond:
7418 // result: y
Alexandru Moșoi05434472016-02-04 19:52:10 +01007419 for {
Keith Randall170589e2015-11-09 20:54:34 -08007420 if v.Args[0].Op != OpAdd64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007421 break
Keith Randall170589e2015-11-09 20:54:34 -08007422 }
7423 x := v.Args[0].Args[0]
7424 y := v.Args[0].Args[1]
7425 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007426 break
Keith Randall170589e2015-11-09 20:54:34 -08007427 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007428 v.reset(OpCopy)
Keith Randall170589e2015-11-09 20:54:34 -08007429 v.Type = y.Type
7430 v.AddArg(y)
7431 return true
7432 }
Keith Randall170589e2015-11-09 20:54:34 -08007433 // match: (Sub64 (Add64 x y) y)
7434 // cond:
7435 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01007436 for {
Keith Randall170589e2015-11-09 20:54:34 -08007437 if v.Args[0].Op != OpAdd64 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007438 break
Keith Randall170589e2015-11-09 20:54:34 -08007439 }
7440 x := v.Args[0].Args[0]
7441 y := v.Args[0].Args[1]
7442 if v.Args[1] != y {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007443 break
Keith Randall170589e2015-11-09 20:54:34 -08007444 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007445 v.reset(OpCopy)
Keith Randall170589e2015-11-09 20:54:34 -08007446 v.Type = x.Type
7447 v.AddArg(x)
7448 return true
7449 }
Keith Randalla347ab72015-10-26 21:49:31 -07007450 return false
7451}
7452func rewriteValuegeneric_OpSub8(v *Value, config *Config) bool {
7453 b := v.Block
7454 _ = b
Keith Randall582baae2015-11-02 21:28:13 -08007455 // match: (Sub8 (Const8 [c]) (Const8 [d]))
7456 // cond:
7457 // result: (Const8 [c-d])
Alexandru Moșoi05434472016-02-04 19:52:10 +01007458 for {
Keith Randall582baae2015-11-02 21:28:13 -08007459 if v.Args[0].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007460 break
Keith Randall582baae2015-11-02 21:28:13 -08007461 }
7462 c := v.Args[0].AuxInt
7463 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007464 break
Keith Randall582baae2015-11-02 21:28:13 -08007465 }
7466 d := v.Args[1].AuxInt
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007467 v.reset(OpConst8)
Keith Randall582baae2015-11-02 21:28:13 -08007468 v.AuxInt = c - d
7469 return true
7470 }
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01007471 // match: (Sub8 x (Const8 <t> [c]))
7472 // cond: x.Op != OpConst8
7473 // result: (Add8 (Const8 <t> [-c]) x)
Alexandru Moșoi05434472016-02-04 19:52:10 +01007474 for {
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01007475 x := v.Args[0]
7476 if v.Args[1].Op != OpConst8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007477 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01007478 }
7479 t := v.Args[1].Type
7480 c := v.Args[1].AuxInt
7481 if !(x.Op != OpConst8) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007482 break
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01007483 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007484 v.reset(OpAdd8)
Todd Neal93a0b0f2016-02-03 06:21:24 -05007485 v0 := b.NewValue0(v.Line, OpConst8, t)
Alexandru Moșoid4a95e72016-02-03 19:43:46 +01007486 v0.AuxInt = -c
7487 v.AddArg(v0)
7488 v.AddArg(x)
7489 return true
7490 }
Keith Randalla347ab72015-10-26 21:49:31 -07007491 // match: (Sub8 x x)
7492 // cond:
7493 // result: (Const8 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01007494 for {
Keith Randalla347ab72015-10-26 21:49:31 -07007495 x := v.Args[0]
7496 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007497 break
Keith Randalla347ab72015-10-26 21:49:31 -07007498 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007499 v.reset(OpConst8)
Keith Randalla347ab72015-10-26 21:49:31 -07007500 v.AuxInt = 0
7501 return true
7502 }
Keith Randall170589e2015-11-09 20:54:34 -08007503 // match: (Sub8 (Add8 x y) x)
7504 // cond:
7505 // result: y
Alexandru Moșoi05434472016-02-04 19:52:10 +01007506 for {
Keith Randall170589e2015-11-09 20:54:34 -08007507 if v.Args[0].Op != OpAdd8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007508 break
Keith Randall170589e2015-11-09 20:54:34 -08007509 }
7510 x := v.Args[0].Args[0]
7511 y := v.Args[0].Args[1]
7512 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007513 break
Keith Randall170589e2015-11-09 20:54:34 -08007514 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007515 v.reset(OpCopy)
Keith Randall170589e2015-11-09 20:54:34 -08007516 v.Type = y.Type
7517 v.AddArg(y)
7518 return true
7519 }
Keith Randall170589e2015-11-09 20:54:34 -08007520 // match: (Sub8 (Add8 x y) y)
7521 // cond:
7522 // result: x
Alexandru Moșoi05434472016-02-04 19:52:10 +01007523 for {
Keith Randall170589e2015-11-09 20:54:34 -08007524 if v.Args[0].Op != OpAdd8 {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007525 break
Keith Randall170589e2015-11-09 20:54:34 -08007526 }
7527 x := v.Args[0].Args[0]
7528 y := v.Args[0].Args[1]
7529 if v.Args[1] != y {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007530 break
Keith Randall170589e2015-11-09 20:54:34 -08007531 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007532 v.reset(OpCopy)
Keith Randall170589e2015-11-09 20:54:34 -08007533 v.Type = x.Type
7534 v.AddArg(x)
7535 return true
7536 }
Keith Randalla347ab72015-10-26 21:49:31 -07007537 return false
7538}
Alexandru Moșoie4bee4b2016-02-17 12:17:11 +01007539func rewriteValuegeneric_OpTrunc16to8(v *Value, config *Config) bool {
7540 b := v.Block
7541 _ = b
7542 // match: (Trunc16to8 (Const16 [c]))
7543 // cond:
7544 // result: (Const8 [int64(int8(c))])
7545 for {
7546 if v.Args[0].Op != OpConst16 {
7547 break
7548 }
7549 c := v.Args[0].AuxInt
7550 v.reset(OpConst8)
7551 v.AuxInt = int64(int8(c))
7552 return true
7553 }
7554 return false
7555}
7556func rewriteValuegeneric_OpTrunc32to16(v *Value, config *Config) bool {
7557 b := v.Block
7558 _ = b
7559 // match: (Trunc32to16 (Const32 [c]))
7560 // cond:
7561 // result: (Const16 [int64(int16(c))])
7562 for {
7563 if v.Args[0].Op != OpConst32 {
7564 break
7565 }
7566 c := v.Args[0].AuxInt
7567 v.reset(OpConst16)
7568 v.AuxInt = int64(int16(c))
7569 return true
7570 }
7571 return false
7572}
7573func rewriteValuegeneric_OpTrunc32to8(v *Value, config *Config) bool {
7574 b := v.Block
7575 _ = b
7576 // match: (Trunc32to8 (Const32 [c]))
7577 // cond:
7578 // result: (Const8 [int64(int8(c))])
7579 for {
7580 if v.Args[0].Op != OpConst32 {
7581 break
7582 }
7583 c := v.Args[0].AuxInt
7584 v.reset(OpConst8)
7585 v.AuxInt = int64(int8(c))
7586 return true
7587 }
7588 return false
7589}
7590func rewriteValuegeneric_OpTrunc64to16(v *Value, config *Config) bool {
7591 b := v.Block
7592 _ = b
7593 // match: (Trunc64to16 (Const64 [c]))
7594 // cond:
7595 // result: (Const16 [int64(int16(c))])
7596 for {
7597 if v.Args[0].Op != OpConst64 {
7598 break
7599 }
7600 c := v.Args[0].AuxInt
7601 v.reset(OpConst16)
7602 v.AuxInt = int64(int16(c))
7603 return true
7604 }
7605 return false
7606}
7607func rewriteValuegeneric_OpTrunc64to32(v *Value, config *Config) bool {
7608 b := v.Block
7609 _ = b
7610 // match: (Trunc64to32 (Const64 [c]))
7611 // cond:
7612 // result: (Const32 [int64(int32(c))])
7613 for {
7614 if v.Args[0].Op != OpConst64 {
7615 break
7616 }
7617 c := v.Args[0].AuxInt
7618 v.reset(OpConst32)
7619 v.AuxInt = int64(int32(c))
7620 return true
7621 }
7622 return false
7623}
7624func rewriteValuegeneric_OpTrunc64to8(v *Value, config *Config) bool {
7625 b := v.Block
7626 _ = b
7627 // match: (Trunc64to8 (Const64 [c]))
7628 // cond:
7629 // result: (Const8 [int64(int8(c))])
7630 for {
7631 if v.Args[0].Op != OpConst64 {
7632 break
7633 }
7634 c := v.Args[0].AuxInt
7635 v.reset(OpConst8)
7636 v.AuxInt = int64(int8(c))
7637 return true
7638 }
7639 return false
7640}
Keith Randalla347ab72015-10-26 21:49:31 -07007641func rewriteValuegeneric_OpXor16(v *Value, config *Config) bool {
7642 b := v.Block
7643 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007644 // match: (Xor16 x (Const16 <t> [c]))
7645 // cond: x.Op != OpConst16
7646 // result: (Xor16 (Const16 <t> [c]) x)
7647 for {
7648 x := v.Args[0]
7649 if v.Args[1].Op != OpConst16 {
7650 break
7651 }
7652 t := v.Args[1].Type
7653 c := v.Args[1].AuxInt
7654 if !(x.Op != OpConst16) {
7655 break
7656 }
7657 v.reset(OpXor16)
7658 v0 := b.NewValue0(v.Line, OpConst16, t)
7659 v0.AuxInt = c
7660 v.AddArg(v0)
7661 v.AddArg(x)
7662 return true
7663 }
Keith Randalla347ab72015-10-26 21:49:31 -07007664 // match: (Xor16 x x)
7665 // cond:
7666 // result: (Const16 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01007667 for {
Keith Randalla347ab72015-10-26 21:49:31 -07007668 x := v.Args[0]
7669 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007670 break
Keith Randalla347ab72015-10-26 21:49:31 -07007671 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007672 v.reset(OpConst16)
Keith Randalla347ab72015-10-26 21:49:31 -07007673 v.AuxInt = 0
7674 return true
7675 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007676 // match: (Xor16 (Const16 [0]) x)
7677 // cond:
7678 // result: x
7679 for {
7680 if v.Args[0].Op != OpConst16 {
7681 break
7682 }
7683 if v.Args[0].AuxInt != 0 {
7684 break
7685 }
7686 x := v.Args[1]
7687 v.reset(OpCopy)
7688 v.Type = x.Type
7689 v.AddArg(x)
7690 return true
7691 }
Keith Randalla347ab72015-10-26 21:49:31 -07007692 return false
7693}
7694func rewriteValuegeneric_OpXor32(v *Value, config *Config) bool {
7695 b := v.Block
7696 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007697 // match: (Xor32 x (Const32 <t> [c]))
7698 // cond: x.Op != OpConst32
7699 // result: (Xor32 (Const32 <t> [c]) x)
7700 for {
7701 x := v.Args[0]
7702 if v.Args[1].Op != OpConst32 {
7703 break
7704 }
7705 t := v.Args[1].Type
7706 c := v.Args[1].AuxInt
7707 if !(x.Op != OpConst32) {
7708 break
7709 }
7710 v.reset(OpXor32)
7711 v0 := b.NewValue0(v.Line, OpConst32, t)
7712 v0.AuxInt = c
7713 v.AddArg(v0)
7714 v.AddArg(x)
7715 return true
7716 }
Keith Randalla347ab72015-10-26 21:49:31 -07007717 // match: (Xor32 x x)
7718 // cond:
7719 // result: (Const32 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01007720 for {
Keith Randalla347ab72015-10-26 21:49:31 -07007721 x := v.Args[0]
7722 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007723 break
Keith Randalla347ab72015-10-26 21:49:31 -07007724 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007725 v.reset(OpConst32)
Keith Randalla347ab72015-10-26 21:49:31 -07007726 v.AuxInt = 0
7727 return true
7728 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007729 // match: (Xor32 (Const32 [0]) x)
7730 // cond:
7731 // result: x
7732 for {
7733 if v.Args[0].Op != OpConst32 {
7734 break
7735 }
7736 if v.Args[0].AuxInt != 0 {
7737 break
7738 }
7739 x := v.Args[1]
7740 v.reset(OpCopy)
7741 v.Type = x.Type
7742 v.AddArg(x)
7743 return true
7744 }
Keith Randalla347ab72015-10-26 21:49:31 -07007745 return false
7746}
7747func rewriteValuegeneric_OpXor64(v *Value, config *Config) bool {
7748 b := v.Block
7749 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007750 // match: (Xor64 x (Const64 <t> [c]))
7751 // cond: x.Op != OpConst64
7752 // result: (Xor64 (Const64 <t> [c]) x)
7753 for {
7754 x := v.Args[0]
7755 if v.Args[1].Op != OpConst64 {
7756 break
7757 }
7758 t := v.Args[1].Type
7759 c := v.Args[1].AuxInt
7760 if !(x.Op != OpConst64) {
7761 break
7762 }
7763 v.reset(OpXor64)
7764 v0 := b.NewValue0(v.Line, OpConst64, t)
7765 v0.AuxInt = c
7766 v.AddArg(v0)
7767 v.AddArg(x)
7768 return true
7769 }
Keith Randalla347ab72015-10-26 21:49:31 -07007770 // match: (Xor64 x x)
7771 // cond:
7772 // result: (Const64 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01007773 for {
Keith Randalla347ab72015-10-26 21:49:31 -07007774 x := v.Args[0]
7775 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007776 break
Keith Randalla347ab72015-10-26 21:49:31 -07007777 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007778 v.reset(OpConst64)
Keith Randalla347ab72015-10-26 21:49:31 -07007779 v.AuxInt = 0
7780 return true
7781 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007782 // match: (Xor64 (Const64 [0]) x)
7783 // cond:
7784 // result: x
7785 for {
7786 if v.Args[0].Op != OpConst64 {
7787 break
7788 }
7789 if v.Args[0].AuxInt != 0 {
7790 break
7791 }
7792 x := v.Args[1]
7793 v.reset(OpCopy)
7794 v.Type = x.Type
7795 v.AddArg(x)
7796 return true
7797 }
Keith Randalla347ab72015-10-26 21:49:31 -07007798 return false
7799}
7800func rewriteValuegeneric_OpXor8(v *Value, config *Config) bool {
7801 b := v.Block
7802 _ = b
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007803 // match: (Xor8 x (Const8 <t> [c]))
7804 // cond: x.Op != OpConst8
7805 // result: (Xor8 (Const8 <t> [c]) x)
7806 for {
7807 x := v.Args[0]
7808 if v.Args[1].Op != OpConst8 {
7809 break
7810 }
7811 t := v.Args[1].Type
7812 c := v.Args[1].AuxInt
7813 if !(x.Op != OpConst8) {
7814 break
7815 }
7816 v.reset(OpXor8)
7817 v0 := b.NewValue0(v.Line, OpConst8, t)
7818 v0.AuxInt = c
7819 v.AddArg(v0)
7820 v.AddArg(x)
7821 return true
7822 }
Keith Randalla347ab72015-10-26 21:49:31 -07007823 // match: (Xor8 x x)
7824 // cond:
7825 // result: (Const8 [0])
Alexandru Moșoi05434472016-02-04 19:52:10 +01007826 for {
Keith Randalla347ab72015-10-26 21:49:31 -07007827 x := v.Args[0]
7828 if v.Args[1] != x {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007829 break
Keith Randalla347ab72015-10-26 21:49:31 -07007830 }
Alexandru Moșoi2df4b9c2016-02-04 17:21:57 +01007831 v.reset(OpConst8)
Keith Randalla347ab72015-10-26 21:49:31 -07007832 v.AuxInt = 0
7833 return true
7834 }
Alexandru Moșoifd458ba2016-02-09 19:13:43 +01007835 // match: (Xor8 (Const8 [0]) x)
7836 // cond:
7837 // result: x
7838 for {
7839 if v.Args[0].Op != OpConst8 {
7840 break
7841 }
7842 if v.Args[0].AuxInt != 0 {
7843 break
7844 }
7845 x := v.Args[1]
7846 v.reset(OpCopy)
7847 v.Type = x.Type
7848 v.AddArg(x)
7849 return true
7850 }
Keith Randalla347ab72015-10-26 21:49:31 -07007851 return false
7852}
Keith Randall0dca7352015-06-06 16:03:33 -07007853func rewriteBlockgeneric(b *Block) bool {
7854 switch b.Kind {
Keith Randall31115a52015-10-23 19:12:49 -07007855 case BlockCheck:
7856 // match: (Check (NilCheck (GetG _) _) next)
Josh Bleecher Snyder3d23afb2015-08-12 11:22:16 -07007857 // cond:
Keith Randall31115a52015-10-23 19:12:49 -07007858 // result: (Plain nil next)
Alexandru Moșoi05434472016-02-04 19:52:10 +01007859 for {
Josh Bleecher Snyder3d23afb2015-08-12 11:22:16 -07007860 v := b.Control
Keith Randall31115a52015-10-23 19:12:49 -07007861 if v.Op != OpNilCheck {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007862 break
Josh Bleecher Snyder3d23afb2015-08-12 11:22:16 -07007863 }
7864 if v.Args[0].Op != OpGetG {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007865 break
Josh Bleecher Snyder3d23afb2015-08-12 11:22:16 -07007866 }
Keith Randall31115a52015-10-23 19:12:49 -07007867 next := b.Succs[0]
7868 b.Kind = BlockPlain
Josh Bleecher Snyder3d23afb2015-08-12 11:22:16 -07007869 b.Control = nil
Keith Randall31115a52015-10-23 19:12:49 -07007870 b.Succs[0] = next
7871 b.Likely = BranchUnknown
Josh Bleecher Snyder3d23afb2015-08-12 11:22:16 -07007872 return true
7873 }
Keith Randall31115a52015-10-23 19:12:49 -07007874 case BlockIf:
Todd Neal52d76f72015-07-23 18:44:09 -05007875 // match: (If (Not cond) yes no)
7876 // cond:
7877 // result: (If cond no yes)
Alexandru Moșoi05434472016-02-04 19:52:10 +01007878 for {
Todd Neal52d76f72015-07-23 18:44:09 -05007879 v := b.Control
7880 if v.Op != OpNot {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007881 break
Todd Neal52d76f72015-07-23 18:44:09 -05007882 }
7883 cond := v.Args[0]
7884 yes := b.Succs[0]
7885 no := b.Succs[1]
7886 b.Kind = BlockIf
7887 b.Control = cond
7888 b.Succs[0] = no
7889 b.Succs[1] = yes
Josh Bleecher Snyderbbf8c5c2015-08-11 17:28:56 -07007890 b.Likely *= -1
Todd Neal52d76f72015-07-23 18:44:09 -05007891 return true
7892 }
Todd Neal991036a2015-09-03 18:24:22 -05007893 // match: (If (ConstBool [c]) yes no)
7894 // cond: c == 1
Keith Randall186cf1b2015-08-28 16:45:17 -07007895 // result: (First nil yes no)
Alexandru Moșoi05434472016-02-04 19:52:10 +01007896 for {
Keith Randall0dca7352015-06-06 16:03:33 -07007897 v := b.Control
Keith Randall9cb332e2015-07-28 14:19:20 -07007898 if v.Op != OpConstBool {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007899 break
Keith Randall0dca7352015-06-06 16:03:33 -07007900 }
Todd Neal991036a2015-09-03 18:24:22 -05007901 c := v.AuxInt
Keith Randall0dca7352015-06-06 16:03:33 -07007902 yes := b.Succs[0]
7903 no := b.Succs[1]
Todd Neal991036a2015-09-03 18:24:22 -05007904 if !(c == 1) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007905 break
Keith Randall0dca7352015-06-06 16:03:33 -07007906 }
Keith Randall186cf1b2015-08-28 16:45:17 -07007907 b.Kind = BlockFirst
Keith Randall0dca7352015-06-06 16:03:33 -07007908 b.Control = nil
Keith Randall0dca7352015-06-06 16:03:33 -07007909 b.Succs[0] = yes
Keith Randall186cf1b2015-08-28 16:45:17 -07007910 b.Succs[1] = no
Keith Randall0dca7352015-06-06 16:03:33 -07007911 return true
7912 }
Todd Neal991036a2015-09-03 18:24:22 -05007913 // match: (If (ConstBool [c]) yes no)
7914 // cond: c == 0
Keith Randall186cf1b2015-08-28 16:45:17 -07007915 // result: (First nil no yes)
Alexandru Moșoi05434472016-02-04 19:52:10 +01007916 for {
Keith Randall0dca7352015-06-06 16:03:33 -07007917 v := b.Control
Keith Randall9cb332e2015-07-28 14:19:20 -07007918 if v.Op != OpConstBool {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007919 break
Keith Randall0dca7352015-06-06 16:03:33 -07007920 }
Todd Neal991036a2015-09-03 18:24:22 -05007921 c := v.AuxInt
Keith Randall0dca7352015-06-06 16:03:33 -07007922 yes := b.Succs[0]
7923 no := b.Succs[1]
Todd Neal991036a2015-09-03 18:24:22 -05007924 if !(c == 0) {
Alexandru Moșoi05434472016-02-04 19:52:10 +01007925 break
Keith Randall0dca7352015-06-06 16:03:33 -07007926 }
Keith Randall186cf1b2015-08-28 16:45:17 -07007927 b.Kind = BlockFirst
Keith Randall0dca7352015-06-06 16:03:33 -07007928 b.Control = nil
Keith Randall0dca7352015-06-06 16:03:33 -07007929 b.Succs[0] = no
Keith Randall186cf1b2015-08-28 16:45:17 -07007930 b.Succs[1] = yes
7931 b.Likely *= -1
Keith Randall0dca7352015-06-06 16:03:33 -07007932 return true
7933 }
Keith Randall0dca7352015-06-06 16:03:33 -07007934 }
7935 return false
7936}