2 * Simplify - do instruction simplification before CSE
4 * Copyright (C) 2004 Linus Torvalds
10 #include "expression.h"
11 #include "linearize.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
)
24 if (bb_list_size(source
->children
) != 1 || bb_list_size(source
->parents
) != 1)
26 return first_basic_block(source
->parents
);
30 * Copy the phi-node's phisrcs into to given array.
31 * Returns 0 if the the list contained the expected
32 * number of element, a positive number if there was
33 * more than expected and a negative one if less.
35 * Note: we can't reuse a function like linearize_ptr_list()
36 * because any VOIDs in the phi-list must be ignored here
37 * as in this context they mean 'entry has been removed'.
39 static int get_phisources(struct instruction
*sources
[], int nbr
, struct instruction
*insn
)
44 assert(insn
->opcode
== OP_PHI
);
45 FOR_EACH_PTR(insn
->phi_list
, phi
) {
46 struct instruction
*def
;
52 assert(def
->opcode
== OP_PHISOURCE
);
54 } END_FOR_EACH_PTR(phi
);
58 static int if_convert_phi(struct instruction
*insn
)
60 struct instruction
*array
[2];
61 struct basic_block
*parents
[3];
62 struct basic_block
*bb
, *bb1
, *bb2
, *source
;
63 struct instruction
*br
;
67 if (get_phisources(array
, 2, insn
))
69 if (linearize_ptr_list((struct ptr_list
*)bb
->parents
, (void **)parents
, 3) != 2)
76 /* Only try the simple "direct parents" case */
77 if ((bb1
!= parents
[0] || bb2
!= parents
[1]) &&
78 (bb1
!= parents
[1] || bb2
!= parents
[0]))
82 * See if we can find a common source for this..
84 source
= phi_parent(bb1
, p1
);
85 if (source
!= phi_parent(bb2
, p2
))
89 * Cool. We now know that 'source' is the exclusive
90 * parent of both phi-nodes, so the exit at the
91 * end of it fully determines which one it is, and
92 * we can turn it into a select.
94 * HOWEVER, right now we only handle regular
95 * conditional branches. No multijumps or computed
96 * stuff. Verify that here.
98 br
= last_instruction(source
->insns
);
99 if (!br
|| br
->opcode
!= OP_CBR
)
103 assert(br
->bb_false
);
106 * We're in business. Match up true/false with p1/p2.
108 if (br
->bb_true
== bb2
|| br
->bb_false
== bb1
) {
115 * OK, we can now replace that last
122 * select pseudo, p1, p2
125 * and remove the phi-node. If it then
126 * turns out that 'a' or 'b' is entirely
127 * empty (common case), and now no longer
128 * a phi-source, we'll be able to simplify
129 * the conditional branch too.
131 insert_select(source
, br
, insn
, p1
, p2
);
132 kill_instruction(insn
);
136 static int clean_up_phi(struct instruction
*insn
)
139 struct instruction
*last
;
144 FOR_EACH_PTR(insn
->phi_list
, phi
) {
145 struct instruction
*def
;
149 if (def
->src1
== VOID
|| !def
->bb
)
152 if (last
->src1
!= def
->src1
)
157 } END_FOR_EACH_PTR(phi
);
160 pseudo_t pseudo
= last
? last
->src1
: VOID
;
161 convert_instruction_target(insn
, pseudo
);
162 kill_instruction(insn
);
166 return if_convert_phi(insn
);
169 static int delete_pseudo_user_list_entry(struct pseudo_user_list
**list
, pseudo_t
*entry
, int count
)
171 struct pseudo_user
*pu
;
173 FOR_EACH_PTR(*list
, pu
) {
174 if (pu
->userp
== entry
) {
175 DELETE_CURRENT_PTR(pu
);
179 } END_FOR_EACH_PTR(pu
);
182 pack_ptr_list((struct ptr_list
**)list
);
186 static inline void remove_usage(pseudo_t p
, pseudo_t
*usep
)
188 if (has_use_list(p
)) {
189 delete_pseudo_user_list_entry(&p
->users
, usep
, 1);
191 kill_instruction(p
->def
);
195 void kill_use(pseudo_t
*usep
)
200 remove_usage(p
, usep
);
204 static void kill_use_list(struct pseudo_list
*list
)
207 FOR_EACH_PTR(list
, p
) {
210 kill_use(THIS_ADDRESS(p
));
211 } END_FOR_EACH_PTR(p
);
215 * kill an instruction:
216 * - remove it from its bb
217 * - remove the usage of all its operands
218 * If forse is zero, the normal case, the function only for
219 * instructions free of (possible) side-effects. Otherwise
220 * the function does that unconditionally (must only be used
221 * for unreachable instructions.
223 void kill_insn(struct instruction
*insn
, int force
)
225 if (!insn
|| !insn
->bb
)
228 switch (insn
->opcode
) {
231 kill_use(&insn
->src3
);
234 case OP_BINARY
... OP_BINCMP_END
:
235 kill_use(&insn
->src2
);
243 case OP_NOT
: case OP_NEG
:
245 kill_use(&insn
->src1
);
249 kill_use_list(insn
->phi_list
);
252 kill_use(&insn
->phi_src
);
256 repeat_phase
|= REPEAT_SYMBOL_CLEANUP
;
260 case OP_COMPUTEDGOTO
:
261 kill_use(&insn
->cond
);
266 /* a "pure" function can be killed too */
267 if (!(insn
->func
->type
== PSEUDO_SYM
))
269 if (!(insn
->func
->sym
->ctype
.modifiers
& MOD_PURE
))
272 kill_use_list(insn
->arguments
);
273 if (insn
->func
->type
== PSEUDO_REG
)
274 kill_use(&insn
->func
);
278 if (!force
&& insn
->type
->ctype
.modifiers
& MOD_VOLATILE
)
280 kill_use(&insn
->src
);
286 kill_use(&insn
->src
);
287 kill_use(&insn
->target
);
300 repeat_phase
|= REPEAT_CSE
;
305 * Kill trivially dead instructions
307 static int dead_insn(struct instruction
*insn
, pseudo_t
*src1
, pseudo_t
*src2
, pseudo_t
*src3
)
309 struct pseudo_user
*pu
;
310 FOR_EACH_PTR(insn
->target
->users
, pu
) {
311 if (*pu
->userp
!= VOID
)
313 } END_FOR_EACH_PTR(pu
);
322 static inline int constant(pseudo_t pseudo
)
324 return pseudo
->type
== PSEUDO_VAL
;
327 static int replace_with_pseudo(struct instruction
*insn
, pseudo_t pseudo
)
329 convert_instruction_target(insn
, pseudo
);
331 switch (insn
->opcode
) {
334 kill_use(&insn
->src3
);
335 case OP_BINARY
... OP_BINCMP_END
:
336 kill_use(&insn
->src2
);
344 kill_use(&insn
->src1
);
354 static unsigned int value_size(long long value
)
369 * Try to determine the maximum size of bits in a pseudo.
371 * Right now this only follow casts and constant values, but we
372 * could look at things like logical 'and' instructions etc.
374 static unsigned int operand_size(struct instruction
*insn
, pseudo_t pseudo
)
376 unsigned int size
= insn
->size
;
378 if (pseudo
->type
== PSEUDO_REG
) {
379 struct instruction
*src
= pseudo
->def
;
380 if (src
&& src
->opcode
== OP_CAST
&& src
->orig_type
) {
381 unsigned int orig_size
= src
->orig_type
->bit_size
;
382 if (orig_size
< size
)
386 if (pseudo
->type
== PSEUDO_VAL
) {
387 unsigned int orig_size
= value_size(pseudo
->value
);
388 if (orig_size
< size
)
394 static int simplify_asr(struct instruction
*insn
, pseudo_t pseudo
, long long value
)
396 unsigned int size
= operand_size(insn
, pseudo
);
399 warning(insn
->pos
, "right shift by bigger than source value");
400 return replace_with_pseudo(insn
, value_pseudo(0));
403 return replace_with_pseudo(insn
, pseudo
);
407 static int simplify_mul_div(struct instruction
*insn
, long long value
)
409 unsigned long long sbit
= 1ULL << (insn
->size
- 1);
410 unsigned long long bits
= sbit
| (sbit
- 1);
413 return replace_with_pseudo(insn
, insn
->src1
);
415 switch (insn
->opcode
) {
419 return replace_with_pseudo(insn
, insn
->src2
);
422 if (!(value
& sbit
)) // positive
427 insn
->opcode
= OP_NEG
;
435 static int compare_opcode(int opcode
, int inverse
)
441 case OP_SET_EQ
: return OP_SET_NE
;
442 case OP_SET_NE
: return OP_SET_EQ
;
444 case OP_SET_LT
: return OP_SET_GE
;
445 case OP_SET_LE
: return OP_SET_GT
;
446 case OP_SET_GT
: return OP_SET_LE
;
447 case OP_SET_GE
: return OP_SET_LT
;
449 case OP_SET_A
: return OP_SET_BE
;
450 case OP_SET_AE
: return OP_SET_B
;
451 case OP_SET_B
: return OP_SET_AE
;
452 case OP_SET_BE
: return OP_SET_A
;
459 static int simplify_seteq_setne(struct instruction
*insn
, long long value
)
461 pseudo_t old
= insn
->src1
;
462 struct instruction
*def
= old
->def
;
467 if (value
!= 0 && value
!= 1)
473 inverse
= (insn
->opcode
== OP_SET_NE
) == value
;
474 opcode
= def
->opcode
;
476 case OP_BINCMP
... OP_BINCMP_END
:
478 // setcc.n %t <- %a, %b
479 // setne.m %r <- %t, $0
481 // setcc.n %t <- %a, %b
482 // setcc.m %r <- %a, $b
483 // and similar for setne/eq ... 0/1
486 insn
->opcode
= compare_opcode(opcode
, inverse
);
487 use_pseudo(insn
, src1
, &insn
->src1
);
488 use_pseudo(insn
, src2
, &insn
->src2
);
489 remove_usage(old
, &insn
->src1
);
497 static int simplify_constant_rightside(struct instruction
*insn
)
499 long long value
= insn
->src2
->value
;
501 switch (insn
->opcode
) {
504 return replace_with_pseudo(insn
, insn
->src2
);
505 goto case_neutral_zero
;
509 insn
->opcode
= OP_ADD
;
510 insn
->src2
= value_pseudo(-value
);
515 case OP_OR
: case OP_XOR
:
520 return replace_with_pseudo(insn
, insn
->src1
);
523 return simplify_asr(insn
, insn
->src1
, value
);
525 case OP_MODU
: case OP_MODS
:
527 return replace_with_pseudo(insn
, value_pseudo(0));
530 case OP_DIVU
: case OP_DIVS
:
531 case OP_MULU
: case OP_MULS
:
532 return simplify_mul_div(insn
, value
);
536 return replace_with_pseudo(insn
, insn
->src1
);
540 return replace_with_pseudo(insn
, insn
->src2
);
545 return simplify_seteq_setne(insn
, value
);
550 static int simplify_constant_leftside(struct instruction
*insn
)
552 long long value
= insn
->src1
->value
;
554 switch (insn
->opcode
) {
555 case OP_ADD
: case OP_OR
: case OP_XOR
:
557 return replace_with_pseudo(insn
, insn
->src2
);
561 case OP_LSR
: case OP_ASR
:
563 case OP_MULU
: case OP_MULS
:
565 return replace_with_pseudo(insn
, insn
->src1
);
571 static int simplify_constant_binop(struct instruction
*insn
)
573 /* FIXME! Verify signs and sizes!! */
574 long long left
= insn
->src1
->value
;
575 long long right
= insn
->src2
->value
;
576 unsigned long long ul
, ur
;
577 long long res
, mask
, bits
;
579 mask
= 1ULL << (insn
->size
-1);
580 bits
= mask
| (mask
-1);
589 switch (insn
->opcode
) {
610 if (left
== mask
&& right
== -1)
622 if (left
== mask
&& right
== -1)
652 /* Binary comparison */
688 replace_with_pseudo(insn
, value_pseudo(res
));
692 static int simplify_binop_same_args(struct instruction
*insn
, pseudo_t arg
)
694 switch (insn
->opcode
) {
696 case OP_SET_LT
: case OP_SET_GT
:
697 case OP_SET_B
: case OP_SET_A
:
698 if (Wtautological_compare
)
699 warning(insn
->pos
, "self-comparison always evaluates to false");
702 return replace_with_pseudo(insn
, value_pseudo(0));
705 case OP_SET_LE
: case OP_SET_GE
:
706 case OP_SET_BE
: case OP_SET_AE
:
707 if (Wtautological_compare
)
708 warning(insn
->pos
, "self-comparison always evaluates to true");
709 return replace_with_pseudo(insn
, value_pseudo(1));
713 return replace_with_pseudo(insn
, arg
);
717 remove_usage(arg
, &insn
->src2
);
718 insn
->src2
= value_pseudo(0);
719 insn
->opcode
= OP_SET_NE
;
729 static int simplify_binop(struct instruction
*insn
)
731 if (dead_insn(insn
, &insn
->src1
, &insn
->src2
, NULL
))
733 if (constant(insn
->src1
)) {
734 if (constant(insn
->src2
))
735 return simplify_constant_binop(insn
);
736 return simplify_constant_leftside(insn
);
738 if (constant(insn
->src2
))
739 return simplify_constant_rightside(insn
);
740 if (insn
->src1
== insn
->src2
)
741 return simplify_binop_same_args(insn
, insn
->src1
);
745 static void switch_pseudo(struct instruction
*insn1
, pseudo_t
*pp1
, struct instruction
*insn2
, pseudo_t
*pp2
)
747 pseudo_t p1
= *pp1
, p2
= *pp2
;
749 use_pseudo(insn1
, p2
, pp1
);
750 use_pseudo(insn2
, p1
, pp2
);
751 remove_usage(p1
, pp1
);
752 remove_usage(p2
, pp2
);
755 static int canonical_order(pseudo_t p1
, pseudo_t p2
)
757 /* symbol/constants on the right */
758 if (p1
->type
== PSEUDO_VAL
)
759 return p2
->type
== PSEUDO_VAL
;
761 if (p1
->type
== PSEUDO_SYM
)
762 return p2
->type
== PSEUDO_SYM
|| p2
->type
== PSEUDO_VAL
;
767 static int simplify_commutative_binop(struct instruction
*insn
)
769 if (!canonical_order(insn
->src1
, insn
->src2
)) {
770 switch_pseudo(insn
, &insn
->src1
, insn
, &insn
->src2
);
776 static inline int simple_pseudo(pseudo_t pseudo
)
778 return pseudo
->type
== PSEUDO_VAL
|| pseudo
->type
== PSEUDO_SYM
;
781 static int simplify_associative_binop(struct instruction
*insn
)
783 struct instruction
*def
;
784 pseudo_t pseudo
= insn
->src1
;
786 if (!simple_pseudo(insn
->src2
))
788 if (pseudo
->type
!= PSEUDO_REG
)
793 if (def
->opcode
!= insn
->opcode
)
795 if (!simple_pseudo(def
->src2
))
797 if (ptr_list_size((struct ptr_list
*)def
->target
->users
) != 1)
799 switch_pseudo(def
, &def
->src1
, insn
, &insn
->src2
);
803 static int simplify_constant_unop(struct instruction
*insn
)
805 long long val
= insn
->src1
->value
;
808 switch (insn
->opcode
) {
818 mask
= 1ULL << (insn
->size
-1);
819 res
&= mask
| (mask
-1);
821 replace_with_pseudo(insn
, value_pseudo(res
));
825 static int simplify_unop(struct instruction
*insn
)
827 if (dead_insn(insn
, &insn
->src1
, NULL
, NULL
))
829 if (constant(insn
->src1
))
830 return simplify_constant_unop(insn
);
832 switch (insn
->opcode
) {
833 struct instruction
*def
;
836 def
= insn
->src
->def
;
837 if (def
&& def
->opcode
== OP_NOT
)
838 return replace_with_pseudo(insn
, def
->src
);
841 def
= insn
->src
->def
;
842 if (def
&& def
->opcode
== OP_NEG
)
843 return replace_with_pseudo(insn
, def
->src
);
851 static int simplify_one_memop(struct instruction
*insn
, pseudo_t orig
)
853 pseudo_t addr
= insn
->src
;
856 if (addr
->type
== PSEUDO_REG
) {
857 struct instruction
*def
= addr
->def
;
858 if (def
->opcode
== OP_SYMADDR
&& def
->src
) {
859 kill_use(&insn
->src
);
860 use_pseudo(insn
, def
->src
, &insn
->src
);
861 return REPEAT_CSE
| REPEAT_SYMBOL_CLEANUP
;
863 if (def
->opcode
== OP_ADD
) {
883 * If some BB have been removed it is possible that this
884 * memop is in fact part of a dead BB. In this case
885 * we must not warn since nothing is wrong.
886 * If not part of a dead BB this will be redone after
887 * the BBs have been cleaned up.
889 if (repeat_phase
& REPEAT_CFG_CLEANUP
)
892 warning(insn
->pos
, "crazy programmer");
894 insn
->offset
+= off
->value
;
895 use_pseudo(insn
, new, &insn
->src
);
896 remove_usage(addr
, &insn
->src
);
897 return REPEAT_CSE
| REPEAT_SYMBOL_CLEANUP
;
901 * We walk the whole chain of adds/subs backwards. That's not
902 * only more efficient, but it allows us to find loops.
904 static int simplify_memop(struct instruction
*insn
)
907 pseudo_t orig
= insn
->src
;
910 one
= simplify_one_memop(insn
, orig
);
916 static long long get_cast_value(long long val
, int old_size
, int new_size
, int sign
)
920 if (sign
&& new_size
> old_size
) {
921 mask
= 1 << (old_size
-1);
923 val
|= ~(mask
| (mask
-1));
925 mask
= 1 << (new_size
-1);
926 return val
& (mask
| (mask
-1));
929 static int simplify_cast(struct instruction
*insn
)
931 struct symbol
*orig_type
;
935 if (dead_insn(insn
, &insn
->src
, NULL
, NULL
))
938 orig_type
= insn
->orig_type
;
942 /* Keep casts with pointer on either side (not only case of OP_PTRCAST) */
943 if (is_ptr_type(orig_type
) || is_ptr_type(insn
->type
))
946 orig_size
= orig_type
->bit_size
;
950 /* A cast of a constant? */
952 int sign
= orig_type
->ctype
.modifiers
& MOD_SIGNED
;
953 long long val
= get_cast_value(src
->value
, orig_size
, size
, sign
);
954 src
= value_pseudo(val
);
958 /* A cast of a "and" might be a no-op.. */
959 if (src
->type
== PSEUDO_REG
) {
960 struct instruction
*def
= src
->def
;
961 if (def
->opcode
== OP_AND
&& def
->size
>= size
) {
962 pseudo_t val
= def
->src2
;
963 if (val
->type
== PSEUDO_VAL
) {
964 unsigned long long value
= val
->value
;
965 if (!(value
>> (size
-1)))
971 if (size
== orig_size
) {
972 int op
= (orig_type
->ctype
.modifiers
& MOD_SIGNED
) ? OP_SCAST
: OP_CAST
;
973 if (insn
->opcode
== op
)
975 if (insn
->opcode
== OP_FPCAST
&& is_float_type(orig_type
))
982 return replace_with_pseudo(insn
, src
);
985 static int simplify_select(struct instruction
*insn
)
987 pseudo_t cond
, src1
, src2
;
989 if (dead_insn(insn
, &insn
->src1
, &insn
->src2
, &insn
->src3
))
995 if (constant(cond
) || src1
== src2
) {
996 pseudo_t
*kill
, take
;
997 kill_use(&insn
->src1
);
998 take
= cond
->value
? src1
: src2
;
999 kill
= cond
->value
? &insn
->src3
: &insn
->src2
;
1001 replace_with_pseudo(insn
, take
);
1004 if (constant(src1
) && constant(src2
)) {
1005 long long val1
= src1
->value
;
1006 long long val2
= src2
->value
;
1008 /* The pair 0/1 is special - replace with SETNE/SETEQ */
1009 if ((val1
| val2
) == 1) {
1010 int opcode
= OP_SET_EQ
;
1015 insn
->opcode
= opcode
;
1016 /* insn->src1 is already cond */
1017 insn
->src2
= src1
; /* Zero */
1024 static int is_in_range(pseudo_t src
, long long low
, long long high
)
1028 switch (src
->type
) {
1031 return value
>= low
&& value
<= high
;
1037 static int simplify_range(struct instruction
*insn
)
1039 pseudo_t src1
, src2
, src3
;
1044 if (src2
->type
!= PSEUDO_VAL
|| src3
->type
!= PSEUDO_VAL
)
1046 if (is_in_range(src1
, src2
->value
, src3
->value
)) {
1047 kill_instruction(insn
);
1054 * Simplify "set_ne/eq $0 + br"
1056 static int simplify_cond_branch(struct instruction
*br
, pseudo_t cond
, struct instruction
*def
, pseudo_t
*pp
)
1058 use_pseudo(br
, *pp
, &br
->cond
);
1059 remove_usage(cond
, &br
->cond
);
1060 if (def
->opcode
== OP_SET_EQ
) {
1061 struct basic_block
*true = br
->bb_true
;
1062 struct basic_block
*false = br
->bb_false
;
1063 br
->bb_false
= true;
1064 br
->bb_true
= false;
1069 static int simplify_branch(struct instruction
*insn
)
1071 pseudo_t cond
= insn
->cond
;
1073 /* Constant conditional */
1074 if (constant(cond
)) {
1075 insert_branch(insn
->bb
, insn
, cond
->value
? insn
->bb_true
: insn
->bb_false
);
1080 if (insn
->bb_true
== insn
->bb_false
) {
1081 struct basic_block
*bb
= insn
->bb
;
1082 struct basic_block
*target
= insn
->bb_false
;
1083 remove_bb_from_list(&target
->parents
, bb
, 1);
1084 remove_bb_from_list(&bb
->children
, target
, 1);
1085 insn
->bb_false
= NULL
;
1086 kill_use(&insn
->cond
);
1088 insn
->opcode
= OP_BR
;
1092 /* Conditional on a SETNE $0 or SETEQ $0 */
1093 if (cond
->type
== PSEUDO_REG
) {
1094 struct instruction
*def
= cond
->def
;
1096 if (def
->opcode
== OP_SET_NE
|| def
->opcode
== OP_SET_EQ
) {
1097 if (constant(def
->src1
) && !def
->src1
->value
)
1098 return simplify_cond_branch(insn
, cond
, def
, &def
->src2
);
1099 if (constant(def
->src2
) && !def
->src2
->value
)
1100 return simplify_cond_branch(insn
, cond
, def
, &def
->src1
);
1102 if (def
->opcode
== OP_SEL
) {
1103 if (constant(def
->src2
) && constant(def
->src3
)) {
1104 long long val1
= def
->src2
->value
;
1105 long long val2
= def
->src3
->value
;
1106 if (!val1
&& !val2
) {
1107 insert_branch(insn
->bb
, insn
, insn
->bb_false
);
1111 insert_branch(insn
->bb
, insn
, insn
->bb_true
);
1115 struct basic_block
*true = insn
->bb_true
;
1116 struct basic_block
*false = insn
->bb_false
;
1117 insn
->bb_false
= true;
1118 insn
->bb_true
= false;
1120 use_pseudo(insn
, def
->src1
, &insn
->cond
);
1121 remove_usage(cond
, &insn
->cond
);
1125 if (def
->opcode
== OP_CAST
|| def
->opcode
== OP_SCAST
) {
1126 int orig_size
= def
->orig_type
? def
->orig_type
->bit_size
: 0;
1127 if (def
->size
> orig_size
) {
1128 use_pseudo(insn
, def
->src
, &insn
->cond
);
1129 remove_usage(cond
, &insn
->cond
);
1137 static int simplify_switch(struct instruction
*insn
)
1139 pseudo_t cond
= insn
->cond
;
1141 struct multijmp
*jmp
;
1143 if (!constant(cond
))
1145 val
= insn
->cond
->value
;
1147 FOR_EACH_PTR(insn
->multijmp_list
, jmp
) {
1149 if (jmp
->begin
> jmp
->end
)
1151 if (val
>= jmp
->begin
&& val
<= jmp
->end
)
1153 } END_FOR_EACH_PTR(jmp
);
1154 warning(insn
->pos
, "Impossible case statement");
1158 insert_branch(insn
->bb
, insn
, jmp
->target
);
1162 int simplify_instruction(struct instruction
*insn
)
1166 switch (insn
->opcode
) {
1167 case OP_ADD
: case OP_MULS
:
1168 case OP_AND
: case OP_OR
: case OP_XOR
:
1169 case OP_AND_BOOL
: case OP_OR_BOOL
:
1170 if (simplify_binop(insn
))
1172 if (simplify_commutative_binop(insn
))
1174 return simplify_associative_binop(insn
);
1177 case OP_SET_EQ
: case OP_SET_NE
:
1178 if (simplify_binop(insn
))
1180 return simplify_commutative_binop(insn
);
1183 case OP_DIVU
: case OP_DIVS
:
1184 case OP_MODU
: case OP_MODS
:
1186 case OP_LSR
: case OP_ASR
:
1187 case OP_SET_LE
: case OP_SET_GE
:
1188 case OP_SET_LT
: case OP_SET_GT
:
1189 case OP_SET_B
: case OP_SET_A
:
1190 case OP_SET_BE
: case OP_SET_AE
:
1191 return simplify_binop(insn
);
1193 case OP_NOT
: case OP_NEG
:
1194 return simplify_unop(insn
);
1195 case OP_LOAD
: case OP_STORE
:
1196 return simplify_memop(insn
);
1198 if (dead_insn(insn
, NULL
, NULL
, NULL
))
1199 return REPEAT_CSE
| REPEAT_SYMBOL_CLEANUP
;
1200 return replace_with_pseudo(insn
, insn
->symbol
);
1205 return simplify_cast(insn
);
1207 if (dead_insn(insn
, NULL
, NULL
, NULL
)) {
1208 kill_use_list(insn
->phi_list
);
1211 return clean_up_phi(insn
);
1213 if (dead_insn(insn
, &insn
->phi_src
, NULL
, NULL
))
1217 return simplify_select(insn
);
1219 return simplify_branch(insn
);
1221 return simplify_switch(insn
);
1223 return simplify_range(insn
);