1 /* Dependency checks for instruction scheduling, shared between ARM and
4 Copyright (C) 1991-2014 Free Software Foundation, Inc.
5 Contributed by ARM Ltd.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published
11 by the Free Software Foundation; either version 3, or (at your
12 option) any later version.
14 GCC is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
17 License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
26 #include "coretypes.h"
31 #include "c-family/c-common.h"
35 /* In ARMv8-A there's a general expectation that AESE/AESMC
36 and AESD/AESIMC sequences of the form:
41 will issue both instructions in a single cycle on super-scalar
42 implementations. This function identifies such pairs. */
45 aarch_crypto_can_dual_issue (rtx_insn
*producer_insn
, rtx_insn
*consumer_insn
)
47 rtx producer_set
, consumer_set
;
48 rtx producer_src
, consumer_src
;
50 producer_set
= single_set (producer_insn
);
51 consumer_set
= single_set (consumer_insn
);
53 producer_src
= producer_set
? SET_SRC (producer_set
) : NULL
;
54 consumer_src
= consumer_set
? SET_SRC (consumer_set
) : NULL
;
56 if (producer_src
&& consumer_src
57 && GET_CODE (producer_src
) == UNSPEC
&& GET_CODE (consumer_src
) == UNSPEC
58 && ((XINT (producer_src
, 1) == UNSPEC_AESE
59 && XINT (consumer_src
, 1) == UNSPEC_AESMC
)
60 || (XINT (producer_src
, 1) == UNSPEC_AESD
61 && XINT (consumer_src
, 1) == UNSPEC_AESIMC
)))
63 unsigned int regno
= REGNO (SET_DEST (producer_set
));
65 return REGNO (SET_DEST (consumer_set
)) == regno
66 && REGNO (XVECEXP (consumer_src
, 0, 0)) == regno
;
72 /* Return TRUE if X is either an arithmetic shift left, or
73 is a multiplication by a power of two. */
75 arm_rtx_shift_left_p (rtx x
)
77 enum rtx_code code
= GET_CODE (x
);
79 if (code
== MULT
&& CONST_INT_P (XEXP (x
, 1))
80 && exact_log2 (INTVAL (XEXP (x
, 1))) > 0)
89 static rtx_code shift_rtx_codes
[] =
90 { ASHIFT
, ROTATE
, ASHIFTRT
, LSHIFTRT
,
91 ROTATERT
, ZERO_EXTEND
, SIGN_EXTEND
};
93 /* Traverse PATTERN looking for a sub-rtx with RTX_CODE CODE.
94 If FIND_ANY_SHIFT then we are interested in anything which can
95 reasonably be described as a SHIFT RTX. */
97 arm_find_sub_rtx_with_code (rtx pattern
, rtx_code code
, bool find_any_shift
)
99 subrtx_var_iterator::array_type array
;
100 FOR_EACH_SUBRTX_VAR (iter
, array
, pattern
, NONCONST
)
105 /* Left shifts might have been canonicalized to a MULT of some
106 power of two. Make sure we catch them. */
107 if (arm_rtx_shift_left_p (x
))
110 for (unsigned int i
= 0; i
< ARRAY_SIZE (shift_rtx_codes
); i
++)
111 if (GET_CODE (x
) == shift_rtx_codes
[i
])
115 if (GET_CODE (x
) == code
)
121 /* Traverse PATTERN looking for any sub-rtx which looks like a shift. */
123 arm_find_shift_sub_rtx (rtx pattern
)
125 return arm_find_sub_rtx_with_code (pattern
, ASHIFT
, true);
128 /* PRODUCER and CONSUMER are two potentially dependant RTX. PRODUCER
129 (possibly) contains a SET which will provide a result we can access
130 using the SET_DEST macro. We will place the RTX which would be
131 written by PRODUCER in SET_SOURCE.
132 Similarly, CONSUMER (possibly) contains a SET which has an operand
133 we can access using SET_SRC. We place this operand in
136 Return nonzero if we found the SET RTX we expected. */
138 arm_get_set_operands (rtx producer
, rtx consumer
,
139 rtx
*set_source
, rtx
*set_destination
)
141 rtx set_producer
= arm_find_sub_rtx_with_code (PATTERN (producer
),
143 rtx set_consumer
= arm_find_sub_rtx_with_code (PATTERN (consumer
),
146 if (set_producer
&& set_consumer
)
148 *set_source
= SET_DEST (set_producer
);
149 *set_destination
= SET_SRC (set_consumer
);
156 aarch_rev16_shright_mask_imm_p (rtx val
, machine_mode mode
)
158 return CONST_INT_P (val
)
160 == trunc_int_for_mode (HOST_WIDE_INT_C (0xff00ff00ff00ff),
165 aarch_rev16_shleft_mask_imm_p (rtx val
, machine_mode mode
)
167 return CONST_INT_P (val
)
169 == trunc_int_for_mode (HOST_WIDE_INT_C (0xff00ff00ff00ff00),
175 aarch_rev16_p_1 (rtx lhs
, rtx rhs
, machine_mode mode
)
177 if (GET_CODE (lhs
) == AND
178 && GET_CODE (XEXP (lhs
, 0)) == ASHIFT
179 && CONST_INT_P (XEXP (XEXP (lhs
, 0), 1))
180 && INTVAL (XEXP (XEXP (lhs
, 0), 1)) == 8
181 && REG_P (XEXP (XEXP (lhs
, 0), 0))
182 && CONST_INT_P (XEXP (lhs
, 1))
183 && GET_CODE (rhs
) == AND
184 && GET_CODE (XEXP (rhs
, 0)) == LSHIFTRT
185 && REG_P (XEXP (XEXP (rhs
, 0), 0))
186 && CONST_INT_P (XEXP (XEXP (rhs
, 0), 1))
187 && INTVAL (XEXP (XEXP (rhs
, 0), 1)) == 8
188 && CONST_INT_P (XEXP (rhs
, 1))
189 && REGNO (XEXP (XEXP (rhs
, 0), 0)) == REGNO (XEXP (XEXP (lhs
, 0), 0)))
192 rtx lhs_mask
= XEXP (lhs
, 1);
193 rtx rhs_mask
= XEXP (rhs
, 1);
195 return aarch_rev16_shright_mask_imm_p (rhs_mask
, mode
)
196 && aarch_rev16_shleft_mask_imm_p (lhs_mask
, mode
);
202 /* Recognise a sequence of bitwise operations corresponding to a rev16 operation.
203 These will be of the form:
204 ((x >> 8) & 0x00ff00ff)
205 | ((x << 8) & 0xff00ff00)
206 for SImode and with similar but wider bitmasks for DImode.
207 The two sub-expressions of the IOR can appear on either side so check both
208 permutations with the help of aarch_rev16_p_1 above. */
211 aarch_rev16_p (rtx x
)
213 rtx left_sub_rtx
, right_sub_rtx
;
216 if (GET_CODE (x
) != IOR
)
219 left_sub_rtx
= XEXP (x
, 0);
220 right_sub_rtx
= XEXP (x
, 1);
222 /* There are no canonicalisation rules for the position of the two shifts
223 involved in a rev, so try both permutations. */
224 is_rev
= aarch_rev16_p_1 (left_sub_rtx
, right_sub_rtx
, GET_MODE (x
));
227 is_rev
= aarch_rev16_p_1 (right_sub_rtx
, left_sub_rtx
, GET_MODE (x
));
232 /* Return nonzero if the CONSUMER instruction (a load) does need
233 PRODUCER's value to calculate the address. */
235 arm_early_load_addr_dep (rtx producer
, rtx consumer
)
239 if (!arm_get_set_operands (producer
, consumer
, &value
, &addr
))
242 return reg_overlap_mentioned_p (value
, addr
);
245 /* Return nonzero if the CONSUMER instruction (an ALU op) does not
246 have an early register shift value or amount dependency on the
247 result of PRODUCER. */
249 arm_no_early_alu_shift_dep (rtx producer
, rtx consumer
)
254 if (!arm_get_set_operands (producer
, consumer
, &value
, &op
))
257 if ((early_op
= arm_find_shift_sub_rtx (op
)))
259 if (REG_P (early_op
))
262 return !reg_overlap_mentioned_p (value
, early_op
);
268 /* Return nonzero if the CONSUMER instruction (an ALU op) does not
269 have an early register shift value dependency on the result of
272 arm_no_early_alu_shift_value_dep (rtx producer
, rtx consumer
)
277 if (!arm_get_set_operands (producer
, consumer
, &value
, &op
))
280 if ((early_op
= arm_find_shift_sub_rtx (op
)))
281 /* We want to check the value being shifted. */
282 if (!reg_overlap_mentioned_p (value
, XEXP (early_op
, 0)))
288 /* Return nonzero if the CONSUMER (a mul or mac op) does not
289 have an early register mult dependency on the result of
292 arm_no_early_mul_dep (rtx producer
, rtx consumer
)
296 if (!arm_get_set_operands (producer
, consumer
, &value
, &op
))
299 if (GET_CODE (op
) == PLUS
|| GET_CODE (op
) == MINUS
)
301 if (GET_CODE (XEXP (op
, 0)) == MULT
)
302 return !reg_overlap_mentioned_p (value
, XEXP (op
, 0));
304 return !reg_overlap_mentioned_p (value
, XEXP (op
, 1));
310 /* Return nonzero if the CONSUMER instruction (a store) does not need
311 PRODUCER's value to calculate the address. */
314 arm_no_early_store_addr_dep (rtx producer
, rtx consumer
)
316 rtx value
= arm_find_sub_rtx_with_code (PATTERN (producer
), SET
, false);
317 rtx addr
= arm_find_sub_rtx_with_code (PATTERN (consumer
), SET
, false);
320 value
= SET_DEST (value
);
323 addr
= SET_DEST (addr
);
328 return !reg_overlap_mentioned_p (value
, addr
);
331 /* Return nonzero if the CONSUMER instruction (a store) does need
332 PRODUCER's value to calculate the address. */
335 arm_early_store_addr_dep (rtx producer
, rtx consumer
)
337 return !arm_no_early_store_addr_dep (producer
, consumer
);
340 /* Return non-zero iff the consumer (a multiply-accumulate or a
341 multiple-subtract instruction) has an accumulator dependency on the
342 result of the producer and no other dependency on that result. It
343 does not check if the producer is multiply-accumulate instruction. */
345 arm_mac_accumulator_is_result (rtx producer
, rtx consumer
)
350 producer
= PATTERN (producer
);
351 consumer
= PATTERN (consumer
);
353 if (GET_CODE (producer
) == COND_EXEC
)
354 producer
= COND_EXEC_CODE (producer
);
355 if (GET_CODE (consumer
) == COND_EXEC
)
356 consumer
= COND_EXEC_CODE (consumer
);
358 if (GET_CODE (producer
) != SET
)
361 result
= XEXP (producer
, 0);
363 if (GET_CODE (consumer
) != SET
)
366 /* Check that the consumer is of the form
367 (set (...) (plus (mult ...) (...)))
369 (set (...) (minus (...) (mult ...))). */
370 if (GET_CODE (XEXP (consumer
, 1)) == PLUS
)
372 if (GET_CODE (XEXP (XEXP (consumer
, 1), 0)) != MULT
)
375 op0
= XEXP (XEXP (XEXP (consumer
, 1), 0), 0);
376 op1
= XEXP (XEXP (XEXP (consumer
, 1), 0), 1);
377 acc
= XEXP (XEXP (consumer
, 1), 1);
379 else if (GET_CODE (XEXP (consumer
, 1)) == MINUS
)
381 if (GET_CODE (XEXP (XEXP (consumer
, 1), 1)) != MULT
)
384 op0
= XEXP (XEXP (XEXP (consumer
, 1), 1), 0);
385 op1
= XEXP (XEXP (XEXP (consumer
, 1), 1), 1);
386 acc
= XEXP (XEXP (consumer
, 1), 0);
391 return (reg_overlap_mentioned_p (result
, acc
)
392 && !reg_overlap_mentioned_p (result
, op0
)
393 && !reg_overlap_mentioned_p (result
, op1
));
396 /* Return non-zero if the consumer (a multiply-accumulate instruction)
397 has an accumulator dependency on the result of the producer (a
398 multiplication instruction) and no other dependency on that result. */
400 arm_mac_accumulator_is_mul_result (rtx producer
, rtx consumer
)
402 rtx mul
= PATTERN (producer
);
403 rtx mac
= PATTERN (consumer
);
405 rtx mac_op0
, mac_op1
, mac_acc
;
407 if (GET_CODE (mul
) == COND_EXEC
)
408 mul
= COND_EXEC_CODE (mul
);
409 if (GET_CODE (mac
) == COND_EXEC
)
410 mac
= COND_EXEC_CODE (mac
);
412 /* Check that mul is of the form (set (...) (mult ...))
413 and mla is of the form (set (...) (plus (mult ...) (...))). */
414 if ((GET_CODE (mul
) != SET
|| GET_CODE (XEXP (mul
, 1)) != MULT
)
415 || (GET_CODE (mac
) != SET
|| GET_CODE (XEXP (mac
, 1)) != PLUS
416 || GET_CODE (XEXP (XEXP (mac
, 1), 0)) != MULT
))
419 mul_result
= XEXP (mul
, 0);
420 mac_op0
= XEXP (XEXP (XEXP (mac
, 1), 0), 0);
421 mac_op1
= XEXP (XEXP (XEXP (mac
, 1), 0), 1);
422 mac_acc
= XEXP (XEXP (mac
, 1), 1);
424 return (reg_overlap_mentioned_p (mul_result
, mac_acc
)
425 && !reg_overlap_mentioned_p (mul_result
, mac_op0
)
426 && !reg_overlap_mentioned_p (mul_result
, mac_op1
));