remove 'Escape' from token character class
[smatch.git] / simplify.c
blobf62fc83a109a2067d4e0541867e8ccf55266d8cc
1 /*
2 * Simplify - do instruction simplification before CSE
4 * Copyright (C) 2004 Linus Torvalds
5 */
7 #include <assert.h>
9 #include "parse.h"
10 #include "expression.h"
11 #include "linearize.h"
12 #include "flow.h"
13 #include "symbol.h"
15 /* Find the trivial parent for a phi-source */
16 static struct basic_block *phi_parent(struct basic_block *source, pseudo_t pseudo)
18 /* Can't go upwards if the pseudo is defined in the bb it came from.. */
19 if (pseudo->type == PSEUDO_REG) {
20 struct instruction *def = pseudo->def;
21 if (def->bb == source)
22 return source;
24 if (bb_list_size(source->children) != 1 || bb_list_size(source->parents) != 1)
25 return source;
26 return first_basic_block(source->parents);
29 static void clear_phi(struct instruction *insn)
31 pseudo_t phi;
33 insn->bb = NULL;
34 FOR_EACH_PTR(insn->phi_list, phi) {
35 *THIS_ADDRESS(phi) = VOID;
36 } END_FOR_EACH_PTR(phi);
39 static int if_convert_phi(struct instruction *insn)
41 pseudo_t array[3];
42 struct basic_block *parents[3];
43 struct basic_block *bb, *bb1, *bb2, *source;
44 struct instruction *br;
45 pseudo_t p1, p2;
47 bb = insn->bb;
48 if (linearize_ptr_list((struct ptr_list *)insn->phi_list, (void **)array, 3) != 2)
49 return 0;
50 if (linearize_ptr_list((struct ptr_list *)bb->parents, (void **)parents, 3) != 2)
51 return 0;
52 p1 = array[0]->def->src1;
53 bb1 = array[0]->def->bb;
54 p2 = array[1]->def->src1;
55 bb2 = array[1]->def->bb;
57 /* Only try the simple "direct parents" case */
58 if ((bb1 != parents[0] || bb2 != parents[1]) &&
59 (bb1 != parents[1] || bb2 != parents[0]))
60 return 0;
63 * See if we can find a common source for this..
65 source = phi_parent(bb1, p1);
66 if (source != phi_parent(bb2, p2))
67 return 0;
70 * Cool. We now know that 'source' is the exclusive
71 * parent of both phi-nodes, so the exit at the
72 * end of it fully determines which one it is, and
73 * we can turn it into a select.
75 * HOWEVER, right now we only handle regular
76 * conditional branches. No multijumps or computed
77 * stuff. Verify that here.
79 br = last_instruction(source->insns);
80 if (!br || br->opcode != OP_BR)
81 return 0;
83 assert(br->cond);
84 assert(br->bb_false);
87 * We're in business. Match up true/false with p1/p2.
89 if (br->bb_true == bb2 || br->bb_false == bb1) {
90 pseudo_t p = p1;
91 p1 = p2;
92 p2 = p;
96 * OK, we can now replace that last
98 * br cond, a, b
100 * with the sequence
102 * setcc cond
103 * select pseudo, p1, p2
104 * br cond, a, b
106 * and remove the phi-node. If it then
107 * turns out that 'a' or 'b' is entirely
108 * empty (common case), and now no longer
109 * a phi-source, we'll be able to simplify
110 * the conditional branch too.
112 insert_select(source, br, insn, p1, p2);
113 clear_phi(insn);
114 return REPEAT_CSE;
117 static int clean_up_phi(struct instruction *insn)
119 pseudo_t phi;
120 struct instruction *last;
121 int same;
123 last = NULL;
124 same = 1;
125 FOR_EACH_PTR(insn->phi_list, phi) {
126 struct instruction *def;
127 if (phi == VOID)
128 continue;
129 def = phi->def;
130 if (def->src1 == VOID || !def->bb)
131 continue;
132 if (last) {
133 if (last->src1 != def->src1)
134 same = 0;
135 continue;
137 last = def;
138 } END_FOR_EACH_PTR(phi);
140 if (same) {
141 pseudo_t pseudo = last ? last->src1 : VOID;
142 convert_instruction_target(insn, pseudo);
143 clear_phi(insn);
144 return REPEAT_CSE;
147 return if_convert_phi(insn);
150 static int delete_pseudo_user_list_entry(struct pseudo_user_list **list, pseudo_t *entry, int count)
152 struct pseudo_user *pu;
154 FOR_EACH_PTR(*list, pu) {
155 if (pu->userp == entry) {
156 DELETE_CURRENT_PTR(pu);
157 if (!--count)
158 goto out;
160 } END_FOR_EACH_PTR(pu);
161 assert(count <= 0);
162 out:
163 pack_ptr_list((struct ptr_list **)list);
164 return count;
167 static inline void remove_usage(pseudo_t p, pseudo_t *usep)
169 if (has_use_list(p)) {
170 delete_pseudo_user_list_entry(&p->users, usep, 1);
171 if (!p->users)
172 kill_instruction(p->def);
176 void kill_use(pseudo_t *usep)
178 if (usep) {
179 pseudo_t p = *usep;
180 *usep = VOID;
181 remove_usage(p, usep);
185 void kill_instruction(struct instruction *insn)
187 if (!insn || !insn->bb)
188 return;
190 switch (insn->opcode) {
191 case OP_SEL:
192 case OP_RANGE:
193 kill_use(&insn->src3);
194 /* fall through */
196 case OP_BINARY ... OP_BINCMP_END:
197 kill_use(&insn->src2);
198 /* fall through */
200 case OP_CAST:
201 case OP_SCAST:
202 case OP_FPCAST:
203 case OP_PTRCAST:
204 case OP_NOT: case OP_NEG:
205 kill_use(&insn->src1);
206 break;
208 case OP_PHI:
209 clear_phi(insn);
210 break;
212 case OP_SYMADDR:
213 repeat_phase |= REPEAT_SYMBOL_CLEANUP;
214 break;
216 case OP_BR:
217 if (!insn->bb_true || !insn->bb_false)
218 break;
219 /* fall through */
221 case OP_COMPUTEDGOTO:
222 kill_use(&insn->cond);
223 break;
225 case OP_ENTRY:
226 default:
227 /* ignore */
228 return;
231 insn->bb = NULL;
232 repeat_phase |= REPEAT_CSE;
233 return;
237 * Kill trivially dead instructions
239 static int dead_insn(struct instruction *insn, pseudo_t *src1, pseudo_t *src2, pseudo_t *src3)
241 struct pseudo_user *pu;
242 FOR_EACH_PTR(insn->target->users, pu) {
243 if (*pu->userp != VOID)
244 return 0;
245 } END_FOR_EACH_PTR(pu);
247 insn->bb = NULL;
248 kill_use(src1);
249 kill_use(src2);
250 kill_use(src3);
251 return REPEAT_CSE;
254 static inline int constant(pseudo_t pseudo)
256 return pseudo->type == PSEUDO_VAL;
259 static int replace_with_pseudo(struct instruction *insn, pseudo_t pseudo)
261 convert_instruction_target(insn, pseudo);
263 switch (insn->opcode) {
264 case OP_SEL:
265 case OP_RANGE:
266 kill_use(&insn->src3);
267 case OP_BINARY ... OP_BINCMP_END:
268 kill_use(&insn->src2);
269 case OP_NOT:
270 case OP_NEG:
271 case OP_SYMADDR:
272 case OP_CAST:
273 case OP_SCAST:
274 case OP_FPCAST:
275 case OP_PTRCAST:
276 kill_use(&insn->src1);
277 break;
279 default:
280 assert(0);
282 insn->bb = NULL;
283 return REPEAT_CSE;
286 static unsigned int value_size(long long value)
288 value >>= 8;
289 if (!value)
290 return 8;
291 value >>= 8;
292 if (!value)
293 return 16;
294 value >>= 16;
295 if (!value)
296 return 32;
297 return 64;
301 * Try to determine the maximum size of bits in a pseudo.
303 * Right now this only follow casts and constant values, but we
304 * could look at things like logical 'and' instructions etc.
306 static unsigned int operand_size(struct instruction *insn, pseudo_t pseudo)
308 unsigned int size = insn->size;
310 if (pseudo->type == PSEUDO_REG) {
311 struct instruction *src = pseudo->def;
312 if (src && src->opcode == OP_CAST && src->orig_type) {
313 unsigned int orig_size = src->orig_type->bit_size;
314 if (orig_size < size)
315 size = orig_size;
318 if (pseudo->type == PSEUDO_VAL) {
319 unsigned int orig_size = value_size(pseudo->value);
320 if (orig_size < size)
321 size = orig_size;
323 return size;
326 static int simplify_asr(struct instruction *insn, pseudo_t pseudo, long long value)
328 unsigned int size = operand_size(insn, pseudo);
330 if (value >= size) {
331 warning(insn->pos, "right shift by bigger than source value");
332 return replace_with_pseudo(insn, value_pseudo(0));
334 if (!value)
335 return replace_with_pseudo(insn, pseudo);
336 return 0;
339 static int simplify_constant_rightside(struct instruction *insn)
341 long long value = insn->src2->value;
343 switch (insn->opcode) {
344 case OP_SUB:
345 if (value) {
346 insn->opcode = OP_ADD;
347 insn->src2 = value_pseudo(-value);
348 return REPEAT_CSE;
350 /* Fall through */
351 case OP_ADD:
352 case OP_OR: case OP_XOR:
353 case OP_OR_BOOL:
354 case OP_SHL:
355 case OP_LSR:
356 if (!value)
357 return replace_with_pseudo(insn, insn->src1);
358 return 0;
359 case OP_ASR:
360 return simplify_asr(insn, insn->src1, value);
362 case OP_MULU: case OP_MULS:
363 case OP_AND_BOOL:
364 if (value == 1)
365 return replace_with_pseudo(insn, insn->src1);
366 /* Fall through */
367 case OP_AND:
368 if (!value)
369 return replace_with_pseudo(insn, insn->src2);
370 return 0;
372 return 0;
375 static int simplify_constant_leftside(struct instruction *insn)
377 long long value = insn->src1->value;
379 switch (insn->opcode) {
380 case OP_ADD: case OP_OR: case OP_XOR:
381 if (!value)
382 return replace_with_pseudo(insn, insn->src2);
383 return 0;
385 case OP_SHL:
386 case OP_LSR: case OP_ASR:
387 case OP_AND:
388 case OP_MULU: case OP_MULS:
389 if (!value)
390 return replace_with_pseudo(insn, insn->src1);
391 return 0;
393 return 0;
396 static int simplify_constant_binop(struct instruction *insn)
398 /* FIXME! Verify signs and sizes!! */
399 long long left = insn->src1->value;
400 long long right = insn->src2->value;
401 unsigned long long ul, ur;
402 long long res, mask, bits;
404 mask = 1ULL << (insn->size-1);
405 bits = mask | (mask-1);
407 if (left & mask)
408 left |= ~bits;
409 if (right & mask)
410 right |= ~bits;
411 ul = left & bits;
412 ur = right & bits;
414 switch (insn->opcode) {
415 case OP_ADD:
416 res = left + right;
417 break;
418 case OP_SUB:
419 res = left - right;
420 break;
421 case OP_MULU:
422 res = ul * ur;
423 break;
424 case OP_MULS:
425 res = left * right;
426 break;
427 case OP_DIVU:
428 if (!ur)
429 return 0;
430 res = ul / ur;
431 break;
432 case OP_DIVS:
433 if (!right)
434 return 0;
435 if (left == mask && right == -1)
436 return 0;
437 res = left / right;
438 break;
439 case OP_MODU:
440 if (!ur)
441 return 0;
442 res = ul % ur;
443 break;
444 case OP_MODS:
445 if (!right)
446 return 0;
447 if (left == mask && right == -1)
448 return 0;
449 res = left % right;
450 break;
451 case OP_SHL:
452 res = left << right;
453 break;
454 case OP_LSR:
455 res = ul >> ur;
456 break;
457 case OP_ASR:
458 res = left >> right;
459 break;
460 /* Logical */
461 case OP_AND:
462 res = left & right;
463 break;
464 case OP_OR:
465 res = left | right;
466 break;
467 case OP_XOR:
468 res = left ^ right;
469 break;
470 case OP_AND_BOOL:
471 res = left && right;
472 break;
473 case OP_OR_BOOL:
474 res = left || right;
475 break;
477 /* Binary comparison */
478 case OP_SET_EQ:
479 res = left == right;
480 break;
481 case OP_SET_NE:
482 res = left != right;
483 break;
484 case OP_SET_LE:
485 res = left <= right;
486 break;
487 case OP_SET_GE:
488 res = left >= right;
489 break;
490 case OP_SET_LT:
491 res = left < right;
492 break;
493 case OP_SET_GT:
494 res = left > right;
495 break;
496 case OP_SET_B:
497 res = ul < ur;
498 break;
499 case OP_SET_A:
500 res = ul > ur;
501 break;
502 case OP_SET_BE:
503 res = ul <= ur;
504 break;
505 case OP_SET_AE:
506 res = ul >= ur;
507 break;
508 default:
509 return 0;
511 res &= bits;
513 replace_with_pseudo(insn, value_pseudo(res));
514 return REPEAT_CSE;
517 static int simplify_binop(struct instruction *insn)
519 if (dead_insn(insn, &insn->src1, &insn->src2, NULL))
520 return REPEAT_CSE;
521 if (constant(insn->src1)) {
522 if (constant(insn->src2))
523 return simplify_constant_binop(insn);
524 return simplify_constant_leftside(insn);
526 if (constant(insn->src2))
527 return simplify_constant_rightside(insn);
528 return 0;
531 static void switch_pseudo(struct instruction *insn1, pseudo_t *pp1, struct instruction *insn2, pseudo_t *pp2)
533 pseudo_t p1 = *pp1, p2 = *pp2;
535 use_pseudo(insn1, p2, pp1);
536 use_pseudo(insn2, p1, pp2);
537 remove_usage(p1, pp1);
538 remove_usage(p2, pp2);
541 static int canonical_order(pseudo_t p1, pseudo_t p2)
543 /* symbol/constants on the right */
544 if (p1->type == PSEUDO_VAL)
545 return p2->type == PSEUDO_VAL;
547 if (p1->type == PSEUDO_SYM)
548 return p2->type == PSEUDO_SYM || p2->type == PSEUDO_VAL;
550 return 1;
553 static int simplify_commutative_binop(struct instruction *insn)
555 if (!canonical_order(insn->src1, insn->src2)) {
556 switch_pseudo(insn, &insn->src1, insn, &insn->src2);
557 return REPEAT_CSE;
559 return 0;
562 static inline int simple_pseudo(pseudo_t pseudo)
564 return pseudo->type == PSEUDO_VAL || pseudo->type == PSEUDO_SYM;
567 static int simplify_associative_binop(struct instruction *insn)
569 struct instruction *def;
570 pseudo_t pseudo = insn->src1;
572 if (!simple_pseudo(insn->src2))
573 return 0;
574 if (pseudo->type != PSEUDO_REG)
575 return 0;
576 def = pseudo->def;
577 if (def == insn)
578 return 0;
579 if (def->opcode != insn->opcode)
580 return 0;
581 if (!simple_pseudo(def->src2))
582 return 0;
583 if (ptr_list_size((struct ptr_list *)def->target->users) != 1)
584 return 0;
585 switch_pseudo(def, &def->src1, insn, &insn->src2);
586 return REPEAT_CSE;
589 static int simplify_constant_unop(struct instruction *insn)
591 long long val = insn->src1->value;
592 long long res, mask;
594 switch (insn->opcode) {
595 case OP_NOT:
596 res = ~val;
597 break;
598 case OP_NEG:
599 res = -val;
600 break;
601 default:
602 return 0;
604 mask = 1ULL << (insn->size-1);
605 res &= mask | (mask-1);
607 replace_with_pseudo(insn, value_pseudo(res));
608 return REPEAT_CSE;
611 static int simplify_unop(struct instruction *insn)
613 if (dead_insn(insn, &insn->src1, NULL, NULL))
614 return REPEAT_CSE;
615 if (constant(insn->src1))
616 return simplify_constant_unop(insn);
617 return 0;
620 static int simplify_one_memop(struct instruction *insn, pseudo_t orig)
622 pseudo_t addr = insn->src;
623 pseudo_t new, off;
625 if (addr->type == PSEUDO_REG) {
626 struct instruction *def = addr->def;
627 if (def->opcode == OP_SYMADDR && def->src) {
628 kill_use(&insn->src);
629 use_pseudo(insn, def->src, &insn->src);
630 return REPEAT_CSE | REPEAT_SYMBOL_CLEANUP;
632 if (def->opcode == OP_ADD) {
633 new = def->src1;
634 off = def->src2;
635 if (constant(off))
636 goto offset;
637 new = off;
638 off = def->src1;
639 if (constant(off))
640 goto offset;
641 return 0;
644 return 0;
646 offset:
647 /* Invalid code */
648 if (new == orig) {
649 if (new == VOID)
650 return 0;
651 new = VOID;
652 warning(insn->pos, "crazy programmer");
654 insn->offset += off->value;
655 use_pseudo(insn, new, &insn->src);
656 remove_usage(addr, &insn->src);
657 return REPEAT_CSE | REPEAT_SYMBOL_CLEANUP;
661 * We walk the whole chain of adds/subs backwards. That's not
662 * only more efficient, but it allows us to find loops.
664 static int simplify_memop(struct instruction *insn)
666 int one, ret = 0;
667 pseudo_t orig = insn->src;
669 do {
670 one = simplify_one_memop(insn, orig);
671 ret |= one;
672 } while (one);
673 return ret;
676 static long long get_cast_value(long long val, int old_size, int new_size, int sign)
678 long long mask;
680 if (sign && new_size > old_size) {
681 mask = 1 << (old_size-1);
682 if (val & mask)
683 val |= ~(mask | (mask-1));
685 mask = 1 << (new_size-1);
686 return val & (mask | (mask-1));
689 static int simplify_cast(struct instruction *insn)
691 struct symbol *orig_type;
692 int orig_size, size;
693 pseudo_t src;
695 if (dead_insn(insn, &insn->src, NULL, NULL))
696 return REPEAT_CSE;
698 orig_type = insn->orig_type;
699 if (!orig_type)
700 return 0;
702 /* Keep casts with pointer on either side (not only case of OP_PTRCAST) */
703 if (is_ptr_type(orig_type) || is_ptr_type(insn->type))
704 return 0;
706 orig_size = orig_type->bit_size;
707 size = insn->size;
708 src = insn->src;
710 /* A cast of a constant? */
711 if (constant(src)) {
712 int sign = orig_type->ctype.modifiers & MOD_SIGNED;
713 long long val = get_cast_value(src->value, orig_size, size, sign);
714 src = value_pseudo(val);
715 goto simplify;
718 /* A cast of a "and" might be a no-op.. */
719 if (src->type == PSEUDO_REG) {
720 struct instruction *def = src->def;
721 if (def->opcode == OP_AND && def->size >= size) {
722 pseudo_t val = def->src2;
723 if (val->type == PSEUDO_VAL) {
724 unsigned long long value = val->value;
725 if (!(value >> (size-1)))
726 goto simplify;
731 if (size == orig_size) {
732 int op = (orig_type->ctype.modifiers & MOD_SIGNED) ? OP_SCAST : OP_CAST;
733 if (insn->opcode == op)
734 goto simplify;
737 return 0;
739 simplify:
740 return replace_with_pseudo(insn, src);
743 static int simplify_select(struct instruction *insn)
745 pseudo_t cond, src1, src2;
747 if (dead_insn(insn, &insn->src1, &insn->src2, &insn->src3))
748 return REPEAT_CSE;
750 cond = insn->src1;
751 src1 = insn->src2;
752 src2 = insn->src3;
753 if (constant(cond) || src1 == src2) {
754 pseudo_t *kill, take;
755 kill_use(&insn->src1);
756 take = cond->value ? src1 : src2;
757 kill = cond->value ? &insn->src3 : &insn->src2;
758 kill_use(kill);
759 replace_with_pseudo(insn, take);
760 return REPEAT_CSE;
762 if (constant(src1) && constant(src2)) {
763 long long val1 = src1->value;
764 long long val2 = src2->value;
766 /* The pair 0/1 is special - replace with SETNE/SETEQ */
767 if ((val1 | val2) == 1) {
768 int opcode = OP_SET_EQ;
769 if (val1) {
770 src1 = src2;
771 opcode = OP_SET_NE;
773 insn->opcode = opcode;
774 /* insn->src1 is already cond */
775 insn->src2 = src1; /* Zero */
776 return REPEAT_CSE;
779 return 0;
782 static int is_in_range(pseudo_t src, long long low, long long high)
784 long long value;
786 switch (src->type) {
787 case PSEUDO_VAL:
788 value = src->value;
789 return value >= low && value <= high;
790 default:
791 return 0;
795 static int simplify_range(struct instruction *insn)
797 pseudo_t src1, src2, src3;
799 src1 = insn->src1;
800 src2 = insn->src2;
801 src3 = insn->src3;
802 if (src2->type != PSEUDO_VAL || src3->type != PSEUDO_VAL)
803 return 0;
804 if (is_in_range(src1, src2->value, src3->value)) {
805 kill_instruction(insn);
806 return REPEAT_CSE;
808 return 0;
812 * Simplify "set_ne/eq $0 + br"
814 static int simplify_cond_branch(struct instruction *br, pseudo_t cond, struct instruction *def, pseudo_t *pp)
816 use_pseudo(br, *pp, &br->cond);
817 remove_usage(cond, &br->cond);
818 if (def->opcode == OP_SET_EQ) {
819 struct basic_block *true = br->bb_true;
820 struct basic_block *false = br->bb_false;
821 br->bb_false = true;
822 br->bb_true = false;
824 return REPEAT_CSE;
827 static int simplify_branch(struct instruction *insn)
829 pseudo_t cond = insn->cond;
831 if (!cond)
832 return 0;
834 /* Constant conditional */
835 if (constant(cond)) {
836 insert_branch(insn->bb, insn, cond->value ? insn->bb_true : insn->bb_false);
837 return REPEAT_CSE;
840 /* Same target? */
841 if (insn->bb_true == insn->bb_false) {
842 struct basic_block *bb = insn->bb;
843 struct basic_block *target = insn->bb_false;
844 remove_bb_from_list(&target->parents, bb, 1);
845 remove_bb_from_list(&bb->children, target, 1);
846 insn->bb_false = NULL;
847 kill_use(&insn->cond);
848 insn->cond = NULL;
849 return REPEAT_CSE;
852 /* Conditional on a SETNE $0 or SETEQ $0 */
853 if (cond->type == PSEUDO_REG) {
854 struct instruction *def = cond->def;
856 if (def->opcode == OP_SET_NE || def->opcode == OP_SET_EQ) {
857 if (constant(def->src1) && !def->src1->value)
858 return simplify_cond_branch(insn, cond, def, &def->src2);
859 if (constant(def->src2) && !def->src2->value)
860 return simplify_cond_branch(insn, cond, def, &def->src1);
862 if (def->opcode == OP_SEL) {
863 if (constant(def->src2) && constant(def->src3)) {
864 long long val1 = def->src2->value;
865 long long val2 = def->src3->value;
866 if (!val1 && !val2) {
867 insert_branch(insn->bb, insn, insn->bb_false);
868 return REPEAT_CSE;
870 if (val1 && val2) {
871 insert_branch(insn->bb, insn, insn->bb_true);
872 return REPEAT_CSE;
874 if (val2) {
875 struct basic_block *true = insn->bb_true;
876 struct basic_block *false = insn->bb_false;
877 insn->bb_false = true;
878 insn->bb_true = false;
880 use_pseudo(insn, def->src1, &insn->cond);
881 remove_usage(cond, &insn->cond);
882 return REPEAT_CSE;
885 if (def->opcode == OP_CAST || def->opcode == OP_SCAST) {
886 int orig_size = def->orig_type ? def->orig_type->bit_size : 0;
887 if (def->size > orig_size) {
888 use_pseudo(insn, def->src, &insn->cond);
889 remove_usage(cond, &insn->cond);
890 return REPEAT_CSE;
894 return 0;
897 static int simplify_switch(struct instruction *insn)
899 pseudo_t cond = insn->cond;
900 long long val;
901 struct multijmp *jmp;
903 if (!constant(cond))
904 return 0;
905 val = insn->cond->value;
907 FOR_EACH_PTR(insn->multijmp_list, jmp) {
908 /* Default case */
909 if (jmp->begin > jmp->end)
910 goto found;
911 if (val >= jmp->begin && val <= jmp->end)
912 goto found;
913 } END_FOR_EACH_PTR(jmp);
914 warning(insn->pos, "Impossible case statement");
915 return 0;
917 found:
918 insert_branch(insn->bb, insn, jmp->target);
919 return REPEAT_CSE;
922 int simplify_instruction(struct instruction *insn)
924 if (!insn->bb)
925 return 0;
926 switch (insn->opcode) {
927 case OP_ADD: case OP_MULS:
928 case OP_AND: case OP_OR: case OP_XOR:
929 case OP_AND_BOOL: case OP_OR_BOOL:
930 if (simplify_binop(insn))
931 return REPEAT_CSE;
932 if (simplify_commutative_binop(insn))
933 return REPEAT_CSE;
934 return simplify_associative_binop(insn);
936 case OP_MULU:
937 case OP_SET_EQ: case OP_SET_NE:
938 if (simplify_binop(insn))
939 return REPEAT_CSE;
940 return simplify_commutative_binop(insn);
942 case OP_SUB:
943 case OP_DIVU: case OP_DIVS:
944 case OP_MODU: case OP_MODS:
945 case OP_SHL:
946 case OP_LSR: case OP_ASR:
947 case OP_SET_LE: case OP_SET_GE:
948 case OP_SET_LT: case OP_SET_GT:
949 case OP_SET_B: case OP_SET_A:
950 case OP_SET_BE: case OP_SET_AE:
951 return simplify_binop(insn);
953 case OP_NOT: case OP_NEG:
954 return simplify_unop(insn);
955 case OP_LOAD: case OP_STORE:
956 return simplify_memop(insn);
957 case OP_SYMADDR:
958 if (dead_insn(insn, NULL, NULL, NULL))
959 return REPEAT_CSE | REPEAT_SYMBOL_CLEANUP;
960 return replace_with_pseudo(insn, insn->symbol);
961 case OP_CAST:
962 case OP_SCAST:
963 case OP_FPCAST:
964 case OP_PTRCAST:
965 return simplify_cast(insn);
966 case OP_PHI:
967 if (dead_insn(insn, NULL, NULL, NULL)) {
968 clear_phi(insn);
969 return REPEAT_CSE;
971 return clean_up_phi(insn);
972 case OP_PHISOURCE:
973 if (dead_insn(insn, &insn->phi_src, NULL, NULL))
974 return REPEAT_CSE;
975 break;
976 case OP_SEL:
977 return simplify_select(insn);
978 case OP_BR:
979 return simplify_branch(insn);
980 case OP_SWITCH:
981 return simplify_switch(insn);
982 case OP_RANGE:
983 return simplify_range(insn);
985 return 0;