[PATCH] rs6000: Fix ICE expanding lxvp and stxvp gimple built-ins [PR101849]

Peter Bergner bergner@linux.ibm.com
Tue Aug 10 23:37:35 GMT 2021


PR101849 shows we ICE on a test case when we pass a non __vector_pair *
pointer to the __builtin_vsx_lxvp and __builtin_vsx_stxvp built-ins
that is cast to __vector_pair *.  The problem is that when we expand
the built-in, the cast has already been removed from gimple and we are
only given the base pointer.  The solution used here (which fixes the ICE)
is to catch this case and convert the pointer to a __vector_pair * pointer
when expanding the built-in.

This passed bootstrap and regression testing on powerpc64le-linux with
no regressions.  Ok for mainline?  This also affects GCC 11 and 10, so
ok there too after it has baked on trunk for a few days?

Peter


gcc/
	PR target/101849
	* config/rs6000/rs6000-call.c (rs6000_gimple_fold_mma_builtin): Cast
	pointer to __vector_pair *.

gcc/testsuite/
	PR target/101849
	* gcc.target/powerpc/pr101849.c: New test.


diff --git a/gcc/config/rs6000/rs6000-call.c b/gcc/config/rs6000/rs6000-call.c
index 904e104c058..d04011c0489 100644
--- a/gcc/config/rs6000/rs6000-call.c
+++ b/gcc/config/rs6000/rs6000-call.c
@@ -11919,6 +11919,9 @@ rs6000_gimple_fold_mma_builtin (gimple_stmt_iterator *gsi)
       tree offset = gimple_call_arg (stmt, 0);
       tree ptr = gimple_call_arg (stmt, 1);
       tree lhs = gimple_call_lhs (stmt);
+      if (TREE_TYPE (TREE_TYPE (ptr)) != vector_pair_type_node)
+	ptr = build1 (VIEW_CONVERT_EXPR,
+		      build_pointer_type (vector_pair_type_node), ptr);
       tree mem = build_simple_mem_ref (build2 (POINTER_PLUS_EXPR,
 					       TREE_TYPE (ptr), ptr, offset));
       gimplify_assign (lhs, mem, &new_seq);
@@ -11932,6 +11935,9 @@ rs6000_gimple_fold_mma_builtin (gimple_stmt_iterator *gsi)
       tree src = gimple_call_arg (stmt, 0);
       tree offset = gimple_call_arg (stmt, 1);
       tree ptr = gimple_call_arg (stmt, 2);
+      if (TREE_TYPE (TREE_TYPE (ptr)) != vector_pair_type_node)
+	ptr = build1 (VIEW_CONVERT_EXPR,
+		      build_pointer_type (vector_pair_type_node), ptr);
       tree mem = build_simple_mem_ref (build2 (POINTER_PLUS_EXPR,
 					       TREE_TYPE (ptr), ptr, offset));
       gimplify_assign (mem, src, &new_seq);
diff --git a/gcc/testsuite/gcc.target/powerpc/pr101849.c b/gcc/testsuite/gcc.target/powerpc/pr101849.c
new file mode 100644
index 00000000000..6d2e3b79282
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr101849.c
@@ -0,0 +1,19 @@
+/* PR target/101849 */
+/* { dg-do compile } */
+/* { dg-require-effective-target power10_ok } */
+/* { dg-options "-O2 -mdejagnu-cpu=power10" } */
+
+/* Verify we do not ICE on the tests below.  */
+
+__vector_pair vp;
+void
+foo (double *x)
+{
+   vp = __builtin_vsx_lxvp (0, (__vector_pair *)(void *)x);
+}
+
+void
+bar (__vector_pair *src, double *x)
+{
+  __builtin_vsx_stxvp (*src, 0, (__vector_pair *)(void *)x);
+}


More information about the Gcc-patches mailing list