aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRoger Sayle <roger@eyesopen.com>2004-09-10 02:39:18 +0000
committerRoger Sayle <sayle@gcc.gnu.org>2004-09-10 02:39:18 +0000
commit049e524f68be57df307f11ea9d3d28afdc37d7c3 (patch)
tree23084ccb47738efb8c8ceb2cc535f0fd0434593b /gcc
parent1b83d20963c6db039c6530949db4da9581f86ce9 (diff)
downloadgcc-049e524f68be57df307f11ea9d3d28afdc37d7c3.zip
gcc-049e524f68be57df307f11ea9d3d28afdc37d7c3.tar.gz
gcc-049e524f68be57df307f11ea9d3d28afdc37d7c3.tar.bz2
re PR middle-end/17055 (ICE while folding int/float vectors)
PR middle-end/17055 * fold-const.c (build_zero_vector): New function to construct a vector (either floating point or integer) of zeros. (fold_convert): Internally, enable conversions of integer zero to arbitrary vector types, using the new build_zero_vector. * gcc.dg/pr17055-1.c: New test case. From-SVN: r87272
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/fold-const.c20
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/pr17055-1.c24
4 files changed, 57 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 90ca63f..a6105a8 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,13 @@
2004-09-09 Roger Sayle <roger@eyesopen.com>
+ PR middle-end/17055
+ * fold-const.c (build_zero_vector): New function to construct a
+ vector (either floating point or integer) of zeros.
+ (fold_convert): Internally, enable conversions of integer zero
+ to arbitrary vector types, using the new build_zero_vector.
+
+2004-09-09 Roger Sayle <roger@eyesopen.com>
+
* config/i386/i386.c (ix86_expand_ashlsi3_const): New function to
expand a left shift by an immediate constant as either an ashl or
a sequence of additions.
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index f6c5396..10cdb69 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -89,6 +89,7 @@ static tree negate_expr (tree);
static tree split_tree (tree, enum tree_code, tree *, tree *, tree *, int);
static tree associate_trees (tree, tree, enum tree_code, tree);
static tree const_binop (enum tree_code, tree, tree, int);
+static tree build_zero_vector (tree);
static tree fold_convert_const (enum tree_code, tree, tree);
static enum tree_code invert_tree_comparison (enum tree_code, bool);
static enum comparison_code comparison_to_compcode (enum tree_code);
@@ -1677,6 +1678,23 @@ size_diffop (tree arg0, tree arg1)
arg1, arg0)));
}
+/* Construct a vector of zero elements of vector type TYPE. */
+
+static tree
+build_zero_vector (tree type)
+{
+ tree elem, list;
+ int i, units;
+
+ elem = fold_convert_const (NOP_EXPR, TREE_TYPE (type), integer_zero_node);
+ units = TYPE_VECTOR_SUBPARTS (type);
+
+ list = NULL_TREE;
+ for (i = 0; i < units; i++)
+ list = tree_cons (NULL_TREE, elem, list);
+ return build_vector (type, list);
+}
+
/* Attempt to fold type conversion operation CODE of expression ARG1 to
type TYPE. If no simplification can be done return NULL_TREE. */
@@ -1940,6 +1958,8 @@ fold_convert (tree type, tree arg)
}
case VECTOR_TYPE:
+ if (integer_zerop (arg))
+ return build_zero_vector (type);
gcc_assert (tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (orig)));
gcc_assert (INTEGRAL_TYPE_P (orig) || POINTER_TYPE_P (orig)
|| TREE_CODE (orig) == VECTOR_TYPE);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 0e07e95..bf369b9 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2004-09-09 Roger Sayle <roger@eyesopen.com>
+
+ PR middle-end/17055
+ * gcc.dg/pr17055-1.c: New test case.
+
2004-09-09 Hans-Peter Nilsson <hp@axis.com>
PR target/17377
diff --git a/gcc/testsuite/gcc.dg/pr17055-1.c b/gcc/testsuite/gcc.dg/pr17055-1.c
new file mode 100644
index 0000000..4c30973
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr17055-1.c
@@ -0,0 +1,24 @@
+/* PR middle-end/17055. */
+/* { dg-do compile } */
+/* { dg-options "-O2 -ffast-math" } */
+
+/* This test used to abort, beacuse we do an "integer" fold to zero, i.e.
+ x - x = (T)0 where T is the type of x. Unfortunately, fold_convert
+ was unable to convert integer_zero_node to the appropriate vector type. */
+
+typedef float v4sf __attribute__((vector_size(16)));
+typedef int v4si __attribute__((vector_size(16)));
+
+v4sf ivf, ovf;
+v4si ivi, ovi;
+
+void testf (void)
+{
+ ovf = ivf - ivf;
+}
+
+void testi (void)
+{
+ ovi = ivi - ivi;
+}
+