diff mbox series

[10] tree-opt: Fix segfault in tree-if-conv.c with -march=armv8.2-a+sve [PR97849]

Message ID 20210331133042.n7e3oy37yyvfgo4y@arm.com
State New
Headers show
Series [10] tree-opt: Fix segfault in tree-if-conv.c with -march=armv8.2-a+sve [PR97849] | expand

Commit Message

Alex Coplan March 31, 2021, 1:30 p.m. UTC
Hi all,

I'd like to backport the fix for PR97849 to GCC 10. The patch on trunk:
https://gcc.gnu.org/g:5700973f4a30762b4fc21687bb5f7843e55da2e4
applies cleanly to the 10 branch.

Bootstrapped and regtested on aarch64-linux-gnu, no regressions.

OK for GCC 10.3?

Thanks,
Alex

---

gcc/ChangeLog
2020-11-24  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>

        PR tree-optimization/97849
        * tree-if-conv.c (tree_if_conversion): Move ssa_name
        replacement code from ifcvt_local_dce to this function
        before calling do_rpo_vn.

gcc/testsuite/ChangeLog
2020-11-24  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>

        PR tree-optimization/97849
        * gcc.dg/tree-ssa/pr97849.c: New test.

Comments

Richard Biener March 31, 2021, 1:35 p.m. UTC | #1
On Wed, Mar 31, 2021 at 3:31 PM Alex Coplan via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> Hi all,
>
> I'd like to backport the fix for PR97849 to GCC 10. The patch on trunk:
> https://gcc.gnu.org/g:5700973f4a30762b4fc21687bb5f7843e55da2e4
> applies cleanly to the 10 branch.
>
> Bootstrapped and regtested on aarch64-linux-gnu, no regressions.
>
> OK for GCC 10.3?

OK.

> Thanks,
> Alex
>
> ---
>
> gcc/ChangeLog
> 2020-11-24  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
>
>         PR tree-optimization/97849
>         * tree-if-conv.c (tree_if_conversion): Move ssa_name
>         replacement code from ifcvt_local_dce to this function
>         before calling do_rpo_vn.
>
> gcc/testsuite/ChangeLog
> 2020-11-24  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
>
>         PR tree-optimization/97849
>         * gcc.dg/tree-ssa/pr97849.c: New test.
diff mbox series

Patch

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr97849.c b/gcc/testsuite/gcc.dg/tree-ssa/pr97849.c
new file mode 100644
index 00000000000..57a31e316a2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr97849.c
@@ -0,0 +1,16 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O1 -ftree-vectorize" } */
+/* { dg-additional-options "-march=armv8.2-a+sve" { target aarch64*-*-* } } */
+
+int a, b, c;
+
+int g() {
+  char i = 0;
+  for (c = 0; c <= 8; c++)
+    --i;
+
+  while (b) {
+    _Bool f = i <= 0;
+    a = (a == 0) ? 0 : f / a;
+  }
+}
diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c
index 2062758f40f..93effaa811b 100644
--- a/gcc/tree-if-conv.c
+++ b/gcc/tree-if-conv.c
@@ -2916,12 +2916,6 @@  ifcvt_local_dce (class loop *loop)
   enum gimple_code code;
   use_operand_p use_p;
   imm_use_iterator imm_iter;
-  std::pair <tree, tree> *name_pair;
-  unsigned int i;
-
-  FOR_EACH_VEC_ELT (redundant_ssa_names, i, name_pair)
-    replace_uses_by (name_pair->first, name_pair->second);
-  redundant_ssa_names.release ();
 
   /* The loop has a single BB only.  */
   basic_block bb = loop->header;
@@ -3124,6 +3118,13 @@  tree_if_conversion (class loop *loop, vec<gimple *> *preds)
   exit_bbs = BITMAP_ALLOC (NULL);
   bitmap_set_bit (exit_bbs, single_exit (loop)->dest->index);
   bitmap_set_bit (exit_bbs, loop->latch->index);
+
+  std::pair <tree, tree> *name_pair;
+  unsigned ssa_names_idx;
+  FOR_EACH_VEC_ELT (redundant_ssa_names, ssa_names_idx, name_pair)
+    replace_uses_by (name_pair->first, name_pair->second);
+  redundant_ssa_names.release ();
+
   todo |= do_rpo_vn (cfun, loop_preheader_edge (loop), exit_bbs);
 
   /* Delete dead predicate computations.  */