]> git.proxmox.com Git - mirror_qemu.git/blob - tcg/optimize.c
tcg/s390: Handle clz opcode
[mirror_qemu.git] / tcg / optimize.c
1 /*
2 * Optimizations for Tiny Code Generator for QEMU
3 *
4 * Copyright (c) 2010 Samsung Electronics.
5 * Contributed by Kirill Batuzov <batuzovk@ispras.ru>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
25
26 #include "qemu/osdep.h"
27 #include "qemu-common.h"
28 #include "exec/cpu-common.h"
29 #include "tcg-op.h"
30
31 #define CASE_OP_32_64(x) \
32 glue(glue(case INDEX_op_, x), _i32): \
33 glue(glue(case INDEX_op_, x), _i64)
34
35 struct tcg_temp_info {
36 bool is_const;
37 uint16_t prev_copy;
38 uint16_t next_copy;
39 tcg_target_ulong val;
40 tcg_target_ulong mask;
41 };
42
43 static struct tcg_temp_info temps[TCG_MAX_TEMPS];
44 static TCGTempSet temps_used;
45
46 static inline bool temp_is_const(TCGArg arg)
47 {
48 return temps[arg].is_const;
49 }
50
51 static inline bool temp_is_copy(TCGArg arg)
52 {
53 return temps[arg].next_copy != arg;
54 }
55
56 /* Reset TEMP's state, possibly removing the temp for the list of copies. */
57 static void reset_temp(TCGArg temp)
58 {
59 temps[temps[temp].next_copy].prev_copy = temps[temp].prev_copy;
60 temps[temps[temp].prev_copy].next_copy = temps[temp].next_copy;
61 temps[temp].next_copy = temp;
62 temps[temp].prev_copy = temp;
63 temps[temp].is_const = false;
64 temps[temp].mask = -1;
65 }
66
67 /* Reset all temporaries, given that there are NB_TEMPS of them. */
68 static void reset_all_temps(int nb_temps)
69 {
70 bitmap_zero(temps_used.l, nb_temps);
71 }
72
73 /* Initialize and activate a temporary. */
74 static void init_temp_info(TCGArg temp)
75 {
76 if (!test_bit(temp, temps_used.l)) {
77 temps[temp].next_copy = temp;
78 temps[temp].prev_copy = temp;
79 temps[temp].is_const = false;
80 temps[temp].mask = -1;
81 set_bit(temp, temps_used.l);
82 }
83 }
84
85 static int op_bits(TCGOpcode op)
86 {
87 const TCGOpDef *def = &tcg_op_defs[op];
88 return def->flags & TCG_OPF_64BIT ? 64 : 32;
89 }
90
91 static TCGOpcode op_to_mov(TCGOpcode op)
92 {
93 switch (op_bits(op)) {
94 case 32:
95 return INDEX_op_mov_i32;
96 case 64:
97 return INDEX_op_mov_i64;
98 default:
99 fprintf(stderr, "op_to_mov: unexpected return value of "
100 "function op_bits.\n");
101 tcg_abort();
102 }
103 }
104
105 static TCGOpcode op_to_movi(TCGOpcode op)
106 {
107 switch (op_bits(op)) {
108 case 32:
109 return INDEX_op_movi_i32;
110 case 64:
111 return INDEX_op_movi_i64;
112 default:
113 fprintf(stderr, "op_to_movi: unexpected return value of "
114 "function op_bits.\n");
115 tcg_abort();
116 }
117 }
118
119 static TCGArg find_better_copy(TCGContext *s, TCGArg temp)
120 {
121 TCGArg i;
122
123 /* If this is already a global, we can't do better. */
124 if (temp < s->nb_globals) {
125 return temp;
126 }
127
128 /* Search for a global first. */
129 for (i = temps[temp].next_copy ; i != temp ; i = temps[i].next_copy) {
130 if (i < s->nb_globals) {
131 return i;
132 }
133 }
134
135 /* If it is a temp, search for a temp local. */
136 if (!s->temps[temp].temp_local) {
137 for (i = temps[temp].next_copy ; i != temp ; i = temps[i].next_copy) {
138 if (s->temps[i].temp_local) {
139 return i;
140 }
141 }
142 }
143
144 /* Failure to find a better representation, return the same temp. */
145 return temp;
146 }
147
148 static bool temps_are_copies(TCGArg arg1, TCGArg arg2)
149 {
150 TCGArg i;
151
152 if (arg1 == arg2) {
153 return true;
154 }
155
156 if (!temp_is_copy(arg1) || !temp_is_copy(arg2)) {
157 return false;
158 }
159
160 for (i = temps[arg1].next_copy ; i != arg1 ; i = temps[i].next_copy) {
161 if (i == arg2) {
162 return true;
163 }
164 }
165
166 return false;
167 }
168
169 static void tcg_opt_gen_movi(TCGContext *s, TCGOp *op, TCGArg *args,
170 TCGArg dst, TCGArg val)
171 {
172 TCGOpcode new_op = op_to_movi(op->opc);
173 tcg_target_ulong mask;
174
175 op->opc = new_op;
176
177 reset_temp(dst);
178 temps[dst].is_const = true;
179 temps[dst].val = val;
180 mask = val;
181 if (TCG_TARGET_REG_BITS > 32 && new_op == INDEX_op_movi_i32) {
182 /* High bits of the destination are now garbage. */
183 mask |= ~0xffffffffull;
184 }
185 temps[dst].mask = mask;
186
187 args[0] = dst;
188 args[1] = val;
189 }
190
191 static void tcg_opt_gen_mov(TCGContext *s, TCGOp *op, TCGArg *args,
192 TCGArg dst, TCGArg src)
193 {
194 if (temps_are_copies(dst, src)) {
195 tcg_op_remove(s, op);
196 return;
197 }
198
199 TCGOpcode new_op = op_to_mov(op->opc);
200 tcg_target_ulong mask;
201
202 op->opc = new_op;
203
204 reset_temp(dst);
205 mask = temps[src].mask;
206 if (TCG_TARGET_REG_BITS > 32 && new_op == INDEX_op_mov_i32) {
207 /* High bits of the destination are now garbage. */
208 mask |= ~0xffffffffull;
209 }
210 temps[dst].mask = mask;
211
212 if (s->temps[src].type == s->temps[dst].type) {
213 temps[dst].next_copy = temps[src].next_copy;
214 temps[dst].prev_copy = src;
215 temps[temps[dst].next_copy].prev_copy = dst;
216 temps[src].next_copy = dst;
217 temps[dst].is_const = temps[src].is_const;
218 temps[dst].val = temps[src].val;
219 }
220
221 args[0] = dst;
222 args[1] = src;
223 }
224
225 static TCGArg do_constant_folding_2(TCGOpcode op, TCGArg x, TCGArg y)
226 {
227 uint64_t l64, h64;
228
229 switch (op) {
230 CASE_OP_32_64(add):
231 return x + y;
232
233 CASE_OP_32_64(sub):
234 return x - y;
235
236 CASE_OP_32_64(mul):
237 return x * y;
238
239 CASE_OP_32_64(and):
240 return x & y;
241
242 CASE_OP_32_64(or):
243 return x | y;
244
245 CASE_OP_32_64(xor):
246 return x ^ y;
247
248 case INDEX_op_shl_i32:
249 return (uint32_t)x << (y & 31);
250
251 case INDEX_op_shl_i64:
252 return (uint64_t)x << (y & 63);
253
254 case INDEX_op_shr_i32:
255 return (uint32_t)x >> (y & 31);
256
257 case INDEX_op_shr_i64:
258 return (uint64_t)x >> (y & 63);
259
260 case INDEX_op_sar_i32:
261 return (int32_t)x >> (y & 31);
262
263 case INDEX_op_sar_i64:
264 return (int64_t)x >> (y & 63);
265
266 case INDEX_op_rotr_i32:
267 return ror32(x, y & 31);
268
269 case INDEX_op_rotr_i64:
270 return ror64(x, y & 63);
271
272 case INDEX_op_rotl_i32:
273 return rol32(x, y & 31);
274
275 case INDEX_op_rotl_i64:
276 return rol64(x, y & 63);
277
278 CASE_OP_32_64(not):
279 return ~x;
280
281 CASE_OP_32_64(neg):
282 return -x;
283
284 CASE_OP_32_64(andc):
285 return x & ~y;
286
287 CASE_OP_32_64(orc):
288 return x | ~y;
289
290 CASE_OP_32_64(eqv):
291 return ~(x ^ y);
292
293 CASE_OP_32_64(nand):
294 return ~(x & y);
295
296 CASE_OP_32_64(nor):
297 return ~(x | y);
298
299 case INDEX_op_clz_i32:
300 return (uint32_t)x ? clz32(x) : y;
301
302 case INDEX_op_clz_i64:
303 return x ? clz64(x) : y;
304
305 case INDEX_op_ctz_i32:
306 return (uint32_t)x ? ctz32(x) : y;
307
308 case INDEX_op_ctz_i64:
309 return x ? ctz64(x) : y;
310
311 CASE_OP_32_64(ext8s):
312 return (int8_t)x;
313
314 CASE_OP_32_64(ext16s):
315 return (int16_t)x;
316
317 CASE_OP_32_64(ext8u):
318 return (uint8_t)x;
319
320 CASE_OP_32_64(ext16u):
321 return (uint16_t)x;
322
323 case INDEX_op_ext_i32_i64:
324 case INDEX_op_ext32s_i64:
325 return (int32_t)x;
326
327 case INDEX_op_extu_i32_i64:
328 case INDEX_op_extrl_i64_i32:
329 case INDEX_op_ext32u_i64:
330 return (uint32_t)x;
331
332 case INDEX_op_extrh_i64_i32:
333 return (uint64_t)x >> 32;
334
335 case INDEX_op_muluh_i32:
336 return ((uint64_t)(uint32_t)x * (uint32_t)y) >> 32;
337 case INDEX_op_mulsh_i32:
338 return ((int64_t)(int32_t)x * (int32_t)y) >> 32;
339
340 case INDEX_op_muluh_i64:
341 mulu64(&l64, &h64, x, y);
342 return h64;
343 case INDEX_op_mulsh_i64:
344 muls64(&l64, &h64, x, y);
345 return h64;
346
347 case INDEX_op_div_i32:
348 /* Avoid crashing on divide by zero, otherwise undefined. */
349 return (int32_t)x / ((int32_t)y ? : 1);
350 case INDEX_op_divu_i32:
351 return (uint32_t)x / ((uint32_t)y ? : 1);
352 case INDEX_op_div_i64:
353 return (int64_t)x / ((int64_t)y ? : 1);
354 case INDEX_op_divu_i64:
355 return (uint64_t)x / ((uint64_t)y ? : 1);
356
357 case INDEX_op_rem_i32:
358 return (int32_t)x % ((int32_t)y ? : 1);
359 case INDEX_op_remu_i32:
360 return (uint32_t)x % ((uint32_t)y ? : 1);
361 case INDEX_op_rem_i64:
362 return (int64_t)x % ((int64_t)y ? : 1);
363 case INDEX_op_remu_i64:
364 return (uint64_t)x % ((uint64_t)y ? : 1);
365
366 default:
367 fprintf(stderr,
368 "Unrecognized operation %d in do_constant_folding.\n", op);
369 tcg_abort();
370 }
371 }
372
373 static TCGArg do_constant_folding(TCGOpcode op, TCGArg x, TCGArg y)
374 {
375 TCGArg res = do_constant_folding_2(op, x, y);
376 if (op_bits(op) == 32) {
377 res = (int32_t)res;
378 }
379 return res;
380 }
381
382 static bool do_constant_folding_cond_32(uint32_t x, uint32_t y, TCGCond c)
383 {
384 switch (c) {
385 case TCG_COND_EQ:
386 return x == y;
387 case TCG_COND_NE:
388 return x != y;
389 case TCG_COND_LT:
390 return (int32_t)x < (int32_t)y;
391 case TCG_COND_GE:
392 return (int32_t)x >= (int32_t)y;
393 case TCG_COND_LE:
394 return (int32_t)x <= (int32_t)y;
395 case TCG_COND_GT:
396 return (int32_t)x > (int32_t)y;
397 case TCG_COND_LTU:
398 return x < y;
399 case TCG_COND_GEU:
400 return x >= y;
401 case TCG_COND_LEU:
402 return x <= y;
403 case TCG_COND_GTU:
404 return x > y;
405 default:
406 tcg_abort();
407 }
408 }
409
410 static bool do_constant_folding_cond_64(uint64_t x, uint64_t y, TCGCond c)
411 {
412 switch (c) {
413 case TCG_COND_EQ:
414 return x == y;
415 case TCG_COND_NE:
416 return x != y;
417 case TCG_COND_LT:
418 return (int64_t)x < (int64_t)y;
419 case TCG_COND_GE:
420 return (int64_t)x >= (int64_t)y;
421 case TCG_COND_LE:
422 return (int64_t)x <= (int64_t)y;
423 case TCG_COND_GT:
424 return (int64_t)x > (int64_t)y;
425 case TCG_COND_LTU:
426 return x < y;
427 case TCG_COND_GEU:
428 return x >= y;
429 case TCG_COND_LEU:
430 return x <= y;
431 case TCG_COND_GTU:
432 return x > y;
433 default:
434 tcg_abort();
435 }
436 }
437
438 static bool do_constant_folding_cond_eq(TCGCond c)
439 {
440 switch (c) {
441 case TCG_COND_GT:
442 case TCG_COND_LTU:
443 case TCG_COND_LT:
444 case TCG_COND_GTU:
445 case TCG_COND_NE:
446 return 0;
447 case TCG_COND_GE:
448 case TCG_COND_GEU:
449 case TCG_COND_LE:
450 case TCG_COND_LEU:
451 case TCG_COND_EQ:
452 return 1;
453 default:
454 tcg_abort();
455 }
456 }
457
458 /* Return 2 if the condition can't be simplified, and the result
459 of the condition (0 or 1) if it can */
460 static TCGArg do_constant_folding_cond(TCGOpcode op, TCGArg x,
461 TCGArg y, TCGCond c)
462 {
463 if (temp_is_const(x) && temp_is_const(y)) {
464 switch (op_bits(op)) {
465 case 32:
466 return do_constant_folding_cond_32(temps[x].val, temps[y].val, c);
467 case 64:
468 return do_constant_folding_cond_64(temps[x].val, temps[y].val, c);
469 default:
470 tcg_abort();
471 }
472 } else if (temps_are_copies(x, y)) {
473 return do_constant_folding_cond_eq(c);
474 } else if (temp_is_const(y) && temps[y].val == 0) {
475 switch (c) {
476 case TCG_COND_LTU:
477 return 0;
478 case TCG_COND_GEU:
479 return 1;
480 default:
481 return 2;
482 }
483 }
484 return 2;
485 }
486
487 /* Return 2 if the condition can't be simplified, and the result
488 of the condition (0 or 1) if it can */
489 static TCGArg do_constant_folding_cond2(TCGArg *p1, TCGArg *p2, TCGCond c)
490 {
491 TCGArg al = p1[0], ah = p1[1];
492 TCGArg bl = p2[0], bh = p2[1];
493
494 if (temp_is_const(bl) && temp_is_const(bh)) {
495 uint64_t b = ((uint64_t)temps[bh].val << 32) | (uint32_t)temps[bl].val;
496
497 if (temp_is_const(al) && temp_is_const(ah)) {
498 uint64_t a;
499 a = ((uint64_t)temps[ah].val << 32) | (uint32_t)temps[al].val;
500 return do_constant_folding_cond_64(a, b, c);
501 }
502 if (b == 0) {
503 switch (c) {
504 case TCG_COND_LTU:
505 return 0;
506 case TCG_COND_GEU:
507 return 1;
508 default:
509 break;
510 }
511 }
512 }
513 if (temps_are_copies(al, bl) && temps_are_copies(ah, bh)) {
514 return do_constant_folding_cond_eq(c);
515 }
516 return 2;
517 }
518
519 static bool swap_commutative(TCGArg dest, TCGArg *p1, TCGArg *p2)
520 {
521 TCGArg a1 = *p1, a2 = *p2;
522 int sum = 0;
523 sum += temp_is_const(a1);
524 sum -= temp_is_const(a2);
525
526 /* Prefer the constant in second argument, and then the form
527 op a, a, b, which is better handled on non-RISC hosts. */
528 if (sum > 0 || (sum == 0 && dest == a2)) {
529 *p1 = a2;
530 *p2 = a1;
531 return true;
532 }
533 return false;
534 }
535
536 static bool swap_commutative2(TCGArg *p1, TCGArg *p2)
537 {
538 int sum = 0;
539 sum += temp_is_const(p1[0]);
540 sum += temp_is_const(p1[1]);
541 sum -= temp_is_const(p2[0]);
542 sum -= temp_is_const(p2[1]);
543 if (sum > 0) {
544 TCGArg t;
545 t = p1[0], p1[0] = p2[0], p2[0] = t;
546 t = p1[1], p1[1] = p2[1], p2[1] = t;
547 return true;
548 }
549 return false;
550 }
551
552 /* Propagate constants and copies, fold constant expressions. */
553 void tcg_optimize(TCGContext *s)
554 {
555 int oi, oi_next, nb_temps, nb_globals;
556 TCGArg *prev_mb_args = NULL;
557
558 /* Array VALS has an element for each temp.
559 If this temp holds a constant then its value is kept in VALS' element.
560 If this temp is a copy of other ones then the other copies are
561 available through the doubly linked circular list. */
562
563 nb_temps = s->nb_temps;
564 nb_globals = s->nb_globals;
565 reset_all_temps(nb_temps);
566
567 for (oi = s->gen_op_buf[0].next; oi != 0; oi = oi_next) {
568 tcg_target_ulong mask, partmask, affected;
569 int nb_oargs, nb_iargs, i;
570 TCGArg tmp;
571
572 TCGOp * const op = &s->gen_op_buf[oi];
573 TCGArg * const args = &s->gen_opparam_buf[op->args];
574 TCGOpcode opc = op->opc;
575 const TCGOpDef *def = &tcg_op_defs[opc];
576
577 oi_next = op->next;
578
579 /* Count the arguments, and initialize the temps that are
580 going to be used */
581 if (opc == INDEX_op_call) {
582 nb_oargs = op->callo;
583 nb_iargs = op->calli;
584 for (i = 0; i < nb_oargs + nb_iargs; i++) {
585 tmp = args[i];
586 if (tmp != TCG_CALL_DUMMY_ARG) {
587 init_temp_info(tmp);
588 }
589 }
590 } else {
591 nb_oargs = def->nb_oargs;
592 nb_iargs = def->nb_iargs;
593 for (i = 0; i < nb_oargs + nb_iargs; i++) {
594 init_temp_info(args[i]);
595 }
596 }
597
598 /* Do copy propagation */
599 for (i = nb_oargs; i < nb_oargs + nb_iargs; i++) {
600 if (temp_is_copy(args[i])) {
601 args[i] = find_better_copy(s, args[i]);
602 }
603 }
604
605 /* For commutative operations make constant second argument */
606 switch (opc) {
607 CASE_OP_32_64(add):
608 CASE_OP_32_64(mul):
609 CASE_OP_32_64(and):
610 CASE_OP_32_64(or):
611 CASE_OP_32_64(xor):
612 CASE_OP_32_64(eqv):
613 CASE_OP_32_64(nand):
614 CASE_OP_32_64(nor):
615 CASE_OP_32_64(muluh):
616 CASE_OP_32_64(mulsh):
617 swap_commutative(args[0], &args[1], &args[2]);
618 break;
619 CASE_OP_32_64(brcond):
620 if (swap_commutative(-1, &args[0], &args[1])) {
621 args[2] = tcg_swap_cond(args[2]);
622 }
623 break;
624 CASE_OP_32_64(setcond):
625 if (swap_commutative(args[0], &args[1], &args[2])) {
626 args[3] = tcg_swap_cond(args[3]);
627 }
628 break;
629 CASE_OP_32_64(movcond):
630 if (swap_commutative(-1, &args[1], &args[2])) {
631 args[5] = tcg_swap_cond(args[5]);
632 }
633 /* For movcond, we canonicalize the "false" input reg to match
634 the destination reg so that the tcg backend can implement
635 a "move if true" operation. */
636 if (swap_commutative(args[0], &args[4], &args[3])) {
637 args[5] = tcg_invert_cond(args[5]);
638 }
639 break;
640 CASE_OP_32_64(add2):
641 swap_commutative(args[0], &args[2], &args[4]);
642 swap_commutative(args[1], &args[3], &args[5]);
643 break;
644 CASE_OP_32_64(mulu2):
645 CASE_OP_32_64(muls2):
646 swap_commutative(args[0], &args[2], &args[3]);
647 break;
648 case INDEX_op_brcond2_i32:
649 if (swap_commutative2(&args[0], &args[2])) {
650 args[4] = tcg_swap_cond(args[4]);
651 }
652 break;
653 case INDEX_op_setcond2_i32:
654 if (swap_commutative2(&args[1], &args[3])) {
655 args[5] = tcg_swap_cond(args[5]);
656 }
657 break;
658 default:
659 break;
660 }
661
662 /* Simplify expressions for "shift/rot r, 0, a => movi r, 0",
663 and "sub r, 0, a => neg r, a" case. */
664 switch (opc) {
665 CASE_OP_32_64(shl):
666 CASE_OP_32_64(shr):
667 CASE_OP_32_64(sar):
668 CASE_OP_32_64(rotl):
669 CASE_OP_32_64(rotr):
670 if (temp_is_const(args[1]) && temps[args[1]].val == 0) {
671 tcg_opt_gen_movi(s, op, args, args[0], 0);
672 continue;
673 }
674 break;
675 CASE_OP_32_64(sub):
676 {
677 TCGOpcode neg_op;
678 bool have_neg;
679
680 if (temp_is_const(args[2])) {
681 /* Proceed with possible constant folding. */
682 break;
683 }
684 if (opc == INDEX_op_sub_i32) {
685 neg_op = INDEX_op_neg_i32;
686 have_neg = TCG_TARGET_HAS_neg_i32;
687 } else {
688 neg_op = INDEX_op_neg_i64;
689 have_neg = TCG_TARGET_HAS_neg_i64;
690 }
691 if (!have_neg) {
692 break;
693 }
694 if (temp_is_const(args[1]) && temps[args[1]].val == 0) {
695 op->opc = neg_op;
696 reset_temp(args[0]);
697 args[1] = args[2];
698 continue;
699 }
700 }
701 break;
702 CASE_OP_32_64(xor):
703 CASE_OP_32_64(nand):
704 if (!temp_is_const(args[1])
705 && temp_is_const(args[2]) && temps[args[2]].val == -1) {
706 i = 1;
707 goto try_not;
708 }
709 break;
710 CASE_OP_32_64(nor):
711 if (!temp_is_const(args[1])
712 && temp_is_const(args[2]) && temps[args[2]].val == 0) {
713 i = 1;
714 goto try_not;
715 }
716 break;
717 CASE_OP_32_64(andc):
718 if (!temp_is_const(args[2])
719 && temp_is_const(args[1]) && temps[args[1]].val == -1) {
720 i = 2;
721 goto try_not;
722 }
723 break;
724 CASE_OP_32_64(orc):
725 CASE_OP_32_64(eqv):
726 if (!temp_is_const(args[2])
727 && temp_is_const(args[1]) && temps[args[1]].val == 0) {
728 i = 2;
729 goto try_not;
730 }
731 break;
732 try_not:
733 {
734 TCGOpcode not_op;
735 bool have_not;
736
737 if (def->flags & TCG_OPF_64BIT) {
738 not_op = INDEX_op_not_i64;
739 have_not = TCG_TARGET_HAS_not_i64;
740 } else {
741 not_op = INDEX_op_not_i32;
742 have_not = TCG_TARGET_HAS_not_i32;
743 }
744 if (!have_not) {
745 break;
746 }
747 op->opc = not_op;
748 reset_temp(args[0]);
749 args[1] = args[i];
750 continue;
751 }
752 default:
753 break;
754 }
755
756 /* Simplify expression for "op r, a, const => mov r, a" cases */
757 switch (opc) {
758 CASE_OP_32_64(add):
759 CASE_OP_32_64(sub):
760 CASE_OP_32_64(shl):
761 CASE_OP_32_64(shr):
762 CASE_OP_32_64(sar):
763 CASE_OP_32_64(rotl):
764 CASE_OP_32_64(rotr):
765 CASE_OP_32_64(or):
766 CASE_OP_32_64(xor):
767 CASE_OP_32_64(andc):
768 if (!temp_is_const(args[1])
769 && temp_is_const(args[2]) && temps[args[2]].val == 0) {
770 tcg_opt_gen_mov(s, op, args, args[0], args[1]);
771 continue;
772 }
773 break;
774 CASE_OP_32_64(and):
775 CASE_OP_32_64(orc):
776 CASE_OP_32_64(eqv):
777 if (!temp_is_const(args[1])
778 && temp_is_const(args[2]) && temps[args[2]].val == -1) {
779 tcg_opt_gen_mov(s, op, args, args[0], args[1]);
780 continue;
781 }
782 break;
783 default:
784 break;
785 }
786
787 /* Simplify using known-zero bits. Currently only ops with a single
788 output argument is supported. */
789 mask = -1;
790 affected = -1;
791 switch (opc) {
792 CASE_OP_32_64(ext8s):
793 if ((temps[args[1]].mask & 0x80) != 0) {
794 break;
795 }
796 CASE_OP_32_64(ext8u):
797 mask = 0xff;
798 goto and_const;
799 CASE_OP_32_64(ext16s):
800 if ((temps[args[1]].mask & 0x8000) != 0) {
801 break;
802 }
803 CASE_OP_32_64(ext16u):
804 mask = 0xffff;
805 goto and_const;
806 case INDEX_op_ext32s_i64:
807 if ((temps[args[1]].mask & 0x80000000) != 0) {
808 break;
809 }
810 case INDEX_op_ext32u_i64:
811 mask = 0xffffffffU;
812 goto and_const;
813
814 CASE_OP_32_64(and):
815 mask = temps[args[2]].mask;
816 if (temp_is_const(args[2])) {
817 and_const:
818 affected = temps[args[1]].mask & ~mask;
819 }
820 mask = temps[args[1]].mask & mask;
821 break;
822
823 case INDEX_op_ext_i32_i64:
824 if ((temps[args[1]].mask & 0x80000000) != 0) {
825 break;
826 }
827 case INDEX_op_extu_i32_i64:
828 /* We do not compute affected as it is a size changing op. */
829 mask = (uint32_t)temps[args[1]].mask;
830 break;
831
832 CASE_OP_32_64(andc):
833 /* Known-zeros does not imply known-ones. Therefore unless
834 args[2] is constant, we can't infer anything from it. */
835 if (temp_is_const(args[2])) {
836 mask = ~temps[args[2]].mask;
837 goto and_const;
838 }
839 /* But we certainly know nothing outside args[1] may be set. */
840 mask = temps[args[1]].mask;
841 break;
842
843 case INDEX_op_sar_i32:
844 if (temp_is_const(args[2])) {
845 tmp = temps[args[2]].val & 31;
846 mask = (int32_t)temps[args[1]].mask >> tmp;
847 }
848 break;
849 case INDEX_op_sar_i64:
850 if (temp_is_const(args[2])) {
851 tmp = temps[args[2]].val & 63;
852 mask = (int64_t)temps[args[1]].mask >> tmp;
853 }
854 break;
855
856 case INDEX_op_shr_i32:
857 if (temp_is_const(args[2])) {
858 tmp = temps[args[2]].val & 31;
859 mask = (uint32_t)temps[args[1]].mask >> tmp;
860 }
861 break;
862 case INDEX_op_shr_i64:
863 if (temp_is_const(args[2])) {
864 tmp = temps[args[2]].val & 63;
865 mask = (uint64_t)temps[args[1]].mask >> tmp;
866 }
867 break;
868
869 case INDEX_op_extrl_i64_i32:
870 mask = (uint32_t)temps[args[1]].mask;
871 break;
872 case INDEX_op_extrh_i64_i32:
873 mask = (uint64_t)temps[args[1]].mask >> 32;
874 break;
875
876 CASE_OP_32_64(shl):
877 if (temp_is_const(args[2])) {
878 tmp = temps[args[2]].val & (TCG_TARGET_REG_BITS - 1);
879 mask = temps[args[1]].mask << tmp;
880 }
881 break;
882
883 CASE_OP_32_64(neg):
884 /* Set to 1 all bits to the left of the rightmost. */
885 mask = -(temps[args[1]].mask & -temps[args[1]].mask);
886 break;
887
888 CASE_OP_32_64(deposit):
889 mask = deposit64(temps[args[1]].mask, args[3], args[4],
890 temps[args[2]].mask);
891 break;
892
893 CASE_OP_32_64(extract):
894 mask = extract64(temps[args[1]].mask, args[2], args[3]);
895 if (args[2] == 0) {
896 affected = temps[args[1]].mask & ~mask;
897 }
898 break;
899 CASE_OP_32_64(sextract):
900 mask = sextract64(temps[args[1]].mask, args[2], args[3]);
901 if (args[2] == 0 && (tcg_target_long)mask >= 0) {
902 affected = temps[args[1]].mask & ~mask;
903 }
904 break;
905
906 CASE_OP_32_64(or):
907 CASE_OP_32_64(xor):
908 mask = temps[args[1]].mask | temps[args[2]].mask;
909 break;
910
911 case INDEX_op_clz_i32:
912 case INDEX_op_ctz_i32:
913 mask = temps[args[2]].mask | 31;
914 break;
915
916 case INDEX_op_clz_i64:
917 case INDEX_op_ctz_i64:
918 mask = temps[args[2]].mask | 63;
919 break;
920
921 CASE_OP_32_64(setcond):
922 case INDEX_op_setcond2_i32:
923 mask = 1;
924 break;
925
926 CASE_OP_32_64(movcond):
927 mask = temps[args[3]].mask | temps[args[4]].mask;
928 break;
929
930 CASE_OP_32_64(ld8u):
931 mask = 0xff;
932 break;
933 CASE_OP_32_64(ld16u):
934 mask = 0xffff;
935 break;
936 case INDEX_op_ld32u_i64:
937 mask = 0xffffffffu;
938 break;
939
940 CASE_OP_32_64(qemu_ld):
941 {
942 TCGMemOpIdx oi = args[nb_oargs + nb_iargs];
943 TCGMemOp mop = get_memop(oi);
944 if (!(mop & MO_SIGN)) {
945 mask = (2ULL << ((8 << (mop & MO_SIZE)) - 1)) - 1;
946 }
947 }
948 break;
949
950 default:
951 break;
952 }
953
954 /* 32-bit ops generate 32-bit results. For the result is zero test
955 below, we can ignore high bits, but for further optimizations we
956 need to record that the high bits contain garbage. */
957 partmask = mask;
958 if (!(def->flags & TCG_OPF_64BIT)) {
959 mask |= ~(tcg_target_ulong)0xffffffffu;
960 partmask &= 0xffffffffu;
961 affected &= 0xffffffffu;
962 }
963
964 if (partmask == 0) {
965 tcg_debug_assert(nb_oargs == 1);
966 tcg_opt_gen_movi(s, op, args, args[0], 0);
967 continue;
968 }
969 if (affected == 0) {
970 tcg_debug_assert(nb_oargs == 1);
971 tcg_opt_gen_mov(s, op, args, args[0], args[1]);
972 continue;
973 }
974
975 /* Simplify expression for "op r, a, 0 => movi r, 0" cases */
976 switch (opc) {
977 CASE_OP_32_64(and):
978 CASE_OP_32_64(mul):
979 CASE_OP_32_64(muluh):
980 CASE_OP_32_64(mulsh):
981 if ((temp_is_const(args[2]) && temps[args[2]].val == 0)) {
982 tcg_opt_gen_movi(s, op, args, args[0], 0);
983 continue;
984 }
985 break;
986 default:
987 break;
988 }
989
990 /* Simplify expression for "op r, a, a => mov r, a" cases */
991 switch (opc) {
992 CASE_OP_32_64(or):
993 CASE_OP_32_64(and):
994 if (temps_are_copies(args[1], args[2])) {
995 tcg_opt_gen_mov(s, op, args, args[0], args[1]);
996 continue;
997 }
998 break;
999 default:
1000 break;
1001 }
1002
1003 /* Simplify expression for "op r, a, a => movi r, 0" cases */
1004 switch (opc) {
1005 CASE_OP_32_64(andc):
1006 CASE_OP_32_64(sub):
1007 CASE_OP_32_64(xor):
1008 if (temps_are_copies(args[1], args[2])) {
1009 tcg_opt_gen_movi(s, op, args, args[0], 0);
1010 continue;
1011 }
1012 break;
1013 default:
1014 break;
1015 }
1016
1017 /* Propagate constants through copy operations and do constant
1018 folding. Constants will be substituted to arguments by register
1019 allocator where needed and possible. Also detect copies. */
1020 switch (opc) {
1021 CASE_OP_32_64(mov):
1022 tcg_opt_gen_mov(s, op, args, args[0], args[1]);
1023 break;
1024 CASE_OP_32_64(movi):
1025 tcg_opt_gen_movi(s, op, args, args[0], args[1]);
1026 break;
1027
1028 CASE_OP_32_64(not):
1029 CASE_OP_32_64(neg):
1030 CASE_OP_32_64(ext8s):
1031 CASE_OP_32_64(ext8u):
1032 CASE_OP_32_64(ext16s):
1033 CASE_OP_32_64(ext16u):
1034 case INDEX_op_ext32s_i64:
1035 case INDEX_op_ext32u_i64:
1036 case INDEX_op_ext_i32_i64:
1037 case INDEX_op_extu_i32_i64:
1038 case INDEX_op_extrl_i64_i32:
1039 case INDEX_op_extrh_i64_i32:
1040 if (temp_is_const(args[1])) {
1041 tmp = do_constant_folding(opc, temps[args[1]].val, 0);
1042 tcg_opt_gen_movi(s, op, args, args[0], tmp);
1043 break;
1044 }
1045 goto do_default;
1046
1047 CASE_OP_32_64(add):
1048 CASE_OP_32_64(sub):
1049 CASE_OP_32_64(mul):
1050 CASE_OP_32_64(or):
1051 CASE_OP_32_64(and):
1052 CASE_OP_32_64(xor):
1053 CASE_OP_32_64(shl):
1054 CASE_OP_32_64(shr):
1055 CASE_OP_32_64(sar):
1056 CASE_OP_32_64(rotl):
1057 CASE_OP_32_64(rotr):
1058 CASE_OP_32_64(andc):
1059 CASE_OP_32_64(orc):
1060 CASE_OP_32_64(eqv):
1061 CASE_OP_32_64(nand):
1062 CASE_OP_32_64(nor):
1063 CASE_OP_32_64(muluh):
1064 CASE_OP_32_64(mulsh):
1065 CASE_OP_32_64(div):
1066 CASE_OP_32_64(divu):
1067 CASE_OP_32_64(rem):
1068 CASE_OP_32_64(remu):
1069 if (temp_is_const(args[1]) && temp_is_const(args[2])) {
1070 tmp = do_constant_folding(opc, temps[args[1]].val,
1071 temps[args[2]].val);
1072 tcg_opt_gen_movi(s, op, args, args[0], tmp);
1073 break;
1074 }
1075 goto do_default;
1076
1077 CASE_OP_32_64(clz):
1078 CASE_OP_32_64(ctz):
1079 if (temp_is_const(args[1])) {
1080 TCGArg v = temps[args[1]].val;
1081 if (v != 0) {
1082 tmp = do_constant_folding(opc, v, 0);
1083 tcg_opt_gen_movi(s, op, args, args[0], tmp);
1084 } else {
1085 tcg_opt_gen_mov(s, op, args, args[0], args[2]);
1086 }
1087 break;
1088 }
1089 goto do_default;
1090
1091 CASE_OP_32_64(deposit):
1092 if (temp_is_const(args[1]) && temp_is_const(args[2])) {
1093 tmp = deposit64(temps[args[1]].val, args[3], args[4],
1094 temps[args[2]].val);
1095 tcg_opt_gen_movi(s, op, args, args[0], tmp);
1096 break;
1097 }
1098 goto do_default;
1099
1100 CASE_OP_32_64(extract):
1101 if (temp_is_const(args[1])) {
1102 tmp = extract64(temps[args[1]].val, args[2], args[3]);
1103 tcg_opt_gen_movi(s, op, args, args[0], tmp);
1104 break;
1105 }
1106 goto do_default;
1107
1108 CASE_OP_32_64(sextract):
1109 if (temp_is_const(args[1])) {
1110 tmp = sextract64(temps[args[1]].val, args[2], args[3]);
1111 tcg_opt_gen_movi(s, op, args, args[0], tmp);
1112 break;
1113 }
1114 goto do_default;
1115
1116 CASE_OP_32_64(setcond):
1117 tmp = do_constant_folding_cond(opc, args[1], args[2], args[3]);
1118 if (tmp != 2) {
1119 tcg_opt_gen_movi(s, op, args, args[0], tmp);
1120 break;
1121 }
1122 goto do_default;
1123
1124 CASE_OP_32_64(brcond):
1125 tmp = do_constant_folding_cond(opc, args[0], args[1], args[2]);
1126 if (tmp != 2) {
1127 if (tmp) {
1128 reset_all_temps(nb_temps);
1129 op->opc = INDEX_op_br;
1130 args[0] = args[3];
1131 } else {
1132 tcg_op_remove(s, op);
1133 }
1134 break;
1135 }
1136 goto do_default;
1137
1138 CASE_OP_32_64(movcond):
1139 tmp = do_constant_folding_cond(opc, args[1], args[2], args[5]);
1140 if (tmp != 2) {
1141 tcg_opt_gen_mov(s, op, args, args[0], args[4-tmp]);
1142 break;
1143 }
1144 if (temp_is_const(args[3]) && temp_is_const(args[4])) {
1145 tcg_target_ulong tv = temps[args[3]].val;
1146 tcg_target_ulong fv = temps[args[4]].val;
1147 TCGCond cond = args[5];
1148 if (fv == 1 && tv == 0) {
1149 cond = tcg_invert_cond(cond);
1150 } else if (!(tv == 1 && fv == 0)) {
1151 goto do_default;
1152 }
1153 args[3] = cond;
1154 op->opc = opc = (opc == INDEX_op_movcond_i32
1155 ? INDEX_op_setcond_i32
1156 : INDEX_op_setcond_i64);
1157 nb_iargs = 2;
1158 }
1159 goto do_default;
1160
1161 case INDEX_op_add2_i32:
1162 case INDEX_op_sub2_i32:
1163 if (temp_is_const(args[2]) && temp_is_const(args[3])
1164 && temp_is_const(args[4]) && temp_is_const(args[5])) {
1165 uint32_t al = temps[args[2]].val;
1166 uint32_t ah = temps[args[3]].val;
1167 uint32_t bl = temps[args[4]].val;
1168 uint32_t bh = temps[args[5]].val;
1169 uint64_t a = ((uint64_t)ah << 32) | al;
1170 uint64_t b = ((uint64_t)bh << 32) | bl;
1171 TCGArg rl, rh;
1172 TCGOp *op2 = tcg_op_insert_before(s, op, INDEX_op_movi_i32, 2);
1173 TCGArg *args2 = &s->gen_opparam_buf[op2->args];
1174
1175 if (opc == INDEX_op_add2_i32) {
1176 a += b;
1177 } else {
1178 a -= b;
1179 }
1180
1181 rl = args[0];
1182 rh = args[1];
1183 tcg_opt_gen_movi(s, op, args, rl, (int32_t)a);
1184 tcg_opt_gen_movi(s, op2, args2, rh, (int32_t)(a >> 32));
1185
1186 /* We've done all we need to do with the movi. Skip it. */
1187 oi_next = op2->next;
1188 break;
1189 }
1190 goto do_default;
1191
1192 case INDEX_op_mulu2_i32:
1193 if (temp_is_const(args[2]) && temp_is_const(args[3])) {
1194 uint32_t a = temps[args[2]].val;
1195 uint32_t b = temps[args[3]].val;
1196 uint64_t r = (uint64_t)a * b;
1197 TCGArg rl, rh;
1198 TCGOp *op2 = tcg_op_insert_before(s, op, INDEX_op_movi_i32, 2);
1199 TCGArg *args2 = &s->gen_opparam_buf[op2->args];
1200
1201 rl = args[0];
1202 rh = args[1];
1203 tcg_opt_gen_movi(s, op, args, rl, (int32_t)r);
1204 tcg_opt_gen_movi(s, op2, args2, rh, (int32_t)(r >> 32));
1205
1206 /* We've done all we need to do with the movi. Skip it. */
1207 oi_next = op2->next;
1208 break;
1209 }
1210 goto do_default;
1211
1212 case INDEX_op_brcond2_i32:
1213 tmp = do_constant_folding_cond2(&args[0], &args[2], args[4]);
1214 if (tmp != 2) {
1215 if (tmp) {
1216 do_brcond_true:
1217 reset_all_temps(nb_temps);
1218 op->opc = INDEX_op_br;
1219 args[0] = args[5];
1220 } else {
1221 do_brcond_false:
1222 tcg_op_remove(s, op);
1223 }
1224 } else if ((args[4] == TCG_COND_LT || args[4] == TCG_COND_GE)
1225 && temp_is_const(args[2]) && temps[args[2]].val == 0
1226 && temp_is_const(args[3]) && temps[args[3]].val == 0) {
1227 /* Simplify LT/GE comparisons vs zero to a single compare
1228 vs the high word of the input. */
1229 do_brcond_high:
1230 reset_all_temps(nb_temps);
1231 op->opc = INDEX_op_brcond_i32;
1232 args[0] = args[1];
1233 args[1] = args[3];
1234 args[2] = args[4];
1235 args[3] = args[5];
1236 } else if (args[4] == TCG_COND_EQ) {
1237 /* Simplify EQ comparisons where one of the pairs
1238 can be simplified. */
1239 tmp = do_constant_folding_cond(INDEX_op_brcond_i32,
1240 args[0], args[2], TCG_COND_EQ);
1241 if (tmp == 0) {
1242 goto do_brcond_false;
1243 } else if (tmp == 1) {
1244 goto do_brcond_high;
1245 }
1246 tmp = do_constant_folding_cond(INDEX_op_brcond_i32,
1247 args[1], args[3], TCG_COND_EQ);
1248 if (tmp == 0) {
1249 goto do_brcond_false;
1250 } else if (tmp != 1) {
1251 goto do_default;
1252 }
1253 do_brcond_low:
1254 reset_all_temps(nb_temps);
1255 op->opc = INDEX_op_brcond_i32;
1256 args[1] = args[2];
1257 args[2] = args[4];
1258 args[3] = args[5];
1259 } else if (args[4] == TCG_COND_NE) {
1260 /* Simplify NE comparisons where one of the pairs
1261 can be simplified. */
1262 tmp = do_constant_folding_cond(INDEX_op_brcond_i32,
1263 args[0], args[2], TCG_COND_NE);
1264 if (tmp == 0) {
1265 goto do_brcond_high;
1266 } else if (tmp == 1) {
1267 goto do_brcond_true;
1268 }
1269 tmp = do_constant_folding_cond(INDEX_op_brcond_i32,
1270 args[1], args[3], TCG_COND_NE);
1271 if (tmp == 0) {
1272 goto do_brcond_low;
1273 } else if (tmp == 1) {
1274 goto do_brcond_true;
1275 }
1276 goto do_default;
1277 } else {
1278 goto do_default;
1279 }
1280 break;
1281
1282 case INDEX_op_setcond2_i32:
1283 tmp = do_constant_folding_cond2(&args[1], &args[3], args[5]);
1284 if (tmp != 2) {
1285 do_setcond_const:
1286 tcg_opt_gen_movi(s, op, args, args[0], tmp);
1287 } else if ((args[5] == TCG_COND_LT || args[5] == TCG_COND_GE)
1288 && temp_is_const(args[3]) && temps[args[3]].val == 0
1289 && temp_is_const(args[4]) && temps[args[4]].val == 0) {
1290 /* Simplify LT/GE comparisons vs zero to a single compare
1291 vs the high word of the input. */
1292 do_setcond_high:
1293 reset_temp(args[0]);
1294 temps[args[0]].mask = 1;
1295 op->opc = INDEX_op_setcond_i32;
1296 args[1] = args[2];
1297 args[2] = args[4];
1298 args[3] = args[5];
1299 } else if (args[5] == TCG_COND_EQ) {
1300 /* Simplify EQ comparisons where one of the pairs
1301 can be simplified. */
1302 tmp = do_constant_folding_cond(INDEX_op_setcond_i32,
1303 args[1], args[3], TCG_COND_EQ);
1304 if (tmp == 0) {
1305 goto do_setcond_const;
1306 } else if (tmp == 1) {
1307 goto do_setcond_high;
1308 }
1309 tmp = do_constant_folding_cond(INDEX_op_setcond_i32,
1310 args[2], args[4], TCG_COND_EQ);
1311 if (tmp == 0) {
1312 goto do_setcond_high;
1313 } else if (tmp != 1) {
1314 goto do_default;
1315 }
1316 do_setcond_low:
1317 reset_temp(args[0]);
1318 temps[args[0]].mask = 1;
1319 op->opc = INDEX_op_setcond_i32;
1320 args[2] = args[3];
1321 args[3] = args[5];
1322 } else if (args[5] == TCG_COND_NE) {
1323 /* Simplify NE comparisons where one of the pairs
1324 can be simplified. */
1325 tmp = do_constant_folding_cond(INDEX_op_setcond_i32,
1326 args[1], args[3], TCG_COND_NE);
1327 if (tmp == 0) {
1328 goto do_setcond_high;
1329 } else if (tmp == 1) {
1330 goto do_setcond_const;
1331 }
1332 tmp = do_constant_folding_cond(INDEX_op_setcond_i32,
1333 args[2], args[4], TCG_COND_NE);
1334 if (tmp == 0) {
1335 goto do_setcond_low;
1336 } else if (tmp == 1) {
1337 goto do_setcond_const;
1338 }
1339 goto do_default;
1340 } else {
1341 goto do_default;
1342 }
1343 break;
1344
1345 case INDEX_op_call:
1346 if (!(args[nb_oargs + nb_iargs + 1]
1347 & (TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_WRITE_GLOBALS))) {
1348 for (i = 0; i < nb_globals; i++) {
1349 if (test_bit(i, temps_used.l)) {
1350 reset_temp(i);
1351 }
1352 }
1353 }
1354 goto do_reset_output;
1355
1356 default:
1357 do_default:
1358 /* Default case: we know nothing about operation (or were unable
1359 to compute the operation result) so no propagation is done.
1360 We trash everything if the operation is the end of a basic
1361 block, otherwise we only trash the output args. "mask" is
1362 the non-zero bits mask for the first output arg. */
1363 if (def->flags & TCG_OPF_BB_END) {
1364 reset_all_temps(nb_temps);
1365 } else {
1366 do_reset_output:
1367 for (i = 0; i < nb_oargs; i++) {
1368 reset_temp(args[i]);
1369 /* Save the corresponding known-zero bits mask for the
1370 first output argument (only one supported so far). */
1371 if (i == 0) {
1372 temps[args[i]].mask = mask;
1373 }
1374 }
1375 }
1376 break;
1377 }
1378
1379 /* Eliminate duplicate and redundant fence instructions. */
1380 if (prev_mb_args) {
1381 switch (opc) {
1382 case INDEX_op_mb:
1383 /* Merge two barriers of the same type into one,
1384 * or a weaker barrier into a stronger one,
1385 * or two weaker barriers into a stronger one.
1386 * mb X; mb Y => mb X|Y
1387 * mb; strl => mb; st
1388 * ldaq; mb => ld; mb
1389 * ldaq; strl => ld; mb; st
1390 * Other combinations are also merged into a strong
1391 * barrier. This is stricter than specified but for
1392 * the purposes of TCG is better than not optimizing.
1393 */
1394 prev_mb_args[0] |= args[0];
1395 tcg_op_remove(s, op);
1396 break;
1397
1398 default:
1399 /* Opcodes that end the block stop the optimization. */
1400 if ((def->flags & TCG_OPF_BB_END) == 0) {
1401 break;
1402 }
1403 /* fallthru */
1404 case INDEX_op_qemu_ld_i32:
1405 case INDEX_op_qemu_ld_i64:
1406 case INDEX_op_qemu_st_i32:
1407 case INDEX_op_qemu_st_i64:
1408 case INDEX_op_call:
1409 /* Opcodes that touch guest memory stop the optimization. */
1410 prev_mb_args = NULL;
1411 break;
1412 }
1413 } else if (opc == INDEX_op_mb) {
1414 prev_mb_args = args;
1415 }
1416 }
1417 }