[committed] Fix EXTRACT_LAST_REDUCTION segfault

Richard Sandiford richard.sandiford@arm.com
Tue Dec 31 16:48:00 GMT 2019


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.

Tested on aarch64-linux-gnu and applied as obvious.

Richard


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.

Index: gcc/tree-vect-stmts.c
===================================================================
--- gcc/tree-vect-stmts.c	2019-12-29 09:27:46.623861776 +0000
+++ gcc/tree-vect-stmts.c	2019-12-31 15:31:37.226253333 +0000
@@ -10033,10 +10033,12 @@ vectorizable_condition (stmt_vec_info st
 	  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);
     }
 
Index: gcc/testsuite/gcc.dg/vect/vect-cond-reduc-6.c
===================================================================
--- /dev/null	2019-09-17 11:41:18.176664108 +0100
+++ gcc/testsuite/gcc.dg/vect/vect-cond-reduc-6.c	2019-12-31 15:31:37.226253333 +0000
@@ -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;
+}



More information about the Gcc-patches mailing list