1 /* RTL simplification functions for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
29 #include "hard-reg-set.h"
32 #include "insn-config.h"
40 /* Simplification and canonicalization of RTL. */
42 /* Nonzero if X has the form (PLUS frame-pointer integer). We check for
43 virtual regs here because the simplify_*_operation routines are called
44 by integrate.c, which is called before virtual register instantiation.
46 ?!? NONZERO_BASE_PLUS_P needs to move into
47 a header file so that their definitions can be shared with the
48 simplification routines in simplify-rtx.c. Until then, do not
49 change this macro without also changing the copy in simplify-rtx.c. */
51 /* Allows reference to the stack pointer.
53 This used to include FIXED_BASE_PLUS_P, however, we can't assume that
54 arg_pointer_rtx by itself is nonzero, because on at least one machine,
55 the i960, the arg pointer is zero when it is unused. */
57 #define NONZERO_BASE_PLUS_P(X) \
58 ((X) == frame_pointer_rtx || (X) == hard_frame_pointer_rtx \
59 || (X) == virtual_stack_vars_rtx \
60 || (X) == virtual_incoming_args_rtx \
61 || (GET_CODE (X) == PLUS && GET_CODE (XEXP (X, 1)) == CONST_INT \
62 && (XEXP (X, 0) == frame_pointer_rtx \
63 || XEXP (X, 0) == hard_frame_pointer_rtx \
64 || ((X) == arg_pointer_rtx \
65 && fixed_regs[ARG_POINTER_REGNUM]) \
66 || XEXP (X, 0) == virtual_stack_vars_rtx \
67 || XEXP (X, 0) == virtual_incoming_args_rtx)) \
68 || (X) == stack_pointer_rtx \
69 || (X) == virtual_stack_dynamic_rtx \
70 || (X) == virtual_outgoing_args_rtx \
71 || (GET_CODE (X) == PLUS && GET_CODE (XEXP (X, 1)) == CONST_INT \
72 && (XEXP (X, 0) == stack_pointer_rtx \
73 || XEXP (X, 0) == virtual_stack_dynamic_rtx \
74 || XEXP (X, 0) == virtual_outgoing_args_rtx)) \
75 || GET_CODE (X) == ADDRESSOF)
77 /* Much code operates on (low, high) pairs; the low value is an
78 unsigned wide int, the high value a signed wide int. We
79 occasionally need to sign extend from low to high as if low were a
81 #define HWI_SIGN_EXTEND(low) \
82 ((((HOST_WIDE_INT) low) < 0) ? ((HOST_WIDE_INT) -1) : ((HOST_WIDE_INT) 0))
84 static rtx neg_const_int
PARAMS ((enum machine_mode
, rtx
));
85 static int simplify_plus_minus_op_data_cmp
PARAMS ((const void *,
87 static rtx simplify_plus_minus
PARAMS ((enum rtx_code
,
88 enum machine_mode
, rtx
,
91 /* Negate a CONST_INT rtx, truncating (because a conversion from a
92 maximally negative number can overflow). */
94 neg_const_int (mode
, i
)
95 enum machine_mode mode
;
98 return gen_int_mode (- INTVAL (i
), mode
);
102 /* Make a binary operation by properly ordering the operands and
103 seeing if the expression folds. */
106 simplify_gen_binary (code
, mode
, op0
, op1
)
108 enum machine_mode mode
;
113 /* Put complex operands first and constants second if commutative. */
114 if (GET_RTX_CLASS (code
) == 'c'
115 && swap_commutative_operands_p (op0
, op1
))
116 tem
= op0
, op0
= op1
, op1
= tem
;
118 /* If this simplifies, do it. */
119 tem
= simplify_binary_operation (code
, mode
, op0
, op1
);
123 /* Handle addition and subtraction specially. Otherwise, just form
126 if (code
== PLUS
|| code
== MINUS
)
128 tem
= simplify_plus_minus (code
, mode
, op0
, op1
, 1);
133 return gen_rtx_fmt_ee (code
, mode
, op0
, op1
);
136 /* If X is a MEM referencing the constant pool, return the real value.
137 Otherwise return X. */
139 avoid_constant_pool_reference (x
)
143 enum machine_mode cmode
;
145 if (GET_CODE (x
) != MEM
)
149 if (GET_CODE (addr
) != SYMBOL_REF
150 || ! CONSTANT_POOL_ADDRESS_P (addr
))
153 c
= get_pool_constant (addr
);
154 cmode
= get_pool_mode (addr
);
156 /* If we're accessing the constant in a different mode than it was
157 originally stored, attempt to fix that up via subreg simplifications.
158 If that fails we have no choice but to return the original memory. */
159 if (cmode
!= GET_MODE (x
))
161 c
= simplify_subreg (GET_MODE (x
), c
, cmode
, 0);
168 /* Make a unary operation by first seeing if it folds and otherwise making
169 the specified operation. */
172 simplify_gen_unary (code
, mode
, op
, op_mode
)
174 enum machine_mode mode
;
176 enum machine_mode op_mode
;
180 /* If this simplifies, use it. */
181 if ((tem
= simplify_unary_operation (code
, mode
, op
, op_mode
)) != 0)
184 return gen_rtx_fmt_e (code
, mode
, op
);
187 /* Likewise for ternary operations. */
190 simplify_gen_ternary (code
, mode
, op0_mode
, op0
, op1
, op2
)
192 enum machine_mode mode
, op0_mode
;
197 /* If this simplifies, use it. */
198 if (0 != (tem
= simplify_ternary_operation (code
, mode
, op0_mode
,
202 return gen_rtx_fmt_eee (code
, mode
, op0
, op1
, op2
);
205 /* Likewise, for relational operations.
206 CMP_MODE specifies mode comparison is done in.
210 simplify_gen_relational (code
, mode
, cmp_mode
, op0
, op1
)
212 enum machine_mode mode
;
213 enum machine_mode cmp_mode
;
218 if ((tem
= simplify_relational_operation (code
, cmp_mode
, op0
, op1
)) != 0)
221 /* For the following tests, ensure const0_rtx is op1. */
222 if (op0
== const0_rtx
&& swap_commutative_operands_p (op0
, op1
))
223 tem
= op0
, op0
= op1
, op1
= tem
, code
= swap_condition (code
);
225 /* If op0 is a compare, extract the comparison arguments from it. */
226 if (GET_CODE (op0
) == COMPARE
&& op1
== const0_rtx
)
227 op1
= XEXP (op0
, 1), op0
= XEXP (op0
, 0);
229 /* If op0 is a comparison, extract the comparison arguments form it. */
230 if (code
== NE
&& op1
== const0_rtx
231 && GET_RTX_CLASS (GET_CODE (op0
)) == '<')
233 else if (code
== EQ
&& op1
== const0_rtx
)
235 /* The following tests GET_RTX_CLASS (GET_CODE (op0)) == '<'. */
236 enum rtx_code
new = reversed_comparison_code (op0
, NULL_RTX
);
246 /* Put complex operands first and constants second. */
247 if (swap_commutative_operands_p (op0
, op1
))
248 tem
= op0
, op0
= op1
, op1
= tem
, code
= swap_condition (code
);
250 return gen_rtx_fmt_ee (code
, mode
, op0
, op1
);
253 /* Replace all occurrences of OLD in X with NEW and try to simplify the
254 resulting RTX. Return a new RTX which is as simplified as possible. */
257 simplify_replace_rtx (x
, old
, new)
262 enum rtx_code code
= GET_CODE (x
);
263 enum machine_mode mode
= GET_MODE (x
);
265 /* If X is OLD, return NEW. Otherwise, if this is an expression, try
266 to build a new expression substituting recursively. If we can't do
267 anything, return our input. */
272 switch (GET_RTX_CLASS (code
))
276 enum machine_mode op_mode
= GET_MODE (XEXP (x
, 0));
277 rtx op
= (XEXP (x
, 0) == old
278 ? new : simplify_replace_rtx (XEXP (x
, 0), old
, new));
280 return simplify_gen_unary (code
, mode
, op
, op_mode
);
286 simplify_gen_binary (code
, mode
,
287 simplify_replace_rtx (XEXP (x
, 0), old
, new),
288 simplify_replace_rtx (XEXP (x
, 1), old
, new));
291 enum machine_mode op_mode
= (GET_MODE (XEXP (x
, 0)) != VOIDmode
292 ? GET_MODE (XEXP (x
, 0))
293 : GET_MODE (XEXP (x
, 1)));
294 rtx op0
= simplify_replace_rtx (XEXP (x
, 0), old
, new);
295 rtx op1
= simplify_replace_rtx (XEXP (x
, 1), old
, new);
298 simplify_gen_relational (code
, mode
,
301 : GET_MODE (op0
) != VOIDmode
310 enum machine_mode op_mode
= GET_MODE (XEXP (x
, 0));
311 rtx op0
= simplify_replace_rtx (XEXP (x
, 0), old
, new);
314 simplify_gen_ternary (code
, mode
,
319 simplify_replace_rtx (XEXP (x
, 1), old
, new),
320 simplify_replace_rtx (XEXP (x
, 2), old
, new));
324 /* The only case we try to handle is a SUBREG. */
328 exp
= simplify_gen_subreg (GET_MODE (x
),
329 simplify_replace_rtx (SUBREG_REG (x
),
331 GET_MODE (SUBREG_REG (x
)),
340 return replace_equiv_address_nv (x
,
341 simplify_replace_rtx (XEXP (x
, 0),
344 if (REG_P (x
) && REG_P (old
) && REGNO (x
) == REGNO (old
))
355 /* Try to simplify a unary operation CODE whose output mode is to be
356 MODE with input operand OP whose mode was originally OP_MODE.
357 Return zero if no simplification can be made. */
359 simplify_unary_operation (code
, mode
, op
, op_mode
)
361 enum machine_mode mode
;
363 enum machine_mode op_mode
;
365 unsigned int width
= GET_MODE_BITSIZE (mode
);
366 rtx trueop
= avoid_constant_pool_reference (op
);
368 /* The order of these tests is critical so that, for example, we don't
369 check the wrong mode (input vs. output) for a conversion operation,
370 such as FIX. At some point, this should be simplified. */
372 if (code
== FLOAT
&& GET_MODE (trueop
) == VOIDmode
373 && (GET_CODE (trueop
) == CONST_DOUBLE
|| GET_CODE (trueop
) == CONST_INT
))
375 HOST_WIDE_INT hv
, lv
;
378 if (GET_CODE (trueop
) == CONST_INT
)
379 lv
= INTVAL (trueop
), hv
= HWI_SIGN_EXTEND (lv
);
381 lv
= CONST_DOUBLE_LOW (trueop
), hv
= CONST_DOUBLE_HIGH (trueop
);
383 REAL_VALUE_FROM_INT (d
, lv
, hv
, mode
);
384 d
= real_value_truncate (mode
, d
);
385 return CONST_DOUBLE_FROM_REAL_VALUE (d
, mode
);
387 else if (code
== UNSIGNED_FLOAT
&& GET_MODE (trueop
) == VOIDmode
388 && (GET_CODE (trueop
) == CONST_DOUBLE
389 || GET_CODE (trueop
) == CONST_INT
))
391 HOST_WIDE_INT hv
, lv
;
394 if (GET_CODE (trueop
) == CONST_INT
)
395 lv
= INTVAL (trueop
), hv
= HWI_SIGN_EXTEND (lv
);
397 lv
= CONST_DOUBLE_LOW (trueop
), hv
= CONST_DOUBLE_HIGH (trueop
);
399 if (op_mode
== VOIDmode
)
401 /* We don't know how to interpret negative-looking numbers in
402 this case, so don't try to fold those. */
406 else if (GET_MODE_BITSIZE (op_mode
) >= HOST_BITS_PER_WIDE_INT
* 2)
409 hv
= 0, lv
&= GET_MODE_MASK (op_mode
);
411 REAL_VALUE_FROM_UNSIGNED_INT (d
, lv
, hv
, mode
);
412 d
= real_value_truncate (mode
, d
);
413 return CONST_DOUBLE_FROM_REAL_VALUE (d
, mode
);
416 if (GET_CODE (trueop
) == CONST_INT
417 && width
<= HOST_BITS_PER_WIDE_INT
&& width
> 0)
419 HOST_WIDE_INT arg0
= INTVAL (trueop
);
433 val
= (arg0
>= 0 ? arg0
: - arg0
);
437 /* Don't use ffs here. Instead, get low order bit and then its
438 number. If arg0 is zero, this will return 0, as desired. */
439 arg0
&= GET_MODE_MASK (mode
);
440 val
= exact_log2 (arg0
& (- arg0
)) + 1;
448 /* When zero-extending a CONST_INT, we need to know its
450 if (op_mode
== VOIDmode
)
452 if (GET_MODE_BITSIZE (op_mode
) == HOST_BITS_PER_WIDE_INT
)
454 /* If we were really extending the mode,
455 we would have to distinguish between zero-extension
456 and sign-extension. */
457 if (width
!= GET_MODE_BITSIZE (op_mode
))
461 else if (GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
)
462 val
= arg0
& ~((HOST_WIDE_INT
) (-1) << GET_MODE_BITSIZE (op_mode
));
468 if (op_mode
== VOIDmode
)
470 if (GET_MODE_BITSIZE (op_mode
) == HOST_BITS_PER_WIDE_INT
)
472 /* If we were really extending the mode,
473 we would have to distinguish between zero-extension
474 and sign-extension. */
475 if (width
!= GET_MODE_BITSIZE (op_mode
))
479 else if (GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
)
482 = arg0
& ~((HOST_WIDE_INT
) (-1) << GET_MODE_BITSIZE (op_mode
));
484 & ((HOST_WIDE_INT
) 1 << (GET_MODE_BITSIZE (op_mode
) - 1)))
485 val
-= (HOST_WIDE_INT
) 1 << GET_MODE_BITSIZE (op_mode
);
502 val
= trunc_int_for_mode (val
, mode
);
504 return GEN_INT (val
);
507 /* We can do some operations on integer CONST_DOUBLEs. Also allow
508 for a DImode operation on a CONST_INT. */
509 else if (GET_MODE (trueop
) == VOIDmode
510 && width
<= HOST_BITS_PER_WIDE_INT
* 2
511 && (GET_CODE (trueop
) == CONST_DOUBLE
512 || GET_CODE (trueop
) == CONST_INT
))
514 unsigned HOST_WIDE_INT l1
, lv
;
515 HOST_WIDE_INT h1
, hv
;
517 if (GET_CODE (trueop
) == CONST_DOUBLE
)
518 l1
= CONST_DOUBLE_LOW (trueop
), h1
= CONST_DOUBLE_HIGH (trueop
);
520 l1
= INTVAL (trueop
), h1
= HWI_SIGN_EXTEND (l1
);
530 neg_double (l1
, h1
, &lv
, &hv
);
535 neg_double (l1
, h1
, &lv
, &hv
);
543 lv
= HOST_BITS_PER_WIDE_INT
+ exact_log2 (h1
& (-h1
)) + 1;
545 lv
= exact_log2 (l1
& (-l1
)) + 1;
549 /* This is just a change-of-mode, so do nothing. */
554 if (op_mode
== VOIDmode
)
557 if (GET_MODE_BITSIZE (op_mode
) > HOST_BITS_PER_WIDE_INT
)
561 lv
= l1
& GET_MODE_MASK (op_mode
);
565 if (op_mode
== VOIDmode
566 || GET_MODE_BITSIZE (op_mode
) > HOST_BITS_PER_WIDE_INT
)
570 lv
= l1
& GET_MODE_MASK (op_mode
);
571 if (GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
572 && (lv
& ((HOST_WIDE_INT
) 1
573 << (GET_MODE_BITSIZE (op_mode
) - 1))) != 0)
574 lv
-= (HOST_WIDE_INT
) 1 << GET_MODE_BITSIZE (op_mode
);
576 hv
= HWI_SIGN_EXTEND (lv
);
587 return immed_double_const (lv
, hv
, mode
);
590 else if (GET_CODE (trueop
) == CONST_DOUBLE
591 && GET_MODE_CLASS (mode
) == MODE_FLOAT
)
594 REAL_VALUE_FROM_CONST_DOUBLE (d
, trueop
);
599 /* We don't attempt to optimize this. */
603 d
= REAL_VALUE_ABS (d
);
606 d
= REAL_VALUE_NEGATE (d
);
609 d
= real_value_truncate (mode
, d
);
612 /* All this does is change the mode. */
615 real_arithmetic (&d
, FIX_TRUNC_EXPR
, &d
, NULL
);
621 return CONST_DOUBLE_FROM_REAL_VALUE (d
, mode
);
624 else if (GET_CODE (trueop
) == CONST_DOUBLE
625 && GET_MODE_CLASS (GET_MODE (trueop
)) == MODE_FLOAT
626 && GET_MODE_CLASS (mode
) == MODE_INT
627 && width
<= HOST_BITS_PER_WIDE_INT
&& width
> 0)
631 REAL_VALUE_FROM_CONST_DOUBLE (d
, trueop
);
634 case FIX
: i
= REAL_VALUE_FIX (d
); break;
635 case UNSIGNED_FIX
: i
= REAL_VALUE_UNSIGNED_FIX (d
); break;
639 return gen_int_mode (i
, mode
);
642 /* This was formerly used only for non-IEEE float.
643 eggert@twinsun.com says it is safe for IEEE also. */
646 enum rtx_code reversed
;
647 /* There are some simplifications we can do even if the operands
652 /* (not (not X)) == X. */
653 if (GET_CODE (op
) == NOT
)
656 /* (not (eq X Y)) == (ne X Y), etc. */
657 if (mode
== BImode
&& GET_RTX_CLASS (GET_CODE (op
)) == '<'
658 && ((reversed
= reversed_comparison_code (op
, NULL_RTX
))
660 return gen_rtx_fmt_ee (reversed
,
661 op_mode
, XEXP (op
, 0), XEXP (op
, 1));
665 /* (neg (neg X)) == X. */
666 if (GET_CODE (op
) == NEG
)
671 /* (sign_extend (truncate (minus (label_ref L1) (label_ref L2))))
672 becomes just the MINUS if its mode is MODE. This allows
673 folding switch statements on machines using casesi (such as
675 if (GET_CODE (op
) == TRUNCATE
676 && GET_MODE (XEXP (op
, 0)) == mode
677 && GET_CODE (XEXP (op
, 0)) == MINUS
678 && GET_CODE (XEXP (XEXP (op
, 0), 0)) == LABEL_REF
679 && GET_CODE (XEXP (XEXP (op
, 0), 1)) == LABEL_REF
)
682 #if defined(POINTERS_EXTEND_UNSIGNED) && !defined(HAVE_ptr_extend)
683 if (! POINTERS_EXTEND_UNSIGNED
684 && mode
== Pmode
&& GET_MODE (op
) == ptr_mode
686 || (GET_CODE (op
) == SUBREG
687 && GET_CODE (SUBREG_REG (op
)) == REG
688 && REG_POINTER (SUBREG_REG (op
))
689 && GET_MODE (SUBREG_REG (op
)) == Pmode
)))
690 return convert_memory_address (Pmode
, op
);
694 #if defined(POINTERS_EXTEND_UNSIGNED) && !defined(HAVE_ptr_extend)
696 if (POINTERS_EXTEND_UNSIGNED
> 0
697 && mode
== Pmode
&& GET_MODE (op
) == ptr_mode
699 || (GET_CODE (op
) == SUBREG
700 && GET_CODE (SUBREG_REG (op
)) == REG
701 && REG_POINTER (SUBREG_REG (op
))
702 && GET_MODE (SUBREG_REG (op
)) == Pmode
)))
703 return convert_memory_address (Pmode
, op
);
715 /* Simplify a binary operation CODE with result mode MODE, operating on OP0
716 and OP1. Return 0 if no simplification is possible.
718 Don't use this for relational operations such as EQ or LT.
719 Use simplify_relational_operation instead. */
721 simplify_binary_operation (code
, mode
, op0
, op1
)
723 enum machine_mode mode
;
726 HOST_WIDE_INT arg0
, arg1
, arg0s
, arg1s
;
728 unsigned int width
= GET_MODE_BITSIZE (mode
);
730 rtx trueop0
= avoid_constant_pool_reference (op0
);
731 rtx trueop1
= avoid_constant_pool_reference (op1
);
733 /* Relational operations don't work here. We must know the mode
734 of the operands in order to do the comparison correctly.
735 Assuming a full word can give incorrect results.
736 Consider comparing 128 with -128 in QImode. */
738 if (GET_RTX_CLASS (code
) == '<')
741 /* Make sure the constant is second. */
742 if (GET_RTX_CLASS (code
) == 'c'
743 && swap_commutative_operands_p (trueop0
, trueop1
))
745 tem
= op0
, op0
= op1
, op1
= tem
;
746 tem
= trueop0
, trueop0
= trueop1
, trueop1
= tem
;
749 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
750 && GET_CODE (trueop0
) == CONST_DOUBLE
751 && GET_CODE (trueop1
) == CONST_DOUBLE
752 && mode
== GET_MODE (op0
) && mode
== GET_MODE (op1
))
754 REAL_VALUE_TYPE f0
, f1
, value
;
756 REAL_VALUE_FROM_CONST_DOUBLE (f0
, trueop0
);
757 REAL_VALUE_FROM_CONST_DOUBLE (f1
, trueop1
);
758 f0
= real_value_truncate (mode
, f0
);
759 f1
= real_value_truncate (mode
, f1
);
762 && !MODE_HAS_INFINITIES (mode
)
763 && REAL_VALUES_EQUAL (f1
, dconst0
))
766 REAL_ARITHMETIC (value
, rtx_to_tree_code (code
), f0
, f1
);
768 value
= real_value_truncate (mode
, value
);
769 return CONST_DOUBLE_FROM_REAL_VALUE (value
, mode
);
772 /* We can fold some multi-word operations. */
773 if (GET_MODE_CLASS (mode
) == MODE_INT
774 && width
== HOST_BITS_PER_WIDE_INT
* 2
775 && (GET_CODE (trueop0
) == CONST_DOUBLE
776 || GET_CODE (trueop0
) == CONST_INT
)
777 && (GET_CODE (trueop1
) == CONST_DOUBLE
778 || GET_CODE (trueop1
) == CONST_INT
))
780 unsigned HOST_WIDE_INT l1
, l2
, lv
;
781 HOST_WIDE_INT h1
, h2
, hv
;
783 if (GET_CODE (trueop0
) == CONST_DOUBLE
)
784 l1
= CONST_DOUBLE_LOW (trueop0
), h1
= CONST_DOUBLE_HIGH (trueop0
);
786 l1
= INTVAL (trueop0
), h1
= HWI_SIGN_EXTEND (l1
);
788 if (GET_CODE (trueop1
) == CONST_DOUBLE
)
789 l2
= CONST_DOUBLE_LOW (trueop1
), h2
= CONST_DOUBLE_HIGH (trueop1
);
791 l2
= INTVAL (trueop1
), h2
= HWI_SIGN_EXTEND (l2
);
796 /* A - B == A + (-B). */
797 neg_double (l2
, h2
, &lv
, &hv
);
800 /* .. fall through ... */
803 add_double (l1
, h1
, l2
, h2
, &lv
, &hv
);
807 mul_double (l1
, h1
, l2
, h2
, &lv
, &hv
);
810 case DIV
: case MOD
: case UDIV
: case UMOD
:
811 /* We'd need to include tree.h to do this and it doesn't seem worth
816 lv
= l1
& l2
, hv
= h1
& h2
;
820 lv
= l1
| l2
, hv
= h1
| h2
;
824 lv
= l1
^ l2
, hv
= h1
^ h2
;
830 && ((unsigned HOST_WIDE_INT
) l1
831 < (unsigned HOST_WIDE_INT
) l2
)))
840 && ((unsigned HOST_WIDE_INT
) l1
841 > (unsigned HOST_WIDE_INT
) l2
)))
848 if ((unsigned HOST_WIDE_INT
) h1
< (unsigned HOST_WIDE_INT
) h2
850 && ((unsigned HOST_WIDE_INT
) l1
851 < (unsigned HOST_WIDE_INT
) l2
)))
858 if ((unsigned HOST_WIDE_INT
) h1
> (unsigned HOST_WIDE_INT
) h2
860 && ((unsigned HOST_WIDE_INT
) l1
861 > (unsigned HOST_WIDE_INT
) l2
)))
867 case LSHIFTRT
: case ASHIFTRT
:
869 case ROTATE
: case ROTATERT
:
870 #ifdef SHIFT_COUNT_TRUNCATED
871 if (SHIFT_COUNT_TRUNCATED
)
872 l2
&= (GET_MODE_BITSIZE (mode
) - 1), h2
= 0;
875 if (h2
!= 0 || l2
>= GET_MODE_BITSIZE (mode
))
878 if (code
== LSHIFTRT
|| code
== ASHIFTRT
)
879 rshift_double (l1
, h1
, l2
, GET_MODE_BITSIZE (mode
), &lv
, &hv
,
881 else if (code
== ASHIFT
)
882 lshift_double (l1
, h1
, l2
, GET_MODE_BITSIZE (mode
), &lv
, &hv
, 1);
883 else if (code
== ROTATE
)
884 lrotate_double (l1
, h1
, l2
, GET_MODE_BITSIZE (mode
), &lv
, &hv
);
885 else /* code == ROTATERT */
886 rrotate_double (l1
, h1
, l2
, GET_MODE_BITSIZE (mode
), &lv
, &hv
);
893 return immed_double_const (lv
, hv
, mode
);
896 if (GET_CODE (op0
) != CONST_INT
|| GET_CODE (op1
) != CONST_INT
897 || width
> HOST_BITS_PER_WIDE_INT
|| width
== 0)
899 /* Even if we can't compute a constant result,
900 there are some cases worth simplifying. */
905 /* Maybe simplify x + 0 to x. The two expressions are equivalent
906 when x is NaN, infinite, or finite and non-zero. They aren't
907 when x is -0 and the rounding mode is not towards -infinity,
908 since (-0) + 0 is then 0. */
909 if (!HONOR_SIGNED_ZEROS (mode
) && trueop1
== CONST0_RTX (mode
))
912 /* ((-a) + b) -> (b - a) and similarly for (a + (-b)). These
913 transformations are safe even for IEEE. */
914 if (GET_CODE (op0
) == NEG
)
915 return simplify_gen_binary (MINUS
, mode
, op1
, XEXP (op0
, 0));
916 else if (GET_CODE (op1
) == NEG
)
917 return simplify_gen_binary (MINUS
, mode
, op0
, XEXP (op1
, 0));
920 if (INTEGRAL_MODE_P (mode
)
921 && GET_CODE (op0
) == NOT
922 && trueop1
== const1_rtx
)
923 return gen_rtx_NEG (mode
, XEXP (op0
, 0));
925 /* Handle both-operands-constant cases. We can only add
926 CONST_INTs to constants since the sum of relocatable symbols
927 can't be handled by most assemblers. Don't add CONST_INT
928 to CONST_INT since overflow won't be computed properly if wider
929 than HOST_BITS_PER_WIDE_INT. */
931 if (CONSTANT_P (op0
) && GET_MODE (op0
) != VOIDmode
932 && GET_CODE (op1
) == CONST_INT
)
933 return plus_constant (op0
, INTVAL (op1
));
934 else if (CONSTANT_P (op1
) && GET_MODE (op1
) != VOIDmode
935 && GET_CODE (op0
) == CONST_INT
)
936 return plus_constant (op1
, INTVAL (op0
));
938 /* See if this is something like X * C - X or vice versa or
939 if the multiplication is written as a shift. If so, we can
940 distribute and make a new multiply, shift, or maybe just
941 have X (if C is 2 in the example above). But don't make
942 real multiply if we didn't have one before. */
944 if (! FLOAT_MODE_P (mode
))
946 HOST_WIDE_INT coeff0
= 1, coeff1
= 1;
947 rtx lhs
= op0
, rhs
= op1
;
950 if (GET_CODE (lhs
) == NEG
)
951 coeff0
= -1, lhs
= XEXP (lhs
, 0);
952 else if (GET_CODE (lhs
) == MULT
953 && GET_CODE (XEXP (lhs
, 1)) == CONST_INT
)
955 coeff0
= INTVAL (XEXP (lhs
, 1)), lhs
= XEXP (lhs
, 0);
958 else if (GET_CODE (lhs
) == ASHIFT
959 && GET_CODE (XEXP (lhs
, 1)) == CONST_INT
960 && INTVAL (XEXP (lhs
, 1)) >= 0
961 && INTVAL (XEXP (lhs
, 1)) < HOST_BITS_PER_WIDE_INT
)
963 coeff0
= ((HOST_WIDE_INT
) 1) << INTVAL (XEXP (lhs
, 1));
967 if (GET_CODE (rhs
) == NEG
)
968 coeff1
= -1, rhs
= XEXP (rhs
, 0);
969 else if (GET_CODE (rhs
) == MULT
970 && GET_CODE (XEXP (rhs
, 1)) == CONST_INT
)
972 coeff1
= INTVAL (XEXP (rhs
, 1)), rhs
= XEXP (rhs
, 0);
975 else if (GET_CODE (rhs
) == ASHIFT
976 && GET_CODE (XEXP (rhs
, 1)) == CONST_INT
977 && INTVAL (XEXP (rhs
, 1)) >= 0
978 && INTVAL (XEXP (rhs
, 1)) < HOST_BITS_PER_WIDE_INT
)
980 coeff1
= ((HOST_WIDE_INT
) 1) << INTVAL (XEXP (rhs
, 1));
984 if (rtx_equal_p (lhs
, rhs
))
986 tem
= simplify_gen_binary (MULT
, mode
, lhs
,
987 GEN_INT (coeff0
+ coeff1
));
988 return (GET_CODE (tem
) == MULT
&& ! had_mult
) ? 0 : tem
;
992 /* If one of the operands is a PLUS or a MINUS, see if we can
993 simplify this by the associative law.
994 Don't use the associative law for floating point.
995 The inaccuracy makes it nonassociative,
996 and subtle programs can break if operations are associated. */
998 if (INTEGRAL_MODE_P (mode
)
999 && (GET_CODE (op0
) == PLUS
|| GET_CODE (op0
) == MINUS
1000 || GET_CODE (op1
) == PLUS
|| GET_CODE (op1
) == MINUS
1001 || (GET_CODE (op0
) == CONST
1002 && GET_CODE (XEXP (op0
, 0)) == PLUS
)
1003 || (GET_CODE (op1
) == CONST
1004 && GET_CODE (XEXP (op1
, 0)) == PLUS
))
1005 && (tem
= simplify_plus_minus (code
, mode
, op0
, op1
, 0)) != 0)
1011 /* Convert (compare FOO (const_int 0)) to FOO unless we aren't
1012 using cc0, in which case we want to leave it as a COMPARE
1013 so we can distinguish it from a register-register-copy.
1015 In IEEE floating point, x-0 is not the same as x. */
1017 if ((TARGET_FLOAT_FORMAT
!= IEEE_FLOAT_FORMAT
1018 || ! FLOAT_MODE_P (mode
) || flag_unsafe_math_optimizations
)
1019 && trueop1
== CONST0_RTX (mode
))
1023 /* Convert (compare (gt (flags) 0) (lt (flags) 0)) to (flags). */
1024 if (((GET_CODE (op0
) == GT
&& GET_CODE (op1
) == LT
)
1025 || (GET_CODE (op0
) == GTU
&& GET_CODE (op1
) == LTU
))
1026 && XEXP (op0
, 1) == const0_rtx
&& XEXP (op1
, 1) == const0_rtx
)
1028 rtx xop00
= XEXP (op0
, 0);
1029 rtx xop10
= XEXP (op1
, 0);
1032 if (GET_CODE (xop00
) == CC0
&& GET_CODE (xop10
) == CC0
)
1034 if (GET_CODE (xop00
) == REG
&& GET_CODE (xop10
) == REG
1035 && GET_MODE (xop00
) == GET_MODE (xop10
)
1036 && REGNO (xop00
) == REGNO (xop10
)
1037 && GET_MODE_CLASS (GET_MODE (xop00
)) == MODE_CC
1038 && GET_MODE_CLASS (GET_MODE (xop10
)) == MODE_CC
)
1045 /* We can't assume x-x is 0 even with non-IEEE floating point,
1046 but since it is zero except in very strange circumstances, we
1047 will treat it as zero with -funsafe-math-optimizations. */
1048 if (rtx_equal_p (trueop0
, trueop1
)
1049 && ! side_effects_p (op0
)
1050 && (! FLOAT_MODE_P (mode
) || flag_unsafe_math_optimizations
))
1051 return CONST0_RTX (mode
);
1053 /* Change subtraction from zero into negation. (0 - x) is the
1054 same as -x when x is NaN, infinite, or finite and non-zero.
1055 But if the mode has signed zeros, and does not round towards
1056 -infinity, then 0 - 0 is 0, not -0. */
1057 if (!HONOR_SIGNED_ZEROS (mode
) && trueop0
== CONST0_RTX (mode
))
1058 return gen_rtx_NEG (mode
, op1
);
1060 /* (-1 - a) is ~a. */
1061 if (trueop0
== constm1_rtx
)
1062 return gen_rtx_NOT (mode
, op1
);
1064 /* Subtracting 0 has no effect unless the mode has signed zeros
1065 and supports rounding towards -infinity. In such a case,
1067 if (!(HONOR_SIGNED_ZEROS (mode
)
1068 && HONOR_SIGN_DEPENDENT_ROUNDING (mode
))
1069 && trueop1
== CONST0_RTX (mode
))
1072 /* See if this is something like X * C - X or vice versa or
1073 if the multiplication is written as a shift. If so, we can
1074 distribute and make a new multiply, shift, or maybe just
1075 have X (if C is 2 in the example above). But don't make
1076 real multiply if we didn't have one before. */
1078 if (! FLOAT_MODE_P (mode
))
1080 HOST_WIDE_INT coeff0
= 1, coeff1
= 1;
1081 rtx lhs
= op0
, rhs
= op1
;
1084 if (GET_CODE (lhs
) == NEG
)
1085 coeff0
= -1, lhs
= XEXP (lhs
, 0);
1086 else if (GET_CODE (lhs
) == MULT
1087 && GET_CODE (XEXP (lhs
, 1)) == CONST_INT
)
1089 coeff0
= INTVAL (XEXP (lhs
, 1)), lhs
= XEXP (lhs
, 0);
1092 else if (GET_CODE (lhs
) == ASHIFT
1093 && GET_CODE (XEXP (lhs
, 1)) == CONST_INT
1094 && INTVAL (XEXP (lhs
, 1)) >= 0
1095 && INTVAL (XEXP (lhs
, 1)) < HOST_BITS_PER_WIDE_INT
)
1097 coeff0
= ((HOST_WIDE_INT
) 1) << INTVAL (XEXP (lhs
, 1));
1098 lhs
= XEXP (lhs
, 0);
1101 if (GET_CODE (rhs
) == NEG
)
1102 coeff1
= - 1, rhs
= XEXP (rhs
, 0);
1103 else if (GET_CODE (rhs
) == MULT
1104 && GET_CODE (XEXP (rhs
, 1)) == CONST_INT
)
1106 coeff1
= INTVAL (XEXP (rhs
, 1)), rhs
= XEXP (rhs
, 0);
1109 else if (GET_CODE (rhs
) == ASHIFT
1110 && GET_CODE (XEXP (rhs
, 1)) == CONST_INT
1111 && INTVAL (XEXP (rhs
, 1)) >= 0
1112 && INTVAL (XEXP (rhs
, 1)) < HOST_BITS_PER_WIDE_INT
)
1114 coeff1
= ((HOST_WIDE_INT
) 1) << INTVAL (XEXP (rhs
, 1));
1115 rhs
= XEXP (rhs
, 0);
1118 if (rtx_equal_p (lhs
, rhs
))
1120 tem
= simplify_gen_binary (MULT
, mode
, lhs
,
1121 GEN_INT (coeff0
- coeff1
));
1122 return (GET_CODE (tem
) == MULT
&& ! had_mult
) ? 0 : tem
;
1126 /* (a - (-b)) -> (a + b). True even for IEEE. */
1127 if (GET_CODE (op1
) == NEG
)
1128 return simplify_gen_binary (PLUS
, mode
, op0
, XEXP (op1
, 0));
1130 /* If one of the operands is a PLUS or a MINUS, see if we can
1131 simplify this by the associative law.
1132 Don't use the associative law for floating point.
1133 The inaccuracy makes it nonassociative,
1134 and subtle programs can break if operations are associated. */
1136 if (INTEGRAL_MODE_P (mode
)
1137 && (GET_CODE (op0
) == PLUS
|| GET_CODE (op0
) == MINUS
1138 || GET_CODE (op1
) == PLUS
|| GET_CODE (op1
) == MINUS
1139 || (GET_CODE (op0
) == CONST
1140 && GET_CODE (XEXP (op0
, 0)) == PLUS
)
1141 || (GET_CODE (op1
) == CONST
1142 && GET_CODE (XEXP (op1
, 0)) == PLUS
))
1143 && (tem
= simplify_plus_minus (code
, mode
, op0
, op1
, 0)) != 0)
1146 /* Don't let a relocatable value get a negative coeff. */
1147 if (GET_CODE (op1
) == CONST_INT
&& GET_MODE (op0
) != VOIDmode
)
1148 return simplify_gen_binary (PLUS
, mode
,
1150 neg_const_int (mode
, op1
));
1152 /* (x - (x & y)) -> (x & ~y) */
1153 if (GET_CODE (op1
) == AND
)
1155 if (rtx_equal_p (op0
, XEXP (op1
, 0)))
1156 return simplify_gen_binary (AND
, mode
, op0
,
1157 gen_rtx_NOT (mode
, XEXP (op1
, 1)));
1158 if (rtx_equal_p (op0
, XEXP (op1
, 1)))
1159 return simplify_gen_binary (AND
, mode
, op0
,
1160 gen_rtx_NOT (mode
, XEXP (op1
, 0)));
1165 if (trueop1
== constm1_rtx
)
1167 tem
= simplify_unary_operation (NEG
, mode
, op0
, mode
);
1169 return tem
? tem
: gen_rtx_NEG (mode
, op0
);
1172 /* Maybe simplify x * 0 to 0. The reduction is not valid if
1173 x is NaN, since x * 0 is then also NaN. Nor is it valid
1174 when the mode has signed zeros, since multiplying a negative
1175 number by 0 will give -0, not 0. */
1176 if (!HONOR_NANS (mode
)
1177 && !HONOR_SIGNED_ZEROS (mode
)
1178 && trueop1
== CONST0_RTX (mode
)
1179 && ! side_effects_p (op0
))
1182 /* In IEEE floating point, x*1 is not equivalent to x for
1184 if (!HONOR_SNANS (mode
)
1185 && trueop1
== CONST1_RTX (mode
))
1188 /* Convert multiply by constant power of two into shift unless
1189 we are still generating RTL. This test is a kludge. */
1190 if (GET_CODE (trueop1
) == CONST_INT
1191 && (val
= exact_log2 (INTVAL (trueop1
))) >= 0
1192 /* If the mode is larger than the host word size, and the
1193 uppermost bit is set, then this isn't a power of two due
1194 to implicit sign extension. */
1195 && (width
<= HOST_BITS_PER_WIDE_INT
1196 || val
!= HOST_BITS_PER_WIDE_INT
- 1)
1197 && ! rtx_equal_function_value_matters
)
1198 return gen_rtx_ASHIFT (mode
, op0
, GEN_INT (val
));
1200 /* x*2 is x+x and x*(-1) is -x */
1201 if (GET_CODE (trueop1
) == CONST_DOUBLE
1202 && GET_MODE_CLASS (GET_MODE (trueop1
)) == MODE_FLOAT
1203 && GET_MODE (op0
) == mode
)
1206 REAL_VALUE_FROM_CONST_DOUBLE (d
, trueop1
);
1208 if (REAL_VALUES_EQUAL (d
, dconst2
))
1209 return gen_rtx_PLUS (mode
, op0
, copy_rtx (op0
));
1211 if (REAL_VALUES_EQUAL (d
, dconstm1
))
1212 return gen_rtx_NEG (mode
, op0
);
1217 if (trueop1
== const0_rtx
)
1219 if (GET_CODE (trueop1
) == CONST_INT
1220 && ((INTVAL (trueop1
) & GET_MODE_MASK (mode
))
1221 == GET_MODE_MASK (mode
)))
1223 if (rtx_equal_p (trueop0
, trueop1
) && ! side_effects_p (op0
))
1225 /* A | (~A) -> -1 */
1226 if (((GET_CODE (op0
) == NOT
&& rtx_equal_p (XEXP (op0
, 0), op1
))
1227 || (GET_CODE (op1
) == NOT
&& rtx_equal_p (XEXP (op1
, 0), op0
)))
1228 && ! side_effects_p (op0
)
1229 && GET_MODE_CLASS (mode
) != MODE_CC
)
1234 if (trueop1
== const0_rtx
)
1236 if (GET_CODE (trueop1
) == CONST_INT
1237 && ((INTVAL (trueop1
) & GET_MODE_MASK (mode
))
1238 == GET_MODE_MASK (mode
)))
1239 return gen_rtx_NOT (mode
, op0
);
1240 if (trueop0
== trueop1
&& ! side_effects_p (op0
)
1241 && GET_MODE_CLASS (mode
) != MODE_CC
)
1246 if (trueop1
== const0_rtx
&& ! side_effects_p (op0
))
1248 if (GET_CODE (trueop1
) == CONST_INT
1249 && ((INTVAL (trueop1
) & GET_MODE_MASK (mode
))
1250 == GET_MODE_MASK (mode
)))
1252 if (trueop0
== trueop1
&& ! side_effects_p (op0
)
1253 && GET_MODE_CLASS (mode
) != MODE_CC
)
1256 if (((GET_CODE (op0
) == NOT
&& rtx_equal_p (XEXP (op0
, 0), op1
))
1257 || (GET_CODE (op1
) == NOT
&& rtx_equal_p (XEXP (op1
, 0), op0
)))
1258 && ! side_effects_p (op0
)
1259 && GET_MODE_CLASS (mode
) != MODE_CC
)
1264 /* Convert divide by power of two into shift (divide by 1 handled
1266 if (GET_CODE (trueop1
) == CONST_INT
1267 && (arg1
= exact_log2 (INTVAL (trueop1
))) > 0)
1268 return gen_rtx_LSHIFTRT (mode
, op0
, GEN_INT (arg1
));
1270 /* ... fall through ... */
1273 if (trueop1
== CONST1_RTX (mode
))
1275 /* On some platforms DIV uses narrower mode than its
1277 rtx x
= gen_lowpart_common (mode
, op0
);
1280 else if (mode
!= GET_MODE (op0
) && GET_MODE (op0
) != VOIDmode
)
1281 return gen_lowpart_SUBREG (mode
, op0
);
1286 /* Maybe change 0 / x to 0. This transformation isn't safe for
1287 modes with NaNs, since 0 / 0 will then be NaN rather than 0.
1288 Nor is it safe for modes with signed zeros, since dividing
1289 0 by a negative number gives -0, not 0. */
1290 if (!HONOR_NANS (mode
)
1291 && !HONOR_SIGNED_ZEROS (mode
)
1292 && trueop0
== CONST0_RTX (mode
)
1293 && ! side_effects_p (op1
))
1296 /* Change division by a constant into multiplication. Only do
1297 this with -funsafe-math-optimizations. */
1298 else if (GET_CODE (trueop1
) == CONST_DOUBLE
1299 && GET_MODE_CLASS (GET_MODE (trueop1
)) == MODE_FLOAT
1300 && trueop1
!= CONST0_RTX (mode
)
1301 && flag_unsafe_math_optimizations
)
1304 REAL_VALUE_FROM_CONST_DOUBLE (d
, trueop1
);
1306 if (! REAL_VALUES_EQUAL (d
, dconst0
))
1308 REAL_ARITHMETIC (d
, rtx_to_tree_code (DIV
), dconst1
, d
);
1309 return gen_rtx_MULT (mode
, op0
,
1310 CONST_DOUBLE_FROM_REAL_VALUE (d
, mode
));
1316 /* Handle modulus by power of two (mod with 1 handled below). */
1317 if (GET_CODE (trueop1
) == CONST_INT
1318 && exact_log2 (INTVAL (trueop1
)) > 0)
1319 return gen_rtx_AND (mode
, op0
, GEN_INT (INTVAL (op1
) - 1));
1321 /* ... fall through ... */
1324 if ((trueop0
== const0_rtx
|| trueop1
== const1_rtx
)
1325 && ! side_effects_p (op0
) && ! side_effects_p (op1
))
1331 /* Rotating ~0 always results in ~0. */
1332 if (GET_CODE (trueop0
) == CONST_INT
&& width
<= HOST_BITS_PER_WIDE_INT
1333 && (unsigned HOST_WIDE_INT
) INTVAL (trueop0
) == GET_MODE_MASK (mode
)
1334 && ! side_effects_p (op1
))
1337 /* ... fall through ... */
1342 if (trueop1
== const0_rtx
)
1344 if (trueop0
== const0_rtx
&& ! side_effects_p (op1
))
1349 if (width
<= HOST_BITS_PER_WIDE_INT
&& GET_CODE (trueop1
) == CONST_INT
1350 && INTVAL (trueop1
) == (HOST_WIDE_INT
) 1 << (width
-1)
1351 && ! side_effects_p (op0
))
1353 else if (rtx_equal_p (trueop0
, trueop1
) && ! side_effects_p (op0
))
1358 if (width
<= HOST_BITS_PER_WIDE_INT
&& GET_CODE (trueop1
) == CONST_INT
1359 && ((unsigned HOST_WIDE_INT
) INTVAL (trueop1
)
1360 == (unsigned HOST_WIDE_INT
) GET_MODE_MASK (mode
) >> 1)
1361 && ! side_effects_p (op0
))
1363 else if (rtx_equal_p (trueop0
, trueop1
) && ! side_effects_p (op0
))
1368 if (trueop1
== const0_rtx
&& ! side_effects_p (op0
))
1370 else if (rtx_equal_p (trueop0
, trueop1
) && ! side_effects_p (op0
))
1375 if (trueop1
== constm1_rtx
&& ! side_effects_p (op0
))
1377 else if (rtx_equal_p (trueop0
, trueop1
) && ! side_effects_p (op0
))
1385 /* ??? There are simplifications that can be done. */
1395 /* Get the integer argument values in two forms:
1396 zero-extended in ARG0, ARG1 and sign-extended in ARG0S, ARG1S. */
1398 arg0
= INTVAL (trueop0
);
1399 arg1
= INTVAL (trueop1
);
1401 if (width
< HOST_BITS_PER_WIDE_INT
)
1403 arg0
&= ((HOST_WIDE_INT
) 1 << width
) - 1;
1404 arg1
&= ((HOST_WIDE_INT
) 1 << width
) - 1;
1407 if (arg0s
& ((HOST_WIDE_INT
) 1 << (width
- 1)))
1408 arg0s
|= ((HOST_WIDE_INT
) (-1) << width
);
1411 if (arg1s
& ((HOST_WIDE_INT
) 1 << (width
- 1)))
1412 arg1s
|= ((HOST_WIDE_INT
) (-1) << width
);
1420 /* Compute the value of the arithmetic. */
1425 val
= arg0s
+ arg1s
;
1429 val
= arg0s
- arg1s
;
1433 val
= arg0s
* arg1s
;
1438 || (arg0s
== (HOST_WIDE_INT
) 1 << (HOST_BITS_PER_WIDE_INT
- 1)
1441 val
= arg0s
/ arg1s
;
1446 || (arg0s
== (HOST_WIDE_INT
) 1 << (HOST_BITS_PER_WIDE_INT
- 1)
1449 val
= arg0s
% arg1s
;
1454 || (arg0s
== (HOST_WIDE_INT
) 1 << (HOST_BITS_PER_WIDE_INT
- 1)
1457 val
= (unsigned HOST_WIDE_INT
) arg0
/ arg1
;
1462 || (arg0s
== (HOST_WIDE_INT
) 1 << (HOST_BITS_PER_WIDE_INT
- 1)
1465 val
= (unsigned HOST_WIDE_INT
) arg0
% arg1
;
1481 /* If shift count is undefined, don't fold it; let the machine do
1482 what it wants. But truncate it if the machine will do that. */
1486 #ifdef SHIFT_COUNT_TRUNCATED
1487 if (SHIFT_COUNT_TRUNCATED
)
1491 val
= ((unsigned HOST_WIDE_INT
) arg0
) >> arg1
;
1498 #ifdef SHIFT_COUNT_TRUNCATED
1499 if (SHIFT_COUNT_TRUNCATED
)
1503 val
= ((unsigned HOST_WIDE_INT
) arg0
) << arg1
;
1510 #ifdef SHIFT_COUNT_TRUNCATED
1511 if (SHIFT_COUNT_TRUNCATED
)
1515 val
= arg0s
>> arg1
;
1517 /* Bootstrap compiler may not have sign extended the right shift.
1518 Manually extend the sign to insure bootstrap cc matches gcc. */
1519 if (arg0s
< 0 && arg1
> 0)
1520 val
|= ((HOST_WIDE_INT
) -1) << (HOST_BITS_PER_WIDE_INT
- arg1
);
1529 val
= ((((unsigned HOST_WIDE_INT
) arg0
) << (width
- arg1
))
1530 | (((unsigned HOST_WIDE_INT
) arg0
) >> arg1
));
1538 val
= ((((unsigned HOST_WIDE_INT
) arg0
) << arg1
)
1539 | (((unsigned HOST_WIDE_INT
) arg0
) >> (width
- arg1
)));
1543 /* Do nothing here. */
1547 val
= arg0s
<= arg1s
? arg0s
: arg1s
;
1551 val
= ((unsigned HOST_WIDE_INT
) arg0
1552 <= (unsigned HOST_WIDE_INT
) arg1
? arg0
: arg1
);
1556 val
= arg0s
> arg1s
? arg0s
: arg1s
;
1560 val
= ((unsigned HOST_WIDE_INT
) arg0
1561 > (unsigned HOST_WIDE_INT
) arg1
? arg0
: arg1
);
1568 val
= trunc_int_for_mode (val
, mode
);
1570 return GEN_INT (val
);
1573 /* Simplify a PLUS or MINUS, at least one of whose operands may be another
1576 Rather than test for specific case, we do this by a brute-force method
1577 and do all possible simplifications until no more changes occur. Then
1578 we rebuild the operation.
1580 If FORCE is true, then always generate the rtx. This is used to
1581 canonicalize stuff emitted from simplify_gen_binary. Note that this
1582 can still fail if the rtx is too complex. It won't fail just because
1583 the result is not 'simpler' than the input, however. */
1585 struct simplify_plus_minus_op_data
1592 simplify_plus_minus_op_data_cmp (p1
, p2
)
1596 const struct simplify_plus_minus_op_data
*d1
= p1
;
1597 const struct simplify_plus_minus_op_data
*d2
= p2
;
1599 return (commutative_operand_precedence (d2
->op
)
1600 - commutative_operand_precedence (d1
->op
));
1604 simplify_plus_minus (code
, mode
, op0
, op1
, force
)
1606 enum machine_mode mode
;
1610 struct simplify_plus_minus_op_data ops
[8];
1612 int n_ops
= 2, input_ops
= 2, input_consts
= 0, n_consts
;
1613 int first
, negate
, changed
;
1616 memset ((char *) ops
, 0, sizeof ops
);
1618 /* Set up the two operands and then expand them until nothing has been
1619 changed. If we run out of room in our array, give up; this should
1620 almost never happen. */
1625 ops
[1].neg
= (code
== MINUS
);
1631 for (i
= 0; i
< n_ops
; i
++)
1633 rtx this_op
= ops
[i
].op
;
1634 int this_neg
= ops
[i
].neg
;
1635 enum rtx_code this_code
= GET_CODE (this_op
);
1644 ops
[n_ops
].op
= XEXP (this_op
, 1);
1645 ops
[n_ops
].neg
= (this_code
== MINUS
) ^ this_neg
;
1648 ops
[i
].op
= XEXP (this_op
, 0);
1654 ops
[i
].op
= XEXP (this_op
, 0);
1655 ops
[i
].neg
= ! this_neg
;
1661 && GET_CODE (XEXP (this_op
, 0)) == PLUS
1662 && CONSTANT_P (XEXP (XEXP (this_op
, 0), 0))
1663 && CONSTANT_P (XEXP (XEXP (this_op
, 0), 1)))
1665 ops
[i
].op
= XEXP (XEXP (this_op
, 0), 0);
1666 ops
[n_ops
].op
= XEXP (XEXP (this_op
, 0), 1);
1667 ops
[n_ops
].neg
= this_neg
;
1675 /* ~a -> (-a - 1) */
1678 ops
[n_ops
].op
= constm1_rtx
;
1679 ops
[n_ops
++].neg
= this_neg
;
1680 ops
[i
].op
= XEXP (this_op
, 0);
1681 ops
[i
].neg
= !this_neg
;
1689 ops
[i
].op
= neg_const_int (mode
, this_op
);
1702 /* If we only have two operands, we can't do anything. */
1703 if (n_ops
<= 2 && !force
)
1706 /* Count the number of CONSTs we didn't split above. */
1707 for (i
= 0; i
< n_ops
; i
++)
1708 if (GET_CODE (ops
[i
].op
) == CONST
)
1711 /* Now simplify each pair of operands until nothing changes. The first
1712 time through just simplify constants against each other. */
1719 for (i
= 0; i
< n_ops
- 1; i
++)
1720 for (j
= i
+ 1; j
< n_ops
; j
++)
1722 rtx lhs
= ops
[i
].op
, rhs
= ops
[j
].op
;
1723 int lneg
= ops
[i
].neg
, rneg
= ops
[j
].neg
;
1725 if (lhs
!= 0 && rhs
!= 0
1726 && (! first
|| (CONSTANT_P (lhs
) && CONSTANT_P (rhs
))))
1728 enum rtx_code ncode
= PLUS
;
1734 tem
= lhs
, lhs
= rhs
, rhs
= tem
;
1736 else if (swap_commutative_operands_p (lhs
, rhs
))
1737 tem
= lhs
, lhs
= rhs
, rhs
= tem
;
1739 tem
= simplify_binary_operation (ncode
, mode
, lhs
, rhs
);
1741 /* Reject "simplifications" that just wrap the two
1742 arguments in a CONST. Failure to do so can result
1743 in infinite recursion with simplify_binary_operation
1744 when it calls us to simplify CONST operations. */
1746 && ! (GET_CODE (tem
) == CONST
1747 && GET_CODE (XEXP (tem
, 0)) == ncode
1748 && XEXP (XEXP (tem
, 0), 0) == lhs
1749 && XEXP (XEXP (tem
, 0), 1) == rhs
)
1750 /* Don't allow -x + -1 -> ~x simplifications in the
1751 first pass. This allows us the chance to combine
1752 the -1 with other constants. */
1754 && GET_CODE (tem
) == NOT
1755 && XEXP (tem
, 0) == rhs
))
1758 if (GET_CODE (tem
) == NEG
)
1759 tem
= XEXP (tem
, 0), lneg
= !lneg
;
1760 if (GET_CODE (tem
) == CONST_INT
&& lneg
)
1761 tem
= neg_const_int (mode
, tem
), lneg
= 0;
1765 ops
[j
].op
= NULL_RTX
;
1775 /* Pack all the operands to the lower-numbered entries. */
1776 for (i
= 0, j
= 0; j
< n_ops
; j
++)
1781 /* Sort the operations based on swap_commutative_operands_p. */
1782 qsort (ops
, n_ops
, sizeof (*ops
), simplify_plus_minus_op_data_cmp
);
1784 /* We suppressed creation of trivial CONST expressions in the
1785 combination loop to avoid recursion. Create one manually now.
1786 The combination loop should have ensured that there is exactly
1787 one CONST_INT, and the sort will have ensured that it is last
1788 in the array and that any other constant will be next-to-last. */
1791 && GET_CODE (ops
[n_ops
- 1].op
) == CONST_INT
1792 && CONSTANT_P (ops
[n_ops
- 2].op
))
1794 rtx value
= ops
[n_ops
- 1].op
;
1795 if (ops
[n_ops
- 1].neg
^ ops
[n_ops
- 2].neg
)
1796 value
= neg_const_int (mode
, value
);
1797 ops
[n_ops
- 2].op
= plus_constant (ops
[n_ops
- 2].op
, INTVAL (value
));
1801 /* Count the number of CONSTs that we generated. */
1803 for (i
= 0; i
< n_ops
; i
++)
1804 if (GET_CODE (ops
[i
].op
) == CONST
)
1807 /* Give up if we didn't reduce the number of operands we had. Make
1808 sure we count a CONST as two operands. If we have the same
1809 number of operands, but have made more CONSTs than before, this
1810 is also an improvement, so accept it. */
1812 && (n_ops
+ n_consts
> input_ops
1813 || (n_ops
+ n_consts
== input_ops
&& n_consts
<= input_consts
)))
1816 /* Put a non-negated operand first. If there aren't any, make all
1817 operands positive and negate the whole thing later. */
1820 for (i
= 0; i
< n_ops
&& ops
[i
].neg
; i
++)
1824 for (i
= 0; i
< n_ops
; i
++)
1836 /* Now make the result by performing the requested operations. */
1838 for (i
= 1; i
< n_ops
; i
++)
1839 result
= gen_rtx_fmt_ee (ops
[i
].neg
? MINUS
: PLUS
,
1840 mode
, result
, ops
[i
].op
);
1842 return negate
? gen_rtx_NEG (mode
, result
) : result
;
1845 /* Like simplify_binary_operation except used for relational operators.
1846 MODE is the mode of the operands, not that of the result. If MODE
1847 is VOIDmode, both operands must also be VOIDmode and we compare the
1848 operands in "infinite precision".
1850 If no simplification is possible, this function returns zero. Otherwise,
1851 it returns either const_true_rtx or const0_rtx. */
1854 simplify_relational_operation (code
, mode
, op0
, op1
)
1856 enum machine_mode mode
;
1859 int equal
, op0lt
, op0ltu
, op1lt
, op1ltu
;
1864 if (mode
== VOIDmode
1865 && (GET_MODE (op0
) != VOIDmode
1866 || GET_MODE (op1
) != VOIDmode
))
1869 /* If op0 is a compare, extract the comparison arguments from it. */
1870 if (GET_CODE (op0
) == COMPARE
&& op1
== const0_rtx
)
1871 op1
= XEXP (op0
, 1), op0
= XEXP (op0
, 0);
1873 trueop0
= avoid_constant_pool_reference (op0
);
1874 trueop1
= avoid_constant_pool_reference (op1
);
1876 /* We can't simplify MODE_CC values since we don't know what the
1877 actual comparison is. */
1878 if (GET_MODE_CLASS (GET_MODE (op0
)) == MODE_CC
1885 /* Make sure the constant is second. */
1886 if (swap_commutative_operands_p (trueop0
, trueop1
))
1888 tem
= op0
, op0
= op1
, op1
= tem
;
1889 tem
= trueop0
, trueop0
= trueop1
, trueop1
= tem
;
1890 code
= swap_condition (code
);
1893 /* For integer comparisons of A and B maybe we can simplify A - B and can
1894 then simplify a comparison of that with zero. If A and B are both either
1895 a register or a CONST_INT, this can't help; testing for these cases will
1896 prevent infinite recursion here and speed things up.
1898 If CODE is an unsigned comparison, then we can never do this optimization,
1899 because it gives an incorrect result if the subtraction wraps around zero.
1900 ANSI C defines unsigned operations such that they never overflow, and
1901 thus such cases can not be ignored. */
1903 if (INTEGRAL_MODE_P (mode
) && trueop1
!= const0_rtx
1904 && ! ((GET_CODE (op0
) == REG
|| GET_CODE (trueop0
) == CONST_INT
)
1905 && (GET_CODE (op1
) == REG
|| GET_CODE (trueop1
) == CONST_INT
))
1906 && 0 != (tem
= simplify_binary_operation (MINUS
, mode
, op0
, op1
))
1907 && code
!= GTU
&& code
!= GEU
&& code
!= LTU
&& code
!= LEU
)
1908 return simplify_relational_operation (signed_condition (code
),
1909 mode
, tem
, const0_rtx
);
1911 if (flag_unsafe_math_optimizations
&& code
== ORDERED
)
1912 return const_true_rtx
;
1914 if (flag_unsafe_math_optimizations
&& code
== UNORDERED
)
1917 /* For modes without NaNs, if the two operands are equal, we know the
1919 if (!HONOR_NANS (GET_MODE (trueop0
)) && rtx_equal_p (trueop0
, trueop1
))
1920 equal
= 1, op0lt
= 0, op0ltu
= 0, op1lt
= 0, op1ltu
= 0;
1922 /* If the operands are floating-point constants, see if we can fold
1924 else if (GET_CODE (trueop0
) == CONST_DOUBLE
1925 && GET_CODE (trueop1
) == CONST_DOUBLE
1926 && GET_MODE_CLASS (GET_MODE (trueop0
)) == MODE_FLOAT
)
1928 REAL_VALUE_TYPE d0
, d1
;
1930 REAL_VALUE_FROM_CONST_DOUBLE (d0
, trueop0
);
1931 REAL_VALUE_FROM_CONST_DOUBLE (d1
, trueop1
);
1933 /* Comparisons are unordered iff at least one of the values is NaN. */
1934 if (REAL_VALUE_ISNAN (d0
) || REAL_VALUE_ISNAN (d1
))
1944 return const_true_rtx
;
1957 equal
= REAL_VALUES_EQUAL (d0
, d1
);
1958 op0lt
= op0ltu
= REAL_VALUES_LESS (d0
, d1
);
1959 op1lt
= op1ltu
= REAL_VALUES_LESS (d1
, d0
);
1962 /* Otherwise, see if the operands are both integers. */
1963 else if ((GET_MODE_CLASS (mode
) == MODE_INT
|| mode
== VOIDmode
)
1964 && (GET_CODE (trueop0
) == CONST_DOUBLE
1965 || GET_CODE (trueop0
) == CONST_INT
)
1966 && (GET_CODE (trueop1
) == CONST_DOUBLE
1967 || GET_CODE (trueop1
) == CONST_INT
))
1969 int width
= GET_MODE_BITSIZE (mode
);
1970 HOST_WIDE_INT l0s
, h0s
, l1s
, h1s
;
1971 unsigned HOST_WIDE_INT l0u
, h0u
, l1u
, h1u
;
1973 /* Get the two words comprising each integer constant. */
1974 if (GET_CODE (trueop0
) == CONST_DOUBLE
)
1976 l0u
= l0s
= CONST_DOUBLE_LOW (trueop0
);
1977 h0u
= h0s
= CONST_DOUBLE_HIGH (trueop0
);
1981 l0u
= l0s
= INTVAL (trueop0
);
1982 h0u
= h0s
= HWI_SIGN_EXTEND (l0s
);
1985 if (GET_CODE (trueop1
) == CONST_DOUBLE
)
1987 l1u
= l1s
= CONST_DOUBLE_LOW (trueop1
);
1988 h1u
= h1s
= CONST_DOUBLE_HIGH (trueop1
);
1992 l1u
= l1s
= INTVAL (trueop1
);
1993 h1u
= h1s
= HWI_SIGN_EXTEND (l1s
);
1996 /* If WIDTH is nonzero and smaller than HOST_BITS_PER_WIDE_INT,
1997 we have to sign or zero-extend the values. */
1998 if (width
!= 0 && width
< HOST_BITS_PER_WIDE_INT
)
2000 l0u
&= ((HOST_WIDE_INT
) 1 << width
) - 1;
2001 l1u
&= ((HOST_WIDE_INT
) 1 << width
) - 1;
2003 if (l0s
& ((HOST_WIDE_INT
) 1 << (width
- 1)))
2004 l0s
|= ((HOST_WIDE_INT
) (-1) << width
);
2006 if (l1s
& ((HOST_WIDE_INT
) 1 << (width
- 1)))
2007 l1s
|= ((HOST_WIDE_INT
) (-1) << width
);
2009 if (width
!= 0 && width
<= HOST_BITS_PER_WIDE_INT
)
2010 h0u
= h1u
= 0, h0s
= HWI_SIGN_EXTEND (l0s
), h1s
= HWI_SIGN_EXTEND (l1s
);
2012 equal
= (h0u
== h1u
&& l0u
== l1u
);
2013 op0lt
= (h0s
< h1s
|| (h0s
== h1s
&& l0u
< l1u
));
2014 op1lt
= (h1s
< h0s
|| (h1s
== h0s
&& l1u
< l0u
));
2015 op0ltu
= (h0u
< h1u
|| (h0u
== h1u
&& l0u
< l1u
));
2016 op1ltu
= (h1u
< h0u
|| (h1u
== h0u
&& l1u
< l0u
));
2019 /* Otherwise, there are some code-specific tests we can make. */
2025 /* References to the frame plus a constant or labels cannot
2026 be zero, but a SYMBOL_REF can due to #pragma weak. */
2027 if (((NONZERO_BASE_PLUS_P (op0
) && trueop1
== const0_rtx
)
2028 || GET_CODE (trueop0
) == LABEL_REF
)
2029 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2030 /* On some machines, the ap reg can be 0 sometimes. */
2031 && op0
!= arg_pointer_rtx
2038 if (((NONZERO_BASE_PLUS_P (op0
) && trueop1
== const0_rtx
)
2039 || GET_CODE (trueop0
) == LABEL_REF
)
2040 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2041 && op0
!= arg_pointer_rtx
2044 return const_true_rtx
;
2048 /* Unsigned values are never negative. */
2049 if (trueop1
== const0_rtx
)
2050 return const_true_rtx
;
2054 if (trueop1
== const0_rtx
)
2059 /* Unsigned values are never greater than the largest
2061 if (GET_CODE (trueop1
) == CONST_INT
2062 && (unsigned HOST_WIDE_INT
) INTVAL (trueop1
) == GET_MODE_MASK (mode
)
2063 && INTEGRAL_MODE_P (mode
))
2064 return const_true_rtx
;
2068 if (GET_CODE (trueop1
) == CONST_INT
2069 && (unsigned HOST_WIDE_INT
) INTVAL (trueop1
) == GET_MODE_MASK (mode
)
2070 && INTEGRAL_MODE_P (mode
))
2075 /* Optimize abs(x) < 0.0. */
2076 if (trueop1
== CONST0_RTX (mode
) && !HONOR_SNANS (mode
))
2078 tem
= GET_CODE (trueop0
) == FLOAT_EXTEND
? XEXP (trueop0
, 0)
2080 if (GET_CODE (tem
) == ABS
)
2086 /* Optimize abs(x) >= 0.0. */
2087 if (trueop1
== CONST0_RTX (mode
) && !HONOR_NANS (mode
))
2089 tem
= GET_CODE (trueop0
) == FLOAT_EXTEND
? XEXP (trueop0
, 0)
2091 if (GET_CODE (tem
) == ABS
)
2103 /* If we reach here, EQUAL, OP0LT, OP0LTU, OP1LT, and OP1LTU are set
2109 return equal
? const_true_rtx
: const0_rtx
;
2112 return ! equal
? const_true_rtx
: const0_rtx
;
2115 return op0lt
? const_true_rtx
: const0_rtx
;
2118 return op1lt
? const_true_rtx
: const0_rtx
;
2120 return op0ltu
? const_true_rtx
: const0_rtx
;
2122 return op1ltu
? const_true_rtx
: const0_rtx
;
2125 return equal
|| op0lt
? const_true_rtx
: const0_rtx
;
2128 return equal
|| op1lt
? const_true_rtx
: const0_rtx
;
2130 return equal
|| op0ltu
? const_true_rtx
: const0_rtx
;
2132 return equal
|| op1ltu
? const_true_rtx
: const0_rtx
;
2134 return const_true_rtx
;
2142 /* Simplify CODE, an operation with result mode MODE and three operands,
2143 OP0, OP1, and OP2. OP0_MODE was the mode of OP0 before it became
2144 a constant. Return 0 if no simplifications is possible. */
2147 simplify_ternary_operation (code
, mode
, op0_mode
, op0
, op1
, op2
)
2149 enum machine_mode mode
, op0_mode
;
2152 unsigned int width
= GET_MODE_BITSIZE (mode
);
2154 /* VOIDmode means "infinite" precision. */
2156 width
= HOST_BITS_PER_WIDE_INT
;
2162 if (GET_CODE (op0
) == CONST_INT
2163 && GET_CODE (op1
) == CONST_INT
2164 && GET_CODE (op2
) == CONST_INT
2165 && ((unsigned) INTVAL (op1
) + (unsigned) INTVAL (op2
) <= width
)
2166 && width
<= (unsigned) HOST_BITS_PER_WIDE_INT
)
2168 /* Extracting a bit-field from a constant */
2169 HOST_WIDE_INT val
= INTVAL (op0
);
2171 if (BITS_BIG_ENDIAN
)
2172 val
>>= (GET_MODE_BITSIZE (op0_mode
)
2173 - INTVAL (op2
) - INTVAL (op1
));
2175 val
>>= INTVAL (op2
);
2177 if (HOST_BITS_PER_WIDE_INT
!= INTVAL (op1
))
2179 /* First zero-extend. */
2180 val
&= ((HOST_WIDE_INT
) 1 << INTVAL (op1
)) - 1;
2181 /* If desired, propagate sign bit. */
2182 if (code
== SIGN_EXTRACT
2183 && (val
& ((HOST_WIDE_INT
) 1 << (INTVAL (op1
) - 1))))
2184 val
|= ~ (((HOST_WIDE_INT
) 1 << INTVAL (op1
)) - 1);
2187 /* Clear the bits that don't belong in our mode,
2188 unless they and our sign bit are all one.
2189 So we get either a reasonable negative value or a reasonable
2190 unsigned value for this mode. */
2191 if (width
< HOST_BITS_PER_WIDE_INT
2192 && ((val
& ((HOST_WIDE_INT
) (-1) << (width
- 1)))
2193 != ((HOST_WIDE_INT
) (-1) << (width
- 1))))
2194 val
&= ((HOST_WIDE_INT
) 1 << width
) - 1;
2196 return GEN_INT (val
);
2201 if (GET_CODE (op0
) == CONST_INT
)
2202 return op0
!= const0_rtx
? op1
: op2
;
2204 /* Convert a == b ? b : a to "a". */
2205 if (GET_CODE (op0
) == NE
&& ! side_effects_p (op0
)
2206 && !HONOR_NANS (mode
)
2207 && rtx_equal_p (XEXP (op0
, 0), op1
)
2208 && rtx_equal_p (XEXP (op0
, 1), op2
))
2210 else if (GET_CODE (op0
) == EQ
&& ! side_effects_p (op0
)
2211 && !HONOR_NANS (mode
)
2212 && rtx_equal_p (XEXP (op0
, 1), op1
)
2213 && rtx_equal_p (XEXP (op0
, 0), op2
))
2215 else if (GET_RTX_CLASS (GET_CODE (op0
)) == '<' && ! side_effects_p (op0
))
2217 enum machine_mode cmp_mode
= (GET_MODE (XEXP (op0
, 0)) == VOIDmode
2218 ? GET_MODE (XEXP (op0
, 1))
2219 : GET_MODE (XEXP (op0
, 0)));
2221 if (cmp_mode
== VOIDmode
)
2222 cmp_mode
= op0_mode
;
2223 temp
= simplify_relational_operation (GET_CODE (op0
), cmp_mode
,
2224 XEXP (op0
, 0), XEXP (op0
, 1));
2226 /* See if any simplifications were possible. */
2227 if (temp
== const0_rtx
)
2229 else if (temp
== const1_rtx
)
2234 /* Look for happy constants in op1 and op2. */
2235 if (GET_CODE (op1
) == CONST_INT
&& GET_CODE (op2
) == CONST_INT
)
2237 HOST_WIDE_INT t
= INTVAL (op1
);
2238 HOST_WIDE_INT f
= INTVAL (op2
);
2240 if (t
== STORE_FLAG_VALUE
&& f
== 0)
2241 code
= GET_CODE (op0
);
2242 else if (t
== 0 && f
== STORE_FLAG_VALUE
)
2245 tmp
= reversed_comparison_code (op0
, NULL_RTX
);
2253 return gen_rtx_fmt_ee (code
, mode
, XEXP (op0
, 0), XEXP (op0
, 1));
2265 /* Simplify SUBREG:OUTERMODE(OP:INNERMODE, BYTE)
2266 Return 0 if no simplifications is possible. */
2268 simplify_subreg (outermode
, op
, innermode
, byte
)
2271 enum machine_mode outermode
, innermode
;
2273 /* Little bit of sanity checking. */
2274 if (innermode
== VOIDmode
|| outermode
== VOIDmode
2275 || innermode
== BLKmode
|| outermode
== BLKmode
)
2278 if (GET_MODE (op
) != innermode
2279 && GET_MODE (op
) != VOIDmode
)
2282 if (byte
% GET_MODE_SIZE (outermode
)
2283 || byte
>= GET_MODE_SIZE (innermode
))
2286 if (outermode
== innermode
&& !byte
)
2289 /* Simplify subregs of vector constants. */
2290 if (GET_CODE (op
) == CONST_VECTOR
)
2292 int elt_size
= GET_MODE_SIZE (GET_MODE_INNER (innermode
));
2293 const unsigned int offset
= byte
/ elt_size
;
2296 if (GET_MODE_INNER (innermode
) == outermode
)
2298 elt
= CONST_VECTOR_ELT (op
, offset
);
2300 /* ?? We probably don't need this copy_rtx because constants
2301 can be shared. ?? */
2303 return copy_rtx (elt
);
2305 else if (GET_MODE_INNER (innermode
) == GET_MODE_INNER (outermode
)
2306 && GET_MODE_SIZE (innermode
) > GET_MODE_SIZE (outermode
))
2308 return (gen_rtx_CONST_VECTOR
2310 gen_rtvec_v (GET_MODE_NUNITS (outermode
),
2311 &CONST_VECTOR_ELT (op
, offset
))));
2313 else if (GET_MODE_CLASS (outermode
) == MODE_INT
2314 && (GET_MODE_SIZE (outermode
) % elt_size
== 0))
2316 /* This happens when the target register size is smaller then
2317 the vector mode, and we synthesize operations with vectors
2318 of elements that are smaller than the register size. */
2319 HOST_WIDE_INT sum
= 0, high
= 0;
2320 unsigned n_elts
= (GET_MODE_SIZE (outermode
) / elt_size
);
2321 unsigned i
= BYTES_BIG_ENDIAN
? offset
: offset
+ n_elts
- 1;
2322 unsigned step
= BYTES_BIG_ENDIAN
? 1 : -1;
2323 int shift
= BITS_PER_UNIT
* elt_size
;
2325 for (; n_elts
--; i
+= step
)
2327 elt
= CONST_VECTOR_ELT (op
, i
);
2328 if (GET_CODE (elt
) == CONST_DOUBLE
2329 && GET_MODE_CLASS (GET_MODE (elt
)) == MODE_FLOAT
)
2331 elt
= gen_lowpart_common (int_mode_for_mode (GET_MODE (elt
)),
2336 if (GET_CODE (elt
) != CONST_INT
)
2338 high
= high
<< shift
| sum
>> (HOST_BITS_PER_WIDE_INT
- shift
);
2339 sum
= (sum
<< shift
) + INTVAL (elt
);
2341 if (GET_MODE_BITSIZE (outermode
) <= HOST_BITS_PER_WIDE_INT
)
2342 return GEN_INT (trunc_int_for_mode (sum
, outermode
));
2343 else if (GET_MODE_BITSIZE (outermode
) == 2* HOST_BITS_PER_WIDE_INT
)
2344 return immed_double_const (high
, sum
, outermode
);
2348 else if (GET_MODE_CLASS (outermode
) == MODE_INT
2349 && (elt_size
% GET_MODE_SIZE (outermode
) == 0))
2351 enum machine_mode new_mode
2352 = int_mode_for_mode (GET_MODE_INNER (innermode
));
2353 int subbyte
= byte
% elt_size
;
2355 op
= simplify_subreg (new_mode
, op
, innermode
, byte
- subbyte
);
2358 return simplify_subreg (outermode
, op
, new_mode
, subbyte
);
2360 else if (GET_MODE_CLASS (outermode
) == MODE_INT
)
2361 /* This shouldn't happen, but let's not do anything stupid. */
2365 /* Attempt to simplify constant to non-SUBREG expression. */
2366 if (CONSTANT_P (op
))
2369 unsigned HOST_WIDE_INT val
= 0;
2371 if (GET_MODE_CLASS (outermode
) == MODE_VECTOR_INT
2372 || GET_MODE_CLASS (outermode
) == MODE_VECTOR_FLOAT
)
2374 /* Construct a CONST_VECTOR from individual subregs. */
2375 enum machine_mode submode
= GET_MODE_INNER (outermode
);
2376 int subsize
= GET_MODE_UNIT_SIZE (outermode
);
2377 int i
, elts
= GET_MODE_NUNITS (outermode
);
2378 rtvec v
= rtvec_alloc (elts
);
2381 for (i
= 0; i
< elts
; i
++, byte
+= subsize
)
2383 /* This might fail, e.g. if taking a subreg from a SYMBOL_REF. */
2384 /* ??? It would be nice if we could actually make such subregs
2385 on targets that allow such relocations. */
2386 elt
= simplify_subreg (submode
, op
, innermode
, byte
);
2389 RTVEC_ELT (v
, i
) = elt
;
2391 return gen_rtx_CONST_VECTOR (outermode
, v
);
2394 /* ??? This code is partly redundant with code below, but can handle
2395 the subregs of floats and similar corner cases.
2396 Later it we should move all simplification code here and rewrite
2397 GEN_LOWPART_IF_POSSIBLE, GEN_HIGHPART, OPERAND_SUBWORD and friends
2398 using SIMPLIFY_SUBREG. */
2399 if (subreg_lowpart_offset (outermode
, innermode
) == byte
2400 && GET_CODE (op
) != CONST_VECTOR
)
2402 rtx
new = gen_lowpart_if_possible (outermode
, op
);
2407 /* Similar comment as above apply here. */
2408 if (GET_MODE_SIZE (outermode
) == UNITS_PER_WORD
2409 && GET_MODE_SIZE (innermode
) > UNITS_PER_WORD
2410 && GET_MODE_CLASS (outermode
) == MODE_INT
)
2412 rtx
new = constant_subword (op
,
2413 (byte
/ UNITS_PER_WORD
),
2419 if (GET_MODE_CLASS (outermode
) != MODE_INT
2420 && GET_MODE_CLASS (outermode
) != MODE_CC
)
2422 enum machine_mode new_mode
= int_mode_for_mode (outermode
);
2424 if (new_mode
!= innermode
|| byte
!= 0)
2426 op
= simplify_subreg (new_mode
, op
, innermode
, byte
);
2429 return simplify_subreg (outermode
, op
, new_mode
, 0);
2433 offset
= byte
* BITS_PER_UNIT
;
2434 switch (GET_CODE (op
))
2437 if (GET_MODE (op
) != VOIDmode
)
2440 /* We can't handle this case yet. */
2441 if (GET_MODE_BITSIZE (outermode
) >= HOST_BITS_PER_WIDE_INT
)
2444 part
= offset
>= HOST_BITS_PER_WIDE_INT
;
2445 if ((BITS_PER_WORD
> HOST_BITS_PER_WIDE_INT
2446 && BYTES_BIG_ENDIAN
)
2447 || (BITS_PER_WORD
<= HOST_BITS_PER_WIDE_INT
2448 && WORDS_BIG_ENDIAN
))
2450 val
= part
? CONST_DOUBLE_HIGH (op
) : CONST_DOUBLE_LOW (op
);
2451 offset
%= HOST_BITS_PER_WIDE_INT
;
2453 /* We've already picked the word we want from a double, so
2454 pretend this is actually an integer. */
2455 innermode
= mode_for_size (HOST_BITS_PER_WIDE_INT
, MODE_INT
, 0);
2459 if (GET_CODE (op
) == CONST_INT
)
2462 /* We don't handle synthetizing of non-integral constants yet. */
2463 if (GET_MODE_CLASS (outermode
) != MODE_INT
)
2466 if (BYTES_BIG_ENDIAN
|| WORDS_BIG_ENDIAN
)
2468 if (WORDS_BIG_ENDIAN
)
2469 offset
= (GET_MODE_BITSIZE (innermode
)
2470 - GET_MODE_BITSIZE (outermode
) - offset
);
2471 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
2472 && GET_MODE_SIZE (outermode
) < UNITS_PER_WORD
)
2473 offset
= (offset
+ BITS_PER_WORD
- GET_MODE_BITSIZE (outermode
)
2474 - 2 * (offset
% BITS_PER_WORD
));
2477 if (offset
>= HOST_BITS_PER_WIDE_INT
)
2478 return ((HOST_WIDE_INT
) val
< 0) ? constm1_rtx
: const0_rtx
;
2482 if (GET_MODE_BITSIZE (outermode
) < HOST_BITS_PER_WIDE_INT
)
2483 val
= trunc_int_for_mode (val
, outermode
);
2484 return GEN_INT (val
);
2491 /* Changing mode twice with SUBREG => just change it once,
2492 or not at all if changing back op starting mode. */
2493 if (GET_CODE (op
) == SUBREG
)
2495 enum machine_mode innermostmode
= GET_MODE (SUBREG_REG (op
));
2496 int final_offset
= byte
+ SUBREG_BYTE (op
);
2499 if (outermode
== innermostmode
2500 && byte
== 0 && SUBREG_BYTE (op
) == 0)
2501 return SUBREG_REG (op
);
2503 /* The SUBREG_BYTE represents offset, as if the value were stored
2504 in memory. Irritating exception is paradoxical subreg, where
2505 we define SUBREG_BYTE to be 0. On big endian machines, this
2506 value should be negative. For a moment, undo this exception. */
2507 if (byte
== 0 && GET_MODE_SIZE (innermode
) < GET_MODE_SIZE (outermode
))
2509 int difference
= (GET_MODE_SIZE (innermode
) - GET_MODE_SIZE (outermode
));
2510 if (WORDS_BIG_ENDIAN
)
2511 final_offset
+= (difference
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
2512 if (BYTES_BIG_ENDIAN
)
2513 final_offset
+= difference
% UNITS_PER_WORD
;
2515 if (SUBREG_BYTE (op
) == 0
2516 && GET_MODE_SIZE (innermostmode
) < GET_MODE_SIZE (innermode
))
2518 int difference
= (GET_MODE_SIZE (innermostmode
) - GET_MODE_SIZE (innermode
));
2519 if (WORDS_BIG_ENDIAN
)
2520 final_offset
+= (difference
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
2521 if (BYTES_BIG_ENDIAN
)
2522 final_offset
+= difference
% UNITS_PER_WORD
;
2525 /* See whether resulting subreg will be paradoxical. */
2526 if (GET_MODE_SIZE (innermostmode
) > GET_MODE_SIZE (outermode
))
2528 /* In nonparadoxical subregs we can't handle negative offsets. */
2529 if (final_offset
< 0)
2531 /* Bail out in case resulting subreg would be incorrect. */
2532 if (final_offset
% GET_MODE_SIZE (outermode
)
2533 || (unsigned) final_offset
>= GET_MODE_SIZE (innermostmode
))
2539 int difference
= (GET_MODE_SIZE (innermostmode
) - GET_MODE_SIZE (outermode
));
2541 /* In paradoxical subreg, see if we are still looking on lower part.
2542 If so, our SUBREG_BYTE will be 0. */
2543 if (WORDS_BIG_ENDIAN
)
2544 offset
+= (difference
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
2545 if (BYTES_BIG_ENDIAN
)
2546 offset
+= difference
% UNITS_PER_WORD
;
2547 if (offset
== final_offset
)
2553 /* Recurse for futher possible simplifications. */
2554 new = simplify_subreg (outermode
, SUBREG_REG (op
),
2555 GET_MODE (SUBREG_REG (op
)),
2559 return gen_rtx_SUBREG (outermode
, SUBREG_REG (op
), final_offset
);
2562 /* SUBREG of a hard register => just change the register number
2563 and/or mode. If the hard register is not valid in that mode,
2564 suppress this simplification. If the hard register is the stack,
2565 frame, or argument pointer, leave this as a SUBREG. */
2568 && (! REG_FUNCTION_VALUE_P (op
)
2569 || ! rtx_equal_function_value_matters
)
2570 #ifdef CLASS_CANNOT_CHANGE_MODE
2571 && ! (CLASS_CANNOT_CHANGE_MODE_P (outermode
, innermode
)
2572 && GET_MODE_CLASS (innermode
) != MODE_COMPLEX_INT
2573 && GET_MODE_CLASS (innermode
) != MODE_COMPLEX_FLOAT
2574 && (TEST_HARD_REG_BIT
2575 (reg_class_contents
[(int) CLASS_CANNOT_CHANGE_MODE
],
2578 && REGNO (op
) < FIRST_PSEUDO_REGISTER
2579 && ((reload_completed
&& !frame_pointer_needed
)
2580 || (REGNO (op
) != FRAME_POINTER_REGNUM
2581 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2582 && REGNO (op
) != HARD_FRAME_POINTER_REGNUM
2585 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2586 && REGNO (op
) != ARG_POINTER_REGNUM
2588 && REGNO (op
) != STACK_POINTER_REGNUM
)
2590 int final_regno
= subreg_hard_regno (gen_rtx_SUBREG (outermode
, op
, byte
),
2593 /* ??? We do allow it if the current REG is not valid for
2594 its mode. This is a kludge to work around how float/complex
2595 arguments are passed on 32-bit SPARC and should be fixed. */
2596 if (HARD_REGNO_MODE_OK (final_regno
, outermode
)
2597 || ! HARD_REGNO_MODE_OK (REGNO (op
), innermode
))
2599 rtx x
= gen_rtx_REG (outermode
, final_regno
);
2601 /* Propagate original regno. We don't have any way to specify
2602 the offset inside orignal regno, so do so only for lowpart.
2603 The information is used only by alias analysis that can not
2604 grog partial register anyway. */
2606 if (subreg_lowpart_offset (outermode
, innermode
) == byte
)
2607 ORIGINAL_REGNO (x
) = ORIGINAL_REGNO (op
);
2612 /* If we have a SUBREG of a register that we are replacing and we are
2613 replacing it with a MEM, make a new MEM and try replacing the
2614 SUBREG with it. Don't do this if the MEM has a mode-dependent address
2615 or if we would be widening it. */
2617 if (GET_CODE (op
) == MEM
2618 && ! mode_dependent_address_p (XEXP (op
, 0))
2619 /* Allow splitting of volatile memory references in case we don't
2620 have instruction to move the whole thing. */
2621 && (! MEM_VOLATILE_P (op
)
2622 || ! have_insn_for (SET
, innermode
))
2623 && GET_MODE_SIZE (outermode
) <= GET_MODE_SIZE (GET_MODE (op
)))
2624 return adjust_address_nv (op
, outermode
, byte
);
2626 /* Handle complex values represented as CONCAT
2627 of real and imaginary part. */
2628 if (GET_CODE (op
) == CONCAT
)
2630 int is_realpart
= byte
< GET_MODE_UNIT_SIZE (innermode
);
2631 rtx part
= is_realpart
? XEXP (op
, 0) : XEXP (op
, 1);
2632 unsigned int final_offset
;
2635 final_offset
= byte
% (GET_MODE_UNIT_SIZE (innermode
));
2636 res
= simplify_subreg (outermode
, part
, GET_MODE (part
), final_offset
);
2639 /* We can at least simplify it by referring directly to the relevant part. */
2640 return gen_rtx_SUBREG (outermode
, part
, final_offset
);
2645 /* Make a SUBREG operation or equivalent if it folds. */
2648 simplify_gen_subreg (outermode
, op
, innermode
, byte
)
2651 enum machine_mode outermode
, innermode
;
2654 /* Little bit of sanity checking. */
2655 if (innermode
== VOIDmode
|| outermode
== VOIDmode
2656 || innermode
== BLKmode
|| outermode
== BLKmode
)
2659 if (GET_MODE (op
) != innermode
2660 && GET_MODE (op
) != VOIDmode
)
2663 if (byte
% GET_MODE_SIZE (outermode
)
2664 || byte
>= GET_MODE_SIZE (innermode
))
2667 if (GET_CODE (op
) == QUEUED
)
2670 new = simplify_subreg (outermode
, op
, innermode
, byte
);
2674 if (GET_CODE (op
) == SUBREG
|| GET_MODE (op
) == VOIDmode
)
2677 return gen_rtx_SUBREG (outermode
, op
, byte
);
2679 /* Simplify X, an rtx expression.
2681 Return the simplified expression or NULL if no simplifications
2684 This is the preferred entry point into the simplification routines;
2685 however, we still allow passes to call the more specific routines.
2687 Right now GCC has three (yes, three) major bodies of RTL simplficiation
2688 code that need to be unified.
2690 1. fold_rtx in cse.c. This code uses various CSE specific
2691 information to aid in RTL simplification.
2693 2. simplify_rtx in combine.c. Similar to fold_rtx, except that
2694 it uses combine specific information to aid in RTL
2697 3. The routines in this file.
2700 Long term we want to only have one body of simplification code; to
2701 get to that state I recommend the following steps:
2703 1. Pour over fold_rtx & simplify_rtx and move any simplifications
2704 which are not pass dependent state into these routines.
2706 2. As code is moved by #1, change fold_rtx & simplify_rtx to
2707 use this routine whenever possible.
2709 3. Allow for pass dependent state to be provided to these
2710 routines and add simplifications based on the pass dependent
2711 state. Remove code from cse.c & combine.c that becomes
2714 It will take time, but ultimately the compiler will be easier to
2715 maintain and improve. It's totally silly that when we add a
2716 simplification that it needs to be added to 4 places (3 for RTL
2717 simplification and 1 for tree simplification. */
2723 enum rtx_code code
= GET_CODE (x
);
2724 enum machine_mode mode
= GET_MODE (x
);
2726 switch (GET_RTX_CLASS (code
))
2729 return simplify_unary_operation (code
, mode
,
2730 XEXP (x
, 0), GET_MODE (XEXP (x
, 0)));
2732 if (swap_commutative_operands_p (XEXP (x
, 0), XEXP (x
, 1)))
2737 XEXP (x
, 0) = XEXP (x
, 1);
2739 return simplify_binary_operation (code
, mode
,
2740 XEXP (x
, 0), XEXP (x
, 1));
2744 return simplify_binary_operation (code
, mode
, XEXP (x
, 0), XEXP (x
, 1));
2748 return simplify_ternary_operation (code
, mode
, GET_MODE (XEXP (x
, 0)),
2749 XEXP (x
, 0), XEXP (x
, 1),
2753 return simplify_relational_operation (code
,
2754 ((GET_MODE (XEXP (x
, 0))
2756 ? GET_MODE (XEXP (x
, 0))
2757 : GET_MODE (XEXP (x
, 1))),
2758 XEXP (x
, 0), XEXP (x
, 1));
2760 /* The only case we try to handle is a SUBREG. */
2762 return simplify_gen_subreg (mode
, SUBREG_REG (x
),
2763 GET_MODE (SUBREG_REG (x
)),