+2014-09-12 Marc Glisse <marc.glisse@inria.fr>
+
+ * tree.c (integer_each_onep): New function.
+ * tree.h (integer_each_onep): Declare it.
+ * fold-const.c (fold_binary_loc): Use it for ~A + 1 to -A and
+ -A - 1 to ~A. Disable (X & 1) ^ 1, (X ^ 1) & 1 and ~X & 1 to
+ (X & 1) == 0 for vector and complex.
+
2014-09-12 Wilco Dijkstra <wilco.dijkstra@arm.com>
* gcc/config/aarch64/aarch64.c (cortexa57_regmove_cost): New cost table
{
/* Convert ~A + 1 to -A. */
if (TREE_CODE (arg0) == BIT_NOT_EXPR
- && integer_onep (arg1))
+ && integer_each_onep (arg1))
return fold_build1_loc (loc, NEGATE_EXPR, type,
fold_convert_loc (loc, type,
TREE_OPERAND (arg0, 0)));
fold_convert_loc (loc, type,
TREE_OPERAND (arg0, 0)));
/* Convert -A - 1 to ~A. */
- if (TREE_CODE (type) != COMPLEX_TYPE
- && TREE_CODE (arg0) == NEGATE_EXPR
- && integer_onep (arg1)
+ if (TREE_CODE (arg0) == NEGATE_EXPR
+ && integer_each_onep (arg1)
&& !TYPE_OVERFLOW_TRAPS (type))
return fold_build1_loc (loc, BIT_NOT_EXPR, type,
fold_convert_loc (loc, type,
/* Fold (X & 1) ^ 1 as (X & 1) == 0. */
if (TREE_CODE (arg0) == BIT_AND_EXPR
+ && INTEGRAL_TYPE_P (type)
&& integer_onep (TREE_OPERAND (arg0, 1))
&& integer_onep (arg1))
return fold_build2_loc (loc, EQ_EXPR, type, arg0,
/* Fold (X ^ 1) & 1 as (X & 1) == 0. */
if (TREE_CODE (arg0) == BIT_XOR_EXPR
+ && INTEGRAL_TYPE_P (type)
&& integer_onep (TREE_OPERAND (arg0, 1))
&& integer_onep (arg1))
{
}
/* Fold ~X & 1 as (X & 1) == 0. */
if (TREE_CODE (arg0) == BIT_NOT_EXPR
+ && INTEGRAL_TYPE_P (type)
&& integer_onep (arg1))
{
tree tem2;
--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-O" } */
+
+typedef int vec __attribute__((vector_size(4*sizeof(int))));
+
+__attribute__((noinline,noclone))
+void f (vec *x) {
+ *x = (*x & 1) ^ 1;
+}
+
+int main() {
+ vec x = { 1, 2, 3, 4 };
+ f(&x);
+ if (x[0] != 0 || x[1] != 1)
+ __builtin_abort();
+ return 0;
+}
}
}
+/* Return 1 if EXPR is the integer constant one. For complex and vector,
+ return 1 if every piece is the integer constant one. */
+
+int
+integer_each_onep (const_tree expr)
+{
+ STRIP_NOPS (expr);
+
+ if (TREE_CODE (expr) == COMPLEX_CST)
+ return (integer_onep (TREE_REALPART (expr))
+ && integer_onep (TREE_IMAGPART (expr)));
+ else
+ return integer_onep (expr);
+}
+
/* Return 1 if EXPR is an integer containing all 1's in as much precision as
it contains, or a complex or vector whose subparts are such integers. */
extern int integer_onep (const_tree);
+/* integer_onep (tree x) is nonzero if X is an integer constant of value 1, or
+ a vector or complex where each part is 1. */
+
+extern int integer_each_onep (const_tree);
+
/* integer_all_onesp (tree x) is nonzero if X is an integer constant
all of whose significant bits are 1. */