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 MARK_CURRENT_DELETED(pu
);
179 } END_FOR_EACH_PTR(pu
);
182 if (ptr_list_size((struct ptr_list
*) *list
) == 0)
187 static inline void remove_usage(pseudo_t p
, pseudo_t
*usep
)
189 if (has_use_list(p
)) {
190 delete_pseudo_user_list_entry(&p
->users
, usep
, 1);
192 kill_instruction(p
->def
);
196 void kill_use(pseudo_t
*usep
)
201 remove_usage(p
, usep
);
205 static void kill_use_list(struct pseudo_list
*list
)
208 FOR_EACH_PTR(list
, p
) {
211 kill_use(THIS_ADDRESS(p
));
212 } END_FOR_EACH_PTR(p
);
216 * kill an instruction:
217 * - remove it from its bb
218 * - remove the usage of all its operands
219 * If forse is zero, the normal case, the function only for
220 * instructions free of (possible) side-effects. Otherwise
221 * the function does that unconditionally (must only be used
222 * for unreachable instructions.
224 void kill_insn(struct instruction
*insn
, int force
)
226 if (!insn
|| !insn
->bb
)
229 switch (insn
->opcode
) {
232 kill_use(&insn
->src3
);
235 case OP_BINARY
... OP_BINCMP_END
:
236 kill_use(&insn
->src2
);
244 case OP_NOT
: case OP_NEG
:
246 kill_use(&insn
->src1
);
250 kill_use_list(insn
->phi_list
);
253 kill_use(&insn
->phi_src
);
257 repeat_phase
|= REPEAT_SYMBOL_CLEANUP
;
261 case OP_COMPUTEDGOTO
:
262 kill_use(&insn
->cond
);
267 /* a "pure" function can be killed too */
268 if (!(insn
->func
->type
== PSEUDO_SYM
))
270 if (!(insn
->func
->sym
->ctype
.modifiers
& MOD_PURE
))
273 kill_use_list(insn
->arguments
);
274 if (insn
->func
->type
== PSEUDO_REG
)
275 kill_use(&insn
->func
);
279 if (!force
&& insn
->type
->ctype
.modifiers
& MOD_VOLATILE
)
281 kill_use(&insn
->src
);
287 kill_use(&insn
->src
);
288 kill_use(&insn
->target
);
301 repeat_phase
|= REPEAT_CSE
;
306 * Kill trivially dead instructions
308 static int dead_insn(struct instruction
*insn
, pseudo_t
*src1
, pseudo_t
*src2
, pseudo_t
*src3
)
310 struct pseudo_user
*pu
;
311 FOR_EACH_PTR(insn
->target
->users
, pu
) {
312 if (*pu
->userp
!= VOID
)
314 } END_FOR_EACH_PTR(pu
);
323 static inline int constant(pseudo_t pseudo
)
325 return pseudo
->type
== PSEUDO_VAL
;
328 static int replace_with_pseudo(struct instruction
*insn
, pseudo_t pseudo
)
330 convert_instruction_target(insn
, pseudo
);
332 switch (insn
->opcode
) {
335 kill_use(&insn
->src3
);
336 case OP_BINARY
... OP_BINCMP_END
:
337 kill_use(&insn
->src2
);
345 kill_use(&insn
->src1
);
355 unsigned int value_size(long long value
)
370 * Try to determine the maximum size of bits in a pseudo.
372 * Right now this only follow casts and constant values, but we
373 * could look at things like logical 'and' instructions etc.
375 static unsigned int operand_size(struct instruction
*insn
, pseudo_t pseudo
)
377 unsigned int size
= insn
->size
;
379 if (pseudo
->type
== PSEUDO_REG
) {
380 struct instruction
*src
= pseudo
->def
;
381 if (src
&& src
->opcode
== OP_CAST
&& src
->orig_type
) {
382 unsigned int orig_size
= src
->orig_type
->bit_size
;
383 if (orig_size
< size
)
387 if (pseudo
->type
== PSEUDO_VAL
) {
388 unsigned int orig_size
= value_size(pseudo
->value
);
389 if (orig_size
< size
)
395 static int simplify_asr(struct instruction
*insn
, pseudo_t pseudo
, long long value
)
397 unsigned int size
= operand_size(insn
, pseudo
);
400 warning(insn
->pos
, "right shift by bigger than source value");
401 return replace_with_pseudo(insn
, value_pseudo(insn
->type
, 0));
404 return replace_with_pseudo(insn
, pseudo
);
408 static int simplify_mul_div(struct instruction
*insn
, long long value
)
410 unsigned long long sbit
= 1ULL << (insn
->size
- 1);
411 unsigned long long bits
= sbit
| (sbit
- 1);
414 return replace_with_pseudo(insn
, insn
->src1
);
416 switch (insn
->opcode
) {
420 return replace_with_pseudo(insn
, insn
->src2
);
423 if (!(value
& sbit
)) // positive
428 insn
->opcode
= OP_NEG
;
436 static int compare_opcode(int opcode
, int inverse
)
442 case OP_SET_EQ
: return OP_SET_NE
;
443 case OP_SET_NE
: return OP_SET_EQ
;
445 case OP_SET_LT
: return OP_SET_GE
;
446 case OP_SET_LE
: return OP_SET_GT
;
447 case OP_SET_GT
: return OP_SET_LE
;
448 case OP_SET_GE
: return OP_SET_LT
;
450 case OP_SET_A
: return OP_SET_BE
;
451 case OP_SET_AE
: return OP_SET_B
;
452 case OP_SET_B
: return OP_SET_AE
;
453 case OP_SET_BE
: return OP_SET_A
;
460 static int simplify_seteq_setne(struct instruction
*insn
, long long value
)
462 pseudo_t old
= insn
->src1
;
463 struct instruction
*def
= old
->def
;
468 if (value
!= 0 && value
!= 1)
474 inverse
= (insn
->opcode
== OP_SET_NE
) == value
;
475 opcode
= def
->opcode
;
477 case OP_BINCMP
... OP_BINCMP_END
:
479 // setcc.n %t <- %a, %b
480 // setne.m %r <- %t, $0
482 // setcc.n %t <- %a, %b
483 // setcc.m %r <- %a, $b
484 // and similar for setne/eq ... 0/1
487 insn
->opcode
= compare_opcode(opcode
, inverse
);
488 use_pseudo(insn
, src1
, &insn
->src1
);
489 use_pseudo(insn
, src2
, &insn
->src2
);
490 remove_usage(old
, &insn
->src1
);
498 static int simplify_constant_rightside(struct instruction
*insn
)
500 long long value
= insn
->src2
->value
;
502 switch (insn
->opcode
) {
505 return replace_with_pseudo(insn
, insn
->src2
);
506 goto case_neutral_zero
;
510 insn
->opcode
= OP_ADD
;
511 insn
->src2
= value_pseudo(insn
->type
, -value
);
516 case OP_OR
: case OP_XOR
:
521 return replace_with_pseudo(insn
, insn
->src1
);
524 return simplify_asr(insn
, insn
->src1
, value
);
526 case OP_MODU
: case OP_MODS
:
528 return replace_with_pseudo(insn
, value_pseudo(insn
->type
, 0));
531 case OP_DIVU
: case OP_DIVS
:
532 case OP_MULU
: case OP_MULS
:
533 return simplify_mul_div(insn
, value
);
537 return replace_with_pseudo(insn
, insn
->src1
);
541 return replace_with_pseudo(insn
, insn
->src2
);
546 return simplify_seteq_setne(insn
, value
);
551 static int simplify_constant_leftside(struct instruction
*insn
)
553 long long value
= insn
->src1
->value
;
555 switch (insn
->opcode
) {
556 case OP_ADD
: case OP_OR
: case OP_XOR
:
558 return replace_with_pseudo(insn
, insn
->src2
);
562 case OP_LSR
: case OP_ASR
:
564 case OP_MULU
: case OP_MULS
:
566 return replace_with_pseudo(insn
, insn
->src1
);
572 static int simplify_constant_binop(struct instruction
*insn
)
574 /* FIXME! Verify signs and sizes!! */
575 long long left
= insn
->src1
->value
;
576 long long right
= insn
->src2
->value
;
577 unsigned long long ul
, ur
;
578 long long res
, mask
, bits
;
580 mask
= 1ULL << (insn
->size
-1);
581 bits
= mask
| (mask
-1);
590 switch (insn
->opcode
) {
611 if (left
== mask
&& right
== -1)
623 if (left
== mask
&& right
== -1)
653 /* Binary comparison */
689 replace_with_pseudo(insn
, value_pseudo(insn
->type
, res
));
693 static int simplify_binop_same_args(struct instruction
*insn
, pseudo_t arg
)
695 switch (insn
->opcode
) {
697 case OP_SET_LT
: case OP_SET_GT
:
698 case OP_SET_B
: case OP_SET_A
:
699 if (Wtautological_compare
)
700 warning(insn
->pos
, "self-comparison always evaluates to false");
703 return replace_with_pseudo(insn
, value_pseudo(insn
->type
, 0));
706 case OP_SET_LE
: case OP_SET_GE
:
707 case OP_SET_BE
: case OP_SET_AE
:
708 if (Wtautological_compare
)
709 warning(insn
->pos
, "self-comparison always evaluates to true");
710 return replace_with_pseudo(insn
, value_pseudo(insn
->type
, 1));
714 return replace_with_pseudo(insn
, arg
);
718 remove_usage(arg
, &insn
->src2
);
719 insn
->src2
= value_pseudo(insn
->type
, 0);
720 insn
->opcode
= OP_SET_NE
;
730 static int simplify_binop(struct instruction
*insn
)
732 if (dead_insn(insn
, &insn
->src1
, &insn
->src2
, NULL
))
734 if (constant(insn
->src1
)) {
735 if (constant(insn
->src2
))
736 return simplify_constant_binop(insn
);
737 return simplify_constant_leftside(insn
);
739 if (constant(insn
->src2
))
740 return simplify_constant_rightside(insn
);
741 if (insn
->src1
== insn
->src2
)
742 return simplify_binop_same_args(insn
, insn
->src1
);
746 static void switch_pseudo(struct instruction
*insn1
, pseudo_t
*pp1
, struct instruction
*insn2
, pseudo_t
*pp2
)
748 pseudo_t p1
= *pp1
, p2
= *pp2
;
750 use_pseudo(insn1
, p2
, pp1
);
751 use_pseudo(insn2
, p1
, pp2
);
752 remove_usage(p1
, pp1
);
753 remove_usage(p2
, pp2
);
756 static int canonical_order(pseudo_t p1
, pseudo_t p2
)
758 /* symbol/constants on the right */
759 if (p1
->type
== PSEUDO_VAL
)
760 return p2
->type
== PSEUDO_VAL
;
762 if (p1
->type
== PSEUDO_SYM
)
763 return p2
->type
== PSEUDO_SYM
|| p2
->type
== PSEUDO_VAL
;
768 static int simplify_commutative_binop(struct instruction
*insn
)
770 if (!canonical_order(insn
->src1
, insn
->src2
)) {
771 switch_pseudo(insn
, &insn
->src1
, insn
, &insn
->src2
);
777 static inline int simple_pseudo(pseudo_t pseudo
)
779 return pseudo
->type
== PSEUDO_VAL
|| pseudo
->type
== PSEUDO_SYM
;
782 static int simplify_associative_binop(struct instruction
*insn
)
784 struct instruction
*def
;
785 pseudo_t pseudo
= insn
->src1
;
787 if (!simple_pseudo(insn
->src2
))
789 if (pseudo
->type
!= PSEUDO_REG
)
794 if (def
->opcode
!= insn
->opcode
)
796 if (!simple_pseudo(def
->src2
))
798 if (ptr_list_size((struct ptr_list
*)def
->target
->users
) != 1)
800 switch_pseudo(def
, &def
->src1
, insn
, &insn
->src2
);
804 static int simplify_constant_unop(struct instruction
*insn
)
806 long long val
= insn
->src1
->value
;
809 switch (insn
->opcode
) {
819 mask
= 1ULL << (insn
->size
-1);
820 res
&= mask
| (mask
-1);
822 replace_with_pseudo(insn
, value_pseudo(insn
->type
, res
));
826 static int simplify_unop(struct instruction
*insn
)
828 if (dead_insn(insn
, &insn
->src1
, NULL
, NULL
))
830 if (constant(insn
->src1
))
831 return simplify_constant_unop(insn
);
833 switch (insn
->opcode
) {
834 struct instruction
*def
;
837 def
= insn
->src
->def
;
838 if (def
&& def
->opcode
== OP_NOT
)
839 return replace_with_pseudo(insn
, def
->src
);
842 def
= insn
->src
->def
;
843 if (def
&& def
->opcode
== OP_NEG
)
844 return replace_with_pseudo(insn
, def
->src
);
852 static int simplify_one_memop(struct instruction
*insn
, pseudo_t orig
)
854 pseudo_t addr
= insn
->src
;
857 if (addr
->type
== PSEUDO_REG
) {
858 struct instruction
*def
= addr
->def
;
859 if (def
->opcode
== OP_SYMADDR
&& def
->src
) {
860 kill_use(&insn
->src
);
861 use_pseudo(insn
, def
->src
, &insn
->src
);
862 return REPEAT_CSE
| REPEAT_SYMBOL_CLEANUP
;
864 if (def
->opcode
== OP_ADD
) {
884 * If some BB have been removed it is possible that this
885 * memop is in fact part of a dead BB. In this case
886 * we must not warn since nothing is wrong.
887 * If not part of a dead BB this will be redone after
888 * the BBs have been cleaned up.
890 if (repeat_phase
& REPEAT_CFG_CLEANUP
)
893 warning(insn
->pos
, "crazy programmer");
895 insn
->offset
+= off
->value
;
896 use_pseudo(insn
, new, &insn
->src
);
897 remove_usage(addr
, &insn
->src
);
898 return REPEAT_CSE
| REPEAT_SYMBOL_CLEANUP
;
902 * We walk the whole chain of adds/subs backwards. That's not
903 * only more efficient, but it allows us to find loops.
905 static int simplify_memop(struct instruction
*insn
)
908 pseudo_t orig
= insn
->src
;
911 one
= simplify_one_memop(insn
, orig
);
917 static long long get_cast_value(long long val
, int old_size
, int new_size
, int sign
)
921 if (sign
&& new_size
> old_size
) {
922 mask
= 1 << (old_size
-1);
924 val
|= ~(mask
| (mask
-1));
926 mask
= 1 << (new_size
-1);
927 return val
& (mask
| (mask
-1));
930 static int simplify_cast(struct instruction
*insn
)
932 struct symbol
*orig_type
;
936 if (dead_insn(insn
, &insn
->src
, NULL
, NULL
))
939 orig_type
= insn
->orig_type
;
943 /* Keep casts with pointer on either side (not only case of OP_PTRCAST) */
944 if (is_ptr_type(orig_type
) || is_ptr_type(insn
->type
))
947 orig_size
= orig_type
->bit_size
;
951 /* A cast of a constant? */
953 int sign
= orig_type
->ctype
.modifiers
& MOD_SIGNED
;
954 long long val
= get_cast_value(src
->value
, orig_size
, size
, sign
);
955 src
= value_pseudo(orig_type
, val
);
959 /* A cast of a "and" might be a no-op.. */
960 if (src
->type
== PSEUDO_REG
) {
961 struct instruction
*def
= src
->def
;
962 if (def
->opcode
== OP_AND
&& def
->size
>= size
) {
963 pseudo_t val
= def
->src2
;
964 if (val
->type
== PSEUDO_VAL
) {
965 unsigned long long value
= val
->value
;
966 if (!(value
>> (size
-1)))
972 if (size
== orig_size
) {
973 int op
= (orig_type
->ctype
.modifiers
& MOD_SIGNED
) ? OP_SCAST
: OP_CAST
;
974 if (insn
->opcode
== op
)
976 if (insn
->opcode
== OP_FPCAST
&& is_float_type(orig_type
))
983 return replace_with_pseudo(insn
, src
);
986 static int simplify_select(struct instruction
*insn
)
988 pseudo_t cond
, src1
, src2
;
990 if (dead_insn(insn
, &insn
->src1
, &insn
->src2
, &insn
->src3
))
996 if (constant(cond
) || src1
== src2
) {
997 pseudo_t
*kill
, take
;
998 kill_use(&insn
->src1
);
999 take
= cond
->value
? src1
: src2
;
1000 kill
= cond
->value
? &insn
->src3
: &insn
->src2
;
1002 replace_with_pseudo(insn
, take
);
1005 if (constant(src1
) && constant(src2
)) {
1006 long long val1
= src1
->value
;
1007 long long val2
= src2
->value
;
1009 /* The pair 0/1 is special - replace with SETNE/SETEQ */
1010 if ((val1
| val2
) == 1) {
1011 int opcode
= OP_SET_EQ
;
1016 insn
->opcode
= opcode
;
1017 /* insn->src1 is already cond */
1018 insn
->src2
= src1
; /* Zero */
1025 static int is_in_range(pseudo_t src
, long long low
, long long high
)
1029 switch (src
->type
) {
1032 return value
>= low
&& value
<= high
;
1038 static int simplify_range(struct instruction
*insn
)
1040 pseudo_t src1
, src2
, src3
;
1045 if (src2
->type
!= PSEUDO_VAL
|| src3
->type
!= PSEUDO_VAL
)
1047 if (is_in_range(src1
, src2
->value
, src3
->value
)) {
1048 kill_instruction(insn
);
1055 * Simplify "set_ne/eq $0 + br"
1057 static int simplify_cond_branch(struct instruction
*br
, pseudo_t cond
, struct instruction
*def
, pseudo_t
*pp
)
1059 use_pseudo(br
, *pp
, &br
->cond
);
1060 remove_usage(cond
, &br
->cond
);
1061 if (def
->opcode
== OP_SET_EQ
) {
1062 struct basic_block
*true = br
->bb_true
;
1063 struct basic_block
*false = br
->bb_false
;
1064 br
->bb_false
= true;
1065 br
->bb_true
= false;
1070 static int simplify_branch(struct instruction
*insn
)
1072 pseudo_t cond
= insn
->cond
;
1074 /* Constant conditional */
1075 if (constant(cond
)) {
1076 insert_branch(insn
->bb
, insn
, cond
->value
? insn
->bb_true
: insn
->bb_false
);
1081 if (insn
->bb_true
== insn
->bb_false
) {
1082 struct basic_block
*bb
= insn
->bb
;
1083 struct basic_block
*target
= insn
->bb_false
;
1084 remove_bb_from_list(&target
->parents
, bb
, 1);
1085 remove_bb_from_list(&bb
->children
, target
, 1);
1086 insn
->bb_false
= NULL
;
1087 kill_use(&insn
->cond
);
1089 insn
->opcode
= OP_BR
;
1093 /* Conditional on a SETNE $0 or SETEQ $0 */
1094 if (cond
->type
== PSEUDO_REG
) {
1095 struct instruction
*def
= cond
->def
;
1097 if (def
->opcode
== OP_SET_NE
|| def
->opcode
== OP_SET_EQ
) {
1098 if (constant(def
->src1
) && !def
->src1
->value
)
1099 return simplify_cond_branch(insn
, cond
, def
, &def
->src2
);
1100 if (constant(def
->src2
) && !def
->src2
->value
)
1101 return simplify_cond_branch(insn
, cond
, def
, &def
->src1
);
1103 if (def
->opcode
== OP_SEL
) {
1104 if (constant(def
->src2
) && constant(def
->src3
)) {
1105 long long val1
= def
->src2
->value
;
1106 long long val2
= def
->src3
->value
;
1107 if (!val1
&& !val2
) {
1108 insert_branch(insn
->bb
, insn
, insn
->bb_false
);
1112 insert_branch(insn
->bb
, insn
, insn
->bb_true
);
1116 struct basic_block
*true = insn
->bb_true
;
1117 struct basic_block
*false = insn
->bb_false
;
1118 insn
->bb_false
= true;
1119 insn
->bb_true
= false;
1121 use_pseudo(insn
, def
->src1
, &insn
->cond
);
1122 remove_usage(cond
, &insn
->cond
);
1126 if (def
->opcode
== OP_CAST
|| def
->opcode
== OP_SCAST
) {
1127 int orig_size
= def
->orig_type
? def
->orig_type
->bit_size
: 0;
1128 if (def
->size
> orig_size
) {
1129 use_pseudo(insn
, def
->src
, &insn
->cond
);
1130 remove_usage(cond
, &insn
->cond
);
1138 static int simplify_switch(struct instruction
*insn
)
1140 pseudo_t cond
= insn
->cond
;
1142 struct multijmp
*jmp
;
1144 if (!constant(cond
))
1146 val
= insn
->cond
->value
;
1148 FOR_EACH_PTR(insn
->multijmp_list
, jmp
) {
1150 if (jmp
->begin
> jmp
->end
)
1152 if (val
>= jmp
->begin
&& val
<= jmp
->end
)
1154 } END_FOR_EACH_PTR(jmp
);
1155 warning(insn
->pos
, "Impossible case statement");
1159 insert_branch(insn
->bb
, insn
, jmp
->target
);
1163 int simplify_instruction(struct instruction
*insn
)
1167 switch (insn
->opcode
) {
1168 case OP_ADD
: case OP_MULS
:
1169 case OP_AND
: case OP_OR
: case OP_XOR
:
1170 case OP_AND_BOOL
: case OP_OR_BOOL
:
1171 if (simplify_binop(insn
))
1173 if (simplify_commutative_binop(insn
))
1175 return simplify_associative_binop(insn
);
1178 case OP_SET_EQ
: case OP_SET_NE
:
1179 if (simplify_binop(insn
))
1181 return simplify_commutative_binop(insn
);
1184 case OP_DIVU
: case OP_DIVS
:
1185 case OP_MODU
: case OP_MODS
:
1187 case OP_LSR
: case OP_ASR
:
1188 case OP_SET_LE
: case OP_SET_GE
:
1189 case OP_SET_LT
: case OP_SET_GT
:
1190 case OP_SET_B
: case OP_SET_A
:
1191 case OP_SET_BE
: case OP_SET_AE
:
1192 return simplify_binop(insn
);
1194 case OP_NOT
: case OP_NEG
:
1195 return simplify_unop(insn
);
1196 case OP_LOAD
: case OP_STORE
:
1197 return simplify_memop(insn
);
1199 if (dead_insn(insn
, NULL
, NULL
, NULL
))
1200 return REPEAT_CSE
| REPEAT_SYMBOL_CLEANUP
;
1201 return replace_with_pseudo(insn
, insn
->symbol
);
1206 return simplify_cast(insn
);
1208 if (dead_insn(insn
, NULL
, NULL
, NULL
)) {
1209 kill_use_list(insn
->phi_list
);
1212 return clean_up_phi(insn
);
1214 if (dead_insn(insn
, &insn
->phi_src
, NULL
, NULL
))
1218 return simplify_select(insn
);
1220 return simplify_branch(insn
);
1222 return simplify_switch(insn
);
1224 return simplify_range(insn
);