This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix ICE with vector types in X % -Y pattern (PR middle-end/70050)


We crashed on the attached testcase because we were trying to apply the
X % -Y -> X % Y transformation even on vectors.  That doesn't go well with the
check for !TYPE_UNSIGNED.  So I think let's limit the pattern to only work on
integral types.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2016-03-03  Marek Polacek  <polacek@redhat.com>

	PR middle-end/70050
	* match.pd (X % -Y): Add INTEGRAL_TYPE_P check.

	* gcc.dg/pr70050.c: New test.

diff --git gcc/match.pd gcc/match.pd
index 5903782..112deb3 100644
--- gcc/match.pd
+++ gcc/match.pd
@@ -293,7 +293,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 /* X % -Y is the same as X % Y.  */
 (simplify
  (trunc_mod @0 (convert? (negate @1)))
- (if (!TYPE_UNSIGNED (type)
+ (if (INTEGRAL_TYPE_P (type)
+      && !TYPE_UNSIGNED (type)
       && !TYPE_OVERFLOW_TRAPS (type)
       && tree_nop_conversion_p (type, TREE_TYPE (@1))
       /* Avoid this transformation if X might be INT_MIN or
diff --git gcc/testsuite/gcc.dg/pr70050.c gcc/testsuite/gcc.dg/pr70050.c
index e69de29..610456f 100644
--- gcc/testsuite/gcc.dg/pr70050.c
+++ gcc/testsuite/gcc.dg/pr70050.c
@@ -0,0 +1,11 @@
+/* PR middle-end/70025 */
+/* { dg-do compile } */
+/* { dg-options "-Wno-psabi" } */
+
+typedef int v8si __attribute__ ((vector_size (32)));
+
+v8si
+foo (v8si v)
+{
+  return v %= -v;
+}

	Marek


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]