Fix EXTRACT_LAST_REDUCTION segfault
authorRichard Sandiford <richard.sandiford@arm.com>
Tue, 31 Dec 2019 15:32:06 +0000 (15:32 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Tue, 31 Dec 2019 15:32:06 +0000 (15:32 +0000)
This code:

      /* Make sure we don't accidentally use the old condition.  */
      cond_expr = NULL_TREE;

was misplaced, since it triggered even when we needed to force the
original unmodified cond_expr into a mask temporary and then invert it.

2019-12-31  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
* tree-vect-stmts.c (vectorizable_condition): Only nullify cond_expr
if we've created a new condition.  Don't nullify it if we've decided
to keep it and then invert the result.

gcc/testsuite/
* gcc.dg/vect/vect-cond-reduc-6.c: New test.

From-SVN: r279804

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/vect-cond-reduc-6.c [new file with mode: 0644]
gcc/tree-vect-stmts.c

index a75b9012e58158c3562bc1592838dfeb188a757c..9f5782fd458f803833a7b91427ea2a3093818524 100644 (file)
@@ -1,3 +1,9 @@
+2020-12-31  Richard Sandiford  <richard.sandiford@arm.com>
+
+       * tree-vect-stmts.c (vectorizable_condition): Only nullify cond_expr
+       if we've created a new condition.  Don't nullify it if we've decided
+       to keep it and then invert the result.
+
 2020-12-31  Richard Sandiford  <richard.sandiford@arm.com>
 
        * tree-vect-loop-manip.c (create_lcssa_for_virtual_phi): Return
index 097c61d6f7dae20483e2cfa3e1537f09c95cd7e0..b3211aafefceb186619cfd8a000b2baa81ffbf54 100644 (file)
@@ -1,3 +1,7 @@
+2020-12-31  Richard Sandiford  <richard.sandiford@arm.com>
+
+       * gcc.dg/vect/vect-cond-reduc-6.c: New test.
+
 2020-12-31  Richard Sandiford  <richard.sandiford@arm.com>
 
        * gcc.dg/vect/vect-epilogues-2.c: New test.
diff --git a/gcc/testsuite/gcc.dg/vect/vect-cond-reduc-6.c b/gcc/testsuite/gcc.dg/vect/vect-cond-reduc-6.c
new file mode 100644 (file)
index 0000000..f1a2209
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+
+int
+f (int *y)
+{
+  int res = 0;
+  for (int i = 0; i < 100; ++i)
+    res = (y[i] & 1) == 0 && (y[i] < 10) ? res : 1;
+  return res;
+}
index d4468083cd0b1288b06b4e22436a592f1516f502..0ce97935f44ed24160edec830cf8a5c2104926e9 100644 (file)
@@ -10033,10 +10033,12 @@ vectorizable_condition (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
          if (new_code == ERROR_MARK)
            must_invert_cmp_result = true;
          else
-           cond_code = new_code;
+           {
+             cond_code = new_code;
+             /* Make sure we don't accidentally use the old condition.  */
+             cond_expr = NULL_TREE;
+           }
        }
-      /* Make sure we don't accidentally use the old condition.  */
-      cond_expr = NULL_TREE;
       std::swap (then_clause, else_clause);
     }