public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-4533] PR107920: Fix handling of virtual operands and disable folding for -fnon-call-exceptions.
@ 2022-12-07  8:06 Prathamesh Kulkarni
  0 siblings, 0 replies; only message in thread
From: Prathamesh Kulkarni @ 2022-12-07  8:06 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:cb6922f490d3133e4ccbc1190b555d16695fc9c3

commit r13-4533-gcb6922f490d3133e4ccbc1190b555d16695fc9c3
Author: Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
Date:   Wed Dec 7 13:34:02 2022 +0530

    PR107920: Fix handling of virtual operands and disable folding for -fnon-call-exceptions.
    
    gcc/ChangeLog:
            PR target/107920
            * config/aarch64/aarch64-sve-builtins-base.cc: Use
            gsi_replace_with_seq_vops to handle virtual operands, and gate
            the transform on !flag_non_call_exceptions.
            * gimple-fold.cc (gsi_replace_with_seq_vops): Make function non static.
            * gimple-fold.h (gsi_replace_with_seq_vops): Declare.
    
    gcc/testsuite/ChangeLog:
            PR target/107920
            * gcc.target/aarch64/sve/acle/general/pr107920.c: New test.
            * g++.target/aarch64/sve/pr107920.C: Likewise.

Diff:
---
 gcc/config/aarch64/aarch64-sve-builtins-base.cc       | 15 +++++++++++----
 gcc/gimple-fold.cc                                    |  2 +-
 gcc/gimple-fold.h                                     |  1 +
 gcc/testsuite/g++.target/aarch64/sve/pr107920.C       | 19 +++++++++++++++++++
 .../gcc.target/aarch64/sve/acle/general/pr107920.c    | 10 ++++++++++
 5 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-sve-builtins-base.cc b/gcc/config/aarch64/aarch64-sve-builtins-base.cc
index 6347407555f..d52ec083ed0 100644
--- a/gcc/config/aarch64/aarch64-sve-builtins-base.cc
+++ b/gcc/config/aarch64/aarch64-sve-builtins-base.cc
@@ -45,6 +45,7 @@
 #include "aarch64-sve-builtins-base.h"
 #include "aarch64-sve-builtins-functions.h"
 #include "ssa.h"
+#include "gimple-fold.h"
 
 using namespace aarch64_sve;
 
@@ -1209,7 +1210,8 @@ public:
        vectype is the corresponding ADVSIMD type.  */
 
     if (!BYTES_BIG_ENDIAN
-	&& integer_all_onesp (arg0))
+	&& integer_all_onesp (arg0)
+	&& !flag_non_call_exceptions)
       {
 	tree lhs = gimple_call_lhs (f.call);
 	tree lhs_type = TREE_TYPE (lhs);
@@ -1232,7 +1234,9 @@ public:
 	tree mem_ref_op = fold_build2 (MEM_REF, access_type, arg1, zero);
 	gimple *mem_ref_stmt
 	  = gimple_build_assign (mem_ref_lhs, mem_ref_op);
-	gsi_insert_before (f.gsi, mem_ref_stmt, GSI_SAME_STMT);
+
+	gimple_seq stmts = NULL;
+	gimple_seq_add_stmt_without_update (&stmts, mem_ref_stmt);
 
 	int source_nelts = TYPE_VECTOR_SUBPARTS (access_type).to_constant ();
 	vec_perm_builder sel (lhs_len, source_nelts, 1);
@@ -1245,8 +1249,11 @@ public:
 						   indices));
 	tree mask_type = build_vector_type (ssizetype, lhs_len);
 	tree mask = vec_perm_indices_to_tree (mask_type, indices);
-	return gimple_build_assign (lhs, VEC_PERM_EXPR,
-				    mem_ref_lhs, mem_ref_lhs, mask);
+	gimple *g2 = gimple_build_assign (lhs, VEC_PERM_EXPR,
+					  mem_ref_lhs, mem_ref_lhs, mask);
+	gimple_seq_add_stmt_without_update (&stmts, g2);
+	gsi_replace_with_seq_vops (f.gsi, stmts);
+	return g2;
       }
 
     return NULL;
diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 88d14c7adcc..c87e17f5763 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -591,7 +591,7 @@ fold_gimple_assign (gimple_stmt_iterator *si)
    If the statement has a lhs the last stmt in the sequence is expected
    to assign to that lhs.  */
 
-static void
+void
 gsi_replace_with_seq_vops (gimple_stmt_iterator *si_p, gimple_seq stmts)
 {
   gimple *stmt = gsi_stmt (*si_p);
diff --git a/gcc/gimple-fold.h b/gcc/gimple-fold.h
index 7d29ee9a9a4..87ed4e56d25 100644
--- a/gcc/gimple-fold.h
+++ b/gcc/gimple-fold.h
@@ -63,6 +63,7 @@ extern bool arith_code_with_undefined_signed_overflow (tree_code);
 extern gimple_seq rewrite_to_defined_overflow (gimple *, bool = false);
 extern void replace_call_with_value (gimple_stmt_iterator *, tree);
 extern tree tree_vec_extract (gimple_stmt_iterator *, tree, tree, tree, tree);
+extern void gsi_replace_with_seq_vops (gimple_stmt_iterator *, gimple_seq);
 
 /* gimple_build, functionally matching fold_buildN, outputs stmts
    int the provided sequence, matching and simplifying them on-the-fly.
diff --git a/gcc/testsuite/g++.target/aarch64/sve/pr107920.C b/gcc/testsuite/g++.target/aarch64/sve/pr107920.C
new file mode 100644
index 00000000000..179b2b605bc
--- /dev/null
+++ b/gcc/testsuite/g++.target/aarch64/sve/pr107920.C
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fnon-call-exceptions" } */
+
+#include "arm_sve.h"
+
+svint8_t
+test_s8(int8_t *x)
+{
+  try
+    {
+      return svld1rq_s8 (svptrue_b8 (), &x[0]);
+    }
+  catch (...)
+    {
+      return svdup_s8 (1);
+    }
+}
+
+/* { dg-final { scan-assembler "__cxa_begin_catch" } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr107920.c b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr107920.c
new file mode 100644
index 00000000000..11448ed5e68
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr107920.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fno-tree-ccp -fno-tree-forwprop" } */
+
+#include "arm_sve.h"
+
+svint8_t
+test_s8(int8_t *x)
+{
+  return svld1rq_s8 (svptrue_b8 (), &x[0]);
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-07  8:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-07  8:06 [gcc r13-4533] PR107920: Fix handling of virtual operands and disable folding for -fnon-call-exceptions Prathamesh Kulkarni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).