]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Fix VSETVL PASS bug in exception handling
authorJu-Zhe Zhong <juzhe.zhong@rivai.ai>
Sat, 4 Feb 2023 01:09:30 +0000 (09:09 +0800)
committerKito Cheng <kito.cheng@sifive.com>
Sun, 12 Feb 2023 02:58:04 +0000 (10:58 +0800)
gcc/ChangeLog:

* config/riscv/riscv-vsetvl.cc (pass_vsetvl::compute_probabilities): Skip exit block.

gcc/testsuite/ChangeLog:

* g++.target/riscv/rvv/base/exception-1.C: New test.

gcc/config/riscv/riscv-vsetvl.cc
gcc/testsuite/g++.target/riscv/rvv/base/exception-1.C [new file with mode: 0644]

index ef5b74c58d241f8c5731c1e82def9e6fc89008d4..8e6063ae83bc682cf5478cec40af8e8957502d01 100644 (file)
@@ -3492,8 +3492,15 @@ pass_vsetvl::compute_probabilities (void)
       basic_block cfg_bb = bb->cfg_bb ();
       auto &curr_prob
        = m_vector_manager->vector_block_infos[cfg_bb->index].probability;
+
+      /* GCC assume entry block (bb 0) are always so
+        executed so set its probability as "always".  */
       if (ENTRY_BLOCK_PTR_FOR_FN (cfun) == cfg_bb)
        curr_prob = profile_probability::always ();
+      /* Exit block (bb 1) is the block we don't need to process.  */
+      if (EXIT_BLOCK_PTR_FOR_FN (cfun) == cfg_bb)
+       continue;
+
       gcc_assert (curr_prob.initialized_p ());
       FOR_EACH_EDGE (e, ei, cfg_bb->succs)
        {
@@ -3507,9 +3514,6 @@ pass_vsetvl::compute_probabilities (void)
            new_prob += curr_prob * e->probability;
        }
     }
-  auto &exit_block
-    = m_vector_manager->vector_block_infos[EXIT_BLOCK_PTR_FOR_FN (cfun)->index];
-  exit_block.probability = profile_probability::always ();
 }
 
 /* Lazy vsetvl insertion for optimize > 0. */
diff --git a/gcc/testsuite/g++.target/riscv/rvv/base/exception-1.C b/gcc/testsuite/g++.target/riscv/rvv/base/exception-1.C
new file mode 100644 (file)
index 0000000..deabfd2
--- /dev/null
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32d -O3" } */
+
+#include "riscv_vector.h"
+void __attribute__((noinline)) foo(int arr[4]) {
+__builtin_printf("%d %d %d %d\n", arr[0], arr[1], arr[2], arr[3]);
+}
+
+void __attribute__((noinline)) test() {
+// Intialization with 2 memsets leads to spilling of zero-splat value
+vint32m1_t a;
+int arr1[4] = {};
+foo(arr1);
+int arr2[4] = {};
+foo(arr2);
+asm volatile ("# %0" : "+vr" (a));
+throw int();
+}
+
+int main() {
+try {
+   test();
+} catch (...) {
+   __builtin_printf("hello\n");
+};
+return 0;
+}