+2017-12-07 Richard Sandiford <richard.sandiford@linaro.org>
+
+ * tree-vector-builder.h
+ (tree_vector_builder::binary_encoded_nelts): Declare.
+ * tree-vector-builder.c
+ (tree_vector_builder::binary_encoded_nelts): New function.
+ * fold-const.c (negate_expr_p): Likewise.
+ (operand_equal_p, fold_checksum_tree): Likewise.
+ * tree-loop-distribution.c (const_with_all_bytes_same): Likewise.
+ * tree.c (integer_zerop, integer_onep, integer_all_onesp, real_zerop)
+ (real_onep, real_minus_onep, add_expr, initializer_zerop): Likewise.
+ (uniform_vector_p): Likewise.
+ * varasm.c (const_hash_1, compare_constant): Likewise.
+ * tree-ssa-ccp.c: Include tree-vector-builder.h.
+ (valid_lattice_transition): Operate directly on the VECTOR_CST
+ encoding.
+ * ipa-icf.c: Include tree-vector-builder.h.
+ (sem_variable::equals): Operate directly on the VECTOR_CST encoding.
+ * print-tree.c (print_node): Print encoding of VECTOR_CSTs.
+
2017-12-07 Richard Sandiford <richard.sandiford@linaro.org>
* tree.c (build_vector): Delete.
if (FLOAT_TYPE_P (TREE_TYPE (type)) || TYPE_OVERFLOW_WRAPS (type))
return true;
- int count = VECTOR_CST_NELTS (t), i;
-
- for (i = 0; i < count; i++)
- if (!negate_expr_p (VECTOR_CST_ELT (t, i)))
+ /* Steps don't prevent negation. */
+ unsigned int count = vector_cst_encoded_nelts (t);
+ for (unsigned int i = 0; i < count; ++i)
+ if (!negate_expr_p (VECTOR_CST_ENCODED_ELT (t, i)))
return false;
return true;
case VECTOR_CST:
{
- unsigned i;
+ if (VECTOR_CST_LOG2_NPATTERNS (arg0)
+ != VECTOR_CST_LOG2_NPATTERNS (arg1))
+ return 0;
- if (VECTOR_CST_NELTS (arg0) != VECTOR_CST_NELTS (arg1))
+ if (VECTOR_CST_NELTS_PER_PATTERN (arg0)
+ != VECTOR_CST_NELTS_PER_PATTERN (arg1))
return 0;
- for (i = 0; i < VECTOR_CST_NELTS (arg0); ++i)
- {
- if (!operand_equal_p (VECTOR_CST_ELT (arg0, i),
- VECTOR_CST_ELT (arg1, i), flags))
- return 0;
- }
+ unsigned int count = vector_cst_encoded_nelts (arg0);
+ for (unsigned int i = 0; i < count; ++i)
+ if (!operand_equal_p (VECTOR_CST_ENCODED_ELT (arg0, i),
+ VECTOR_CST_ENCODED_ELT (arg1, i), flags))
+ return 0;
return 1;
}
fold_checksum_tree (TREE_IMAGPART (expr), ctx, ht);
break;
case VECTOR_CST:
- for (i = 0; i < (int) VECTOR_CST_NELTS (expr); ++i)
- fold_checksum_tree (VECTOR_CST_ELT (expr, i), ctx, ht);
+ len = vector_cst_encoded_nelts (expr);
+ for (i = 0; i < len; ++i)
+ fold_checksum_tree (VECTOR_CST_ENCODED_ELT (expr, i), ctx, ht);
break;
default:
break;
#include "ipa-icf.h"
#include "stor-layout.h"
#include "dbgcnt.h"
+#include "tree-vector-builder.h"
using namespace ipa_icf_gimple;
&TREE_REAL_CST (t2)));
case VECTOR_CST:
{
- unsigned i;
-
if (VECTOR_CST_NELTS (t1) != VECTOR_CST_NELTS (t2))
return return_false_with_msg ("VECTOR_CST nelts mismatch");
- for (i = 0; i < VECTOR_CST_NELTS (t1); ++i)
- if (!sem_variable::equals (VECTOR_CST_ELT (t1, i),
- VECTOR_CST_ELT (t2, i)))
- return 0;
+ unsigned int count
+ = tree_vector_builder::binary_encoded_nelts (t1, t2);
+ for (unsigned int i = 0; i < count; ++i)
+ if (!sem_variable::equals (VECTOR_CST_ENCODED_ELT (t1, i),
+ VECTOR_CST_ENCODED_ELT (t2, i)))
+ return false;
- return 1;
+ return true;
}
case ARRAY_REF:
case ARRAY_RANGE_REF:
case VECTOR_CST:
{
- /* Big enough for 2 UINT_MAX plus the string below. */
+ /* Big enough for UINT_MAX plus the string below. */
char buf[32];
- unsigned i;
- for (i = 0; i < VECTOR_CST_NELTS (node); ++i)
+ fprintf (file, " npatterns:%u nelts-per-pattern:%u",
+ VECTOR_CST_NPATTERNS (node),
+ VECTOR_CST_NELTS_PER_PATTERN (node));
+ unsigned int count = vector_cst_encoded_nelts (node);
+ for (unsigned int i = 0; i < count; ++i)
{
- unsigned j;
- /* Coalesce the output of identical consecutive elements. */
- for (j = i + 1; j < VECTOR_CST_NELTS (node); j++)
- if (VECTOR_CST_ELT (node, j) != VECTOR_CST_ELT (node, i))
- break;
- j--;
- if (i == j)
- sprintf (buf, "elt:%u: ", i);
- else
- sprintf (buf, "elt:%u...%u: ", i, j);
- print_node (file, buf, VECTOR_CST_ELT (node, i), indent + 4);
- i = j;
+ sprintf (buf, "elt:%u: ", i);
+ print_node (file, buf, VECTOR_CST_ENCODED_ELT (node, i),
+ indent + 4);
}
}
break;
return 0;
break;
case VECTOR_CST:
- unsigned int j;
- for (j = 0; j < VECTOR_CST_NELTS (val); ++j)
- if (const_with_all_bytes_same (VECTOR_CST_ELT (val, j)))
- break;
- if (j == VECTOR_CST_NELTS (val))
- return 0;
- break;
+ {
+ unsigned int count = vector_cst_encoded_nelts (val);
+ unsigned int j;
+ for (j = 0; j < count; ++j)
+ if (const_with_all_bytes_same (VECTOR_CST_ENCODED_ELT (val, j)))
+ break;
+ if (j == count)
+ return 0;
+ break;
+ }
default:
break;
}
#include "diagnostic-core.h"
#include "stringpool.h"
#include "attribs.h"
+#include "tree-vector-builder.h"
/* Possible lattice values. */
typedef enum
else if (VECTOR_FLOAT_TYPE_P (type)
&& !HONOR_NANS (type))
{
- for (unsigned i = 0; i < VECTOR_CST_NELTS (old_val.value); ++i)
+ unsigned int count
+ = tree_vector_builder::binary_encoded_nelts (old_val.value,
+ new_val.value);
+ for (unsigned int i = 0; i < count; ++i)
if (!REAL_VALUE_ISNAN
- (TREE_REAL_CST (VECTOR_CST_ELT (old_val.value, i)))
- && !operand_equal_p (VECTOR_CST_ELT (old_val.value, i),
- VECTOR_CST_ELT (new_val.value, i), 0))
+ (TREE_REAL_CST (VECTOR_CST_ENCODED_ELT (old_val.value, i)))
+ && !operand_equal_p (VECTOR_CST_ENCODED_ELT (old_val.value, i),
+ VECTOR_CST_ENCODED_ELT (new_val.value, i), 0))
return false;
return true;
}
return true;
}
+/* Return the number of elements that the caller needs to operate on in
+ order to handle a binary operation on VECTOR_CSTs T1 and T2. This static
+ function is used instead of new_binary_operation if the result of the
+ operation is not a VECTOR_CST. */
+
+unsigned int
+tree_vector_builder::binary_encoded_nelts (tree t1, tree t2)
+{
+ unsigned int nelts = TYPE_VECTOR_SUBPARTS (TREE_TYPE (t1));
+ gcc_assert (nelts == TYPE_VECTOR_SUBPARTS (TREE_TYPE (t2)));
+ /* See new_binary_operation for details. */
+ unsigned int npatterns = least_common_multiple (VECTOR_CST_NPATTERNS (t1),
+ VECTOR_CST_NPATTERNS (t2));
+ unsigned int nelts_per_pattern = MAX (VECTOR_CST_NELTS_PER_PATTERN (t1),
+ VECTOR_CST_NELTS_PER_PATTERN (t2));
+ return MIN (npatterns * nelts_per_pattern, nelts);
+}
+
/* Return a vector element with the value BASE + FACTOR * STEP. */
tree
bool new_unary_operation (tree, tree, bool);
bool new_binary_operation (tree, tree, tree, bool);
+ static unsigned int binary_encoded_nelts (tree, tree);
+
private:
bool equal_p (const_tree, const_tree) const;
bool allow_steps_p () const;
return (integer_zerop (TREE_REALPART (expr))
&& integer_zerop (TREE_IMAGPART (expr)));
case VECTOR_CST:
- {
- unsigned i;
- for (i = 0; i < VECTOR_CST_NELTS (expr); ++i)
- if (!integer_zerop (VECTOR_CST_ELT (expr, i)))
- return false;
- return true;
- }
+ return (VECTOR_CST_NPATTERNS (expr) == 1
+ && VECTOR_CST_DUPLICATE_P (expr)
+ && integer_zerop (VECTOR_CST_ENCODED_ELT (expr, 0)));
default:
return false;
}
return (integer_onep (TREE_REALPART (expr))
&& integer_zerop (TREE_IMAGPART (expr)));
case VECTOR_CST:
- {
- unsigned i;
- for (i = 0; i < VECTOR_CST_NELTS (expr); ++i)
- if (!integer_onep (VECTOR_CST_ELT (expr, i)))
- return false;
- return true;
- }
+ return (VECTOR_CST_NPATTERNS (expr) == 1
+ && VECTOR_CST_DUPLICATE_P (expr)
+ && integer_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
default:
return false;
}
return 1;
else if (TREE_CODE (expr) == VECTOR_CST)
- {
- unsigned i;
- for (i = 0; i < VECTOR_CST_NELTS (expr); ++i)
- if (!integer_all_onesp (VECTOR_CST_ELT (expr, i)))
- return 0;
- return 1;
- }
+ return (VECTOR_CST_NPATTERNS (expr) == 1
+ && VECTOR_CST_DUPLICATE_P (expr)
+ && integer_all_onesp (VECTOR_CST_ENCODED_ELT (expr, 0)));
else if (TREE_CODE (expr) != INTEGER_CST)
return 0;
&& real_zerop (TREE_IMAGPART (expr));
case VECTOR_CST:
{
- unsigned i;
- for (i = 0; i < VECTOR_CST_NELTS (expr); ++i)
- if (!real_zerop (VECTOR_CST_ELT (expr, i)))
+ /* Don't simply check for a duplicate because the predicate
+ accepts both +0.0 and -0.0. */
+ unsigned count = vector_cst_encoded_nelts (expr);
+ for (unsigned int i = 0; i < count; ++i)
+ if (!real_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
return false;
return true;
}
return real_onep (TREE_REALPART (expr))
&& real_zerop (TREE_IMAGPART (expr));
case VECTOR_CST:
- {
- unsigned i;
- for (i = 0; i < VECTOR_CST_NELTS (expr); ++i)
- if (!real_onep (VECTOR_CST_ELT (expr, i)))
- return false;
- return true;
- }
+ return (VECTOR_CST_NPATTERNS (expr) == 1
+ && VECTOR_CST_DUPLICATE_P (expr)
+ && real_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
default:
return false;
}
return real_minus_onep (TREE_REALPART (expr))
&& real_zerop (TREE_IMAGPART (expr));
case VECTOR_CST:
- {
- unsigned i;
- for (i = 0; i < VECTOR_CST_NELTS (expr); ++i)
- if (!real_minus_onep (VECTOR_CST_ELT (expr, i)))
- return false;
- return true;
- }
+ return (VECTOR_CST_NPATTERNS (expr) == 1
+ && VECTOR_CST_DUPLICATE_P (expr)
+ && real_minus_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
default:
return false;
}
return;
case VECTOR_CST:
{
- unsigned i;
- for (i = 0; i < VECTOR_CST_NELTS (t); ++i)
- inchash::add_expr (VECTOR_CST_ELT (t, i), hstate, flags);
+ hstate.add_int (VECTOR_CST_NPATTERNS (t));
+ hstate.add_int (VECTOR_CST_NELTS_PER_PATTERN (t));
+ unsigned int count = vector_cst_encoded_nelts (t);
+ for (unsigned int i = 0; i < count; ++i)
+ inchash::add_expr (VECTOR_CST_ENCODED_ELT (t, i), hstate, flags);
return;
}
case SSA_NAME:
&& ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init))));
case VECTOR_CST:
- {
- unsigned i;
- for (i = 0; i < VECTOR_CST_NELTS (init); ++i)
- if (!initializer_zerop (VECTOR_CST_ELT (init, i)))
- return false;
- return true;
- }
+ return (VECTOR_CST_NPATTERNS (init) == 1
+ && VECTOR_CST_DUPLICATE_P (init)
+ && initializer_zerop (VECTOR_CST_ENCODED_ELT (init, 0)));
case CONSTRUCTOR:
{
if (TREE_CODE (vec) == VECTOR_CST)
{
- first = VECTOR_CST_ELT (vec, 0);
- for (i = 1; i < VECTOR_CST_NELTS (vec); ++i)
- if (!operand_equal_p (first, VECTOR_CST_ELT (vec, i), 0))
- return NULL_TREE;
-
- return first;
+ if (VECTOR_CST_NPATTERNS (vec) == 1 && VECTOR_CST_DUPLICATE_P (vec))
+ return VECTOR_CST_ENCODED_ELT (vec, 0);
+ return NULL_TREE;
}
else if (TREE_CODE (vec) == CONSTRUCTOR)
case VECTOR_CST:
{
- unsigned i;
-
- hi = 7 + VECTOR_CST_NELTS (exp);
-
- for (i = 0; i < VECTOR_CST_NELTS (exp); ++i)
- hi = hi * 563 + const_hash_1 (VECTOR_CST_ELT (exp, i));
-
+ hi = 7 + VECTOR_CST_NPATTERNS (exp);
+ hi = hi * 563 + VECTOR_CST_NELTS_PER_PATTERN (exp);
+ unsigned int count = vector_cst_encoded_nelts (exp);
+ for (unsigned int i = 0; i < count; ++i)
+ hi = hi * 563 + const_hash_1 (VECTOR_CST_ENCODED_ELT (exp, i));
return hi;
}
case VECTOR_CST:
{
- unsigned i;
+ if (VECTOR_CST_NPATTERNS (t1)
+ != VECTOR_CST_NPATTERNS (t2))
+ return 0;
- if (VECTOR_CST_NELTS (t1) != VECTOR_CST_NELTS (t2))
+ if (VECTOR_CST_NELTS_PER_PATTERN (t1)
+ != VECTOR_CST_NELTS_PER_PATTERN (t2))
return 0;
- for (i = 0; i < VECTOR_CST_NELTS (t1); ++i)
- if (!compare_constant (VECTOR_CST_ELT (t1, i),
- VECTOR_CST_ELT (t2, i)))
+ unsigned int count = vector_cst_encoded_nelts (t1);
+ for (unsigned int i = 0; i < count; ++i)
+ if (!compare_constant (VECTOR_CST_ENCODED_ELT (t1, i),
+ VECTOR_CST_ENCODED_ELT (t2, i)))
return 0;
return 1;