1 /* Preamble and helpers for the autogenerated generic-match.cc file.
2 Copyright (C) 2014-2024 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
30 #include "vec-perm-indices.h"
31 #include "fold-const.h"
32 #include "fold-const-call.h"
33 #include "stor-layout.h"
36 #include "case-cfn-macros.h"
38 #include "optabs-tree.h"
42 #include "langhooks.h"
43 #include "tree-pass.h"
47 /* Routine to determine if the types T1 and T2 are effectively
48 the same for GENERIC. If T1 or T2 is not a type, the test
49 applies to their TREE_TYPE. */
52 types_match (tree t1
, tree t2
)
59 return TYPE_MAIN_VARIANT (t1
) == TYPE_MAIN_VARIANT (t2
);
62 /* Routine to determine if the types T1, T2 and T3 are effectively
63 the same for GENERIC. If T1, T2 or T2 is not a type, the test
64 applies to their TREE_TYPE. */
67 types_match (tree t1
, tree t2
, tree t3
)
69 return types_match (t1
, t2
) && types_match (t2
, t3
);
72 /* Return if T has a single use. For GENERIC, we assume this is
76 single_use (tree t ATTRIBUTE_UNUSED
)
81 /* Return true if math operations should be canonicalized,
82 e.g. sqrt(sqrt(x)) -> pow(x, 0.25). */
85 canonicalize_math_p ()
87 return !cfun
|| (cfun
->curr_properties
& PROP_gimple_opt_math
) == 0;
90 /* Return true if math operations that are beneficial only after
91 vectorization should be canonicalized. */
94 canonicalize_math_after_vectorization_p ()
99 /* Return true if we can still perform transformations that may introduce
100 vector operations that are not supported by the target. Vector lowering
101 normally handles those, but after that pass, it becomes unsafe. */
104 optimize_vectors_before_lowering_p ()
106 return !cfun
|| (cfun
->curr_properties
& PROP_gimple_lvec
) == 0;
109 /* Return true if successive divisions can be optimized.
110 Defer to GIMPLE opts. */
113 optimize_successive_divisions_p (tree
, tree
)
118 /* Return true if EXPR1 and EXPR2 have the same value, but not necessarily
119 same type. The types can differ through nop conversions. */
122 bitwise_equal_p (tree expr1
, tree expr2
)
128 if (!tree_nop_conversion_p (TREE_TYPE (expr1
), TREE_TYPE (expr2
)))
130 if (TREE_CODE (expr1
) == INTEGER_CST
&& TREE_CODE (expr2
) == INTEGER_CST
)
131 return wi::to_wide (expr1
) == wi::to_wide (expr2
);
132 return operand_equal_p (expr1
, expr2
, 0);
135 /* Return true if EXPR1 and EXPR2 have the bitwise opposite value,
136 but not necessarily same type.
137 The types can differ through nop conversions. */
140 bitwise_inverted_equal_p (tree expr1
, tree expr2
, bool &wascmp
)
147 if (!tree_nop_conversion_p (TREE_TYPE (expr1
), TREE_TYPE (expr2
)))
149 tree cst1
= uniform_integer_cst_p (expr1
);
150 tree cst2
= uniform_integer_cst_p (expr2
);
152 return wi::to_wide (cst1
) == ~wi::to_wide (cst2
);
153 if (operand_equal_p (expr1
, expr2
, 0))
155 if (TREE_CODE (expr1
) == BIT_NOT_EXPR
156 && bitwise_equal_p (TREE_OPERAND (expr1
, 0), expr2
))
158 if (TREE_CODE (expr2
) == BIT_NOT_EXPR
159 && bitwise_equal_p (expr1
, TREE_OPERAND (expr2
, 0)))
162 /* `X ^ CST` and `X ^ ~CST` match for ~. */
163 if (TREE_CODE (expr1
) == BIT_XOR_EXPR
&& TREE_CODE (expr2
) == BIT_XOR_EXPR
164 && bitwise_equal_p (TREE_OPERAND (expr1
, 0), TREE_OPERAND (expr2
, 0)))
166 tree cst1
= uniform_integer_cst_p (TREE_OPERAND (expr1
, 1));
167 tree cst2
= uniform_integer_cst_p (TREE_OPERAND (expr2
, 1));
168 if (cst1
&& cst2
&& wi::to_wide (cst1
) == ~wi::to_wide (cst2
))
171 if (COMPARISON_CLASS_P (expr1
)
172 && COMPARISON_CLASS_P (expr2
))
174 tree op10
= TREE_OPERAND (expr1
, 0);
175 tree op20
= TREE_OPERAND (expr2
, 0);
177 if (!operand_equal_p (op10
, op20
))
179 tree op11
= TREE_OPERAND (expr1
, 1);
180 tree op21
= TREE_OPERAND (expr2
, 1);
181 if (!operand_equal_p (op11
, op21
))
183 if (invert_tree_comparison (TREE_CODE (expr1
),
185 == TREE_CODE (expr2
))