]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR rtl-optimization/80385 (Segfault in commutative_operand_precedence...
authorJakub Jelinek <jakub@redhat.com>
Tue, 30 May 2017 08:26:33 +0000 (10:26 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 30 May 2017 08:26:33 +0000 (10:26 +0200)
Backported from mainline
2017-04-11  Jakub Jelinek  <jakub@redhat.com>

PR rtl-optimization/80385
* simplify-rtx.c (simplify_unary_operation_1): Don't transform
(not (neg X)) into (plus X -1) for complex or non-integral modes.

* g++.dg/opt/pr80385.C: New test.

From-SVN: r248672

gcc/ChangeLog
gcc/simplify-rtx.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/pr80385.C [new file with mode: 0644]

index 24ddc3397a5ca7427d9fbc928b4eeed080bb65a4..f81669cf787855aeeaf26f746839477ab1d0305d 100644 (file)
@@ -3,6 +3,10 @@
        Backported from mainline
        2017-04-11  Jakub Jelinek  <jakub@redhat.com>
 
+       PR rtl-optimization/80385
+       * simplify-rtx.c (simplify_unary_operation_1): Don't transform
+       (not (neg X)) into (plus X -1) for complex or non-integral modes.
+
        PR libgomp/80394
        * omp-low.c (scan_omp_task): Don't optimize away empty tasks
        if they have any depend clauses.
index 2982bd21a1ed6163eb47d491bbb3b54b5b9f7a33..5f732b279c8c92be9eb34b8758dd9dc6440cd4c8 100644 (file)
@@ -874,8 +874,10 @@ simplify_unary_operation_1 (enum rtx_code code, machine_mode mode, rtx op)
          && XEXP (op, 1) == constm1_rtx)
        return simplify_gen_unary (NEG, mode, XEXP (op, 0), mode);
 
-      /* Similarly, (not (neg X)) is (plus X -1).  */
-      if (GET_CODE (op) == NEG)
+      /* Similarly, (not (neg X)) is (plus X -1).  Only do this for
+        modes that have CONSTM1_RTX, i.e. MODE_INT, MODE_PARTIAL_INT
+        and MODE_VECTOR_INT.  */
+      if (GET_CODE (op) == NEG && CONSTM1_RTX (mode))
        return simplify_gen_binary (PLUS, mode, XEXP (op, 0),
                                    CONSTM1_RTX (mode));
 
index 3494df82b19ba84a9fa82235e42b1984f92d9ed6..930ceb1d97b460038c63c445261bd929a5007872 100644 (file)
@@ -3,6 +3,9 @@
        Backported from mainline
        2017-04-11  Jakub Jelinek  <jakub@redhat.com>
 
+       PR rtl-optimization/80385
+       * g++.dg/opt/pr80385.C: New test.
+
        PR c++/80363
        * g++.dg/ext/pr80363.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/opt/pr80385.C b/gcc/testsuite/g++.dg/opt/pr80385.C
new file mode 100644 (file)
index 0000000..f18abc9
--- /dev/null
@@ -0,0 +1,14 @@
+// PR rtl-optimization/80385
+// { dg-do compile { target { i?86-*-* x86_64-*-* } } }
+// { dg-options "-Ofast -msse2" }
+
+#include <x86intrin.h>
+
+__m128 a, e;
+struct A { __m128 b; A (); A (__m128 x) : b(x) {} };
+A operator+ (A, A);
+A operator- (A) { __m128 c = -a; return c; }
+A foo (A x) { __m128 d = x.b; return _mm_andnot_ps (d, e); }
+struct B { A n[1]; };
+void bar (B x) { A f = foo (x.n[0]); A g = f + A (); }
+void baz () { B h; B i; A j; i.n[0] = -j; h = i; B k = h; bar (k); }