From 3efe2e2cc10787a69473b926e100d4dde302f638 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>
Date: Wed, 19 Mar 2014 10:13:32 +0100
Subject: [PATCH] re PR tree-optimization/60559 (g++.dg/vect/pr60023.cc fails
 with -fno-tree-dce (ICE))

	PR tree-optimization/60559
	* vectorizable_mask_load_store): Replace scalar MASK_LOAD
	with build_zero_cst assignment.

	* g++.dg/vect/pr60559.cc: New test.

From-SVN: r208676
---
 gcc/ChangeLog                        |  6 ++++++
 gcc/testsuite/ChangeLog              |  5 +++++
 gcc/testsuite/g++.dg/vect/pr60559.cc |  8 ++++++++
 gcc/tree-vect-stmts.c                | 21 +++++++++++++++++++++
 4 files changed, 40 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/vect/pr60559.cc

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 6f408a5b13da..5785c61919cb 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-19  Jakub Jelinek  <jakub@redhat.com>
+
+	PR tree-optimization/60559
+	* vectorizable_mask_load_store): Replace scalar MASK_LOAD
+	with build_zero_cst assignment.
+
 2014-03-18  Kai Tietz  <ktietz@redhat.com>
 
 	PR rtl-optimization/56356
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d41d926f858d..67cf9ddc6f5f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2014-03-19  Jakub Jelinek  <jakub@redhat.com>
+
+	PR tree-optimization/60559
+	* g++.dg/vect/pr60559.cc: New test.
+
 2014-03-18  Ian Lance Taylor  <iant@google.com>
 
 	PR target/60563
diff --git a/gcc/testsuite/g++.dg/vect/pr60559.cc b/gcc/testsuite/g++.dg/vect/pr60559.cc
new file mode 100644
index 000000000000..f179a1aebcf8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/vect/pr60559.cc
@@ -0,0 +1,8 @@
+// PR tree-optimization/60559
+// { dg-do compile }
+// { dg-additional-options "-O3 -std=c++11 -fnon-call-exceptions -fno-tree-dce" }
+// { dg-additional-options "-mavx2" { target { i?86-*-* x86_64-*-* } } }
+
+#include "pr60023.cc"
+
+// { dg-final { cleanup-tree-dump "vect" } }
diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
index 70fb411f8f54..884e769c8848 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -2038,6 +2038,15 @@ vectorizable_mask_load_store (gimple stmt, gimple_stmt_iterator *gsi,
 	    STMT_VINFO_RELATED_STMT (prev_stmt_info) = new_stmt;
 	  prev_stmt_info = vinfo_for_stmt (new_stmt);
 	}
+
+      /* Ensure that even with -fno-tree-dce the scalar MASK_LOAD is removed
+	 from the IL.  */
+      tree lhs = gimple_call_lhs (stmt);
+      new_stmt = gimple_build_assign (lhs, build_zero_cst (TREE_TYPE (lhs)));
+      set_vinfo_for_stmt (new_stmt, stmt_info);
+      set_vinfo_for_stmt (stmt, NULL);
+      STMT_VINFO_STMT (stmt_info) = new_stmt;
+      gsi_replace (gsi, new_stmt, true);
       return true;
     }
   else if (is_store)
@@ -2149,6 +2158,18 @@ vectorizable_mask_load_store (gimple stmt, gimple_stmt_iterator *gsi,
 	}
     }
 
+  if (!is_store)
+    {
+      /* Ensure that even with -fno-tree-dce the scalar MASK_LOAD is removed
+	 from the IL.  */
+      tree lhs = gimple_call_lhs (stmt);
+      new_stmt = gimple_build_assign (lhs, build_zero_cst (TREE_TYPE (lhs)));
+      set_vinfo_for_stmt (new_stmt, stmt_info);
+      set_vinfo_for_stmt (stmt, NULL);
+      STMT_VINFO_STMT (stmt_info) = new_stmt;
+      gsi_replace (gsi, new_stmt, true);
+    }
+
   return true;
 }
 
-- 
GitLab