aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorMarc Glisse <marc.glisse@inria.fr>2013-03-21 17:33:33 +0100
committerMarc Glisse <glisse@gcc.gnu.org>2013-03-21 16:33:33 +0000
commit08e0cda61db940bb3b312b44b6d96219f697c27a (patch)
tree32255bfeab9804ebb6cbd03117e49ca038c33706 /gcc/fold-const.c
parentd08633b496a5820431e4049ee8a564796a42114d (diff)
downloadgcc-08e0cda61db940bb3b312b44b6d96219f697c27a.zip
gcc-08e0cda61db940bb3b312b44b6d96219f697c27a.tar.gz
gcc-08e0cda61db940bb3b312b44b6d96219f697c27a.tar.bz2
tree.h (VECTOR_TYPE_P): New macro.
2013-03-21 Marc Glisse <marc.glisse@inria.fr> gcc/ * tree.h (VECTOR_TYPE_P): New macro. (VECTOR_INTEGER_TYPE_P, VECTOR_FLOAT_TYPE_P, FLOAT_TYPE_P, TYPE_MODE): Use it. * fold-const.c (fold_cond_expr_with_comparison): Use build_zero_cst. VEC_COND_EXPR cannot be lvalues. (fold_ternary_loc) <VEC_COND_EXPR>: Merge with the COND_EXPR case. gcc/cp/ * call.c (build_conditional_expr_1): Fold VEC_COND_EXPR. gcc/testsuite/ * g++.dg/ext/vector21.C: New testcase. From-SVN: r196884
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index ae03938..905661c 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -4633,7 +4633,7 @@ fold_cond_expr_with_comparison (location_t loc, tree type,
if (comp_code == NE_EXPR)
return pedantic_non_lvalue_loc (loc, fold_convert_loc (loc, type, arg1));
else if (comp_code == EQ_EXPR)
- return build_int_cst (type, 0);
+ return build_zero_cst (type);
}
/* Try some transformations of A op B ? A : B.
@@ -4667,6 +4667,7 @@ fold_cond_expr_with_comparison (location_t loc, tree type,
/* Avoid these transformations if the COND_EXPR may be used
as an lvalue in the C++ front-end. PR c++/19199. */
&& (in_gimple_form
+ || VECTOR_TYPE_P (type)
|| (strcmp (lang_hooks.name, "GNU C++") != 0
&& strcmp (lang_hooks.name, "GNU Objective-C++") != 0)
|| ! maybe_lvalue_p (arg1)
@@ -13899,6 +13900,7 @@ fold_ternary_loc (location_t loc, enum tree_code code, tree type,
return NULL_TREE;
case COND_EXPR:
+ case VEC_COND_EXPR:
/* Pedantic ANSI C says that a conditional expression is never an lvalue,
so all simple results must be passed through pedantic_non_lvalue. */
if (TREE_CODE (arg0) == INTEGER_CST)
@@ -13916,6 +13918,14 @@ fold_ternary_loc (location_t loc, enum tree_code code, tree type,
return pedantic_non_lvalue_loc (loc, tem);
return NULL_TREE;
}
+ else if (TREE_CODE (arg0) == VECTOR_CST)
+ {
+ if (integer_all_onesp (arg0))
+ return pedantic_omit_one_operand_loc (loc, type, arg1, arg2);
+ if (integer_zerop (arg0))
+ return pedantic_omit_one_operand_loc (loc, type, arg2, arg1);
+ }
+
if (operand_equal_p (arg1, op2, 0))
return pedantic_omit_one_operand_loc (loc, type, arg1, arg0);
@@ -13951,6 +13961,10 @@ fold_ternary_loc (location_t loc, enum tree_code code, tree type,
}
}
+ /* ??? Fixup the code below for VEC_COND_EXPR. */
+ if (code == VEC_COND_EXPR)
+ return NULL_TREE;
+
/* If the second operand is simpler than the third, swap them
since that produces better jump optimization results. */
if (truth_value_p (TREE_CODE (arg0))
@@ -14138,16 +14152,6 @@ fold_ternary_loc (location_t loc, enum tree_code code, tree type,
return NULL_TREE;
- case VEC_COND_EXPR:
- if (TREE_CODE (arg0) == VECTOR_CST)
- {
- if (integer_all_onesp (arg0) && !TREE_SIDE_EFFECTS (op2))
- return pedantic_non_lvalue_loc (loc, op1);
- if (integer_zerop (arg0) && !TREE_SIDE_EFFECTS (op1))
- return pedantic_non_lvalue_loc (loc, op2);
- }
- return NULL_TREE;
-
case CALL_EXPR:
/* CALL_EXPRs used to be ternary exprs. Catch any mistaken uses
of fold_ternary on them. */