When we emit a sequence before a preexisting insn and naming a BB to
store in the insns, we will attempt to store the BB even in barriers
present in the sequence.

Barriers don't expect blocks, and rtl checking catches the problem.

When emitting after a preexisting insn, we skip the block setting in
barriers.  Change the before emitter to do so as well.

Regstrapped on x86_64-linux-gnu.  Testcase used to reproduce the problem
and to confirm the fix with a cross to riscv32-elf configured with rtl
checking.  Ok to install?


for  gcc/ChangeLog

        PR middle-end/113506
        * emit-rtl.cc (add_insn_before): Don't set the block of a
        barrier.

for  gcc/testsuite/ChangeLog

        PR middle-end/113506
        * gcc.target/riscv/pr113506.c: New.
---
 gcc/emit-rtl.cc                           |    6 ++++--
 gcc/testsuite/gcc.target/riscv/pr113506.c |   15 +++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/pr113506.c

diff --git a/gcc/emit-rtl.cc b/gcc/emit-rtl.cc
index a556692e8a02a..3af6849a29bc6 100644
--- a/gcc/emit-rtl.cc
+++ b/gcc/emit-rtl.cc
@@ -4369,9 +4369,11 @@ add_insn_before (rtx_insn *insn, rtx_insn *before, 
basic_block bb)
 {
   add_insn_before_nobb (insn, before);
 
+  if (BARRIER_P (insn))
+    return;
+
   if (!bb
-      && !BARRIER_P (before)
-      && !BARRIER_P (insn))
+      && !BARRIER_P (before))
     bb = BLOCK_FOR_INSN (before);
 
   if (bb)
diff --git a/gcc/testsuite/gcc.target/riscv/pr113506.c 
b/gcc/testsuite/gcc.target/riscv/pr113506.c
new file mode 100644
index 0000000000000..404dda9fd532d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/pr113506.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-fchecking=1 -Os -fno-tree-coalesce-vars -finline-stringops" 
} */
+
+typedef unsigned v32su __attribute__((vector_size (32)));
+
+v32su foo_v32su_4;
+
+unsigned
+foo (v32su v32su_2)
+{
+  v32su_2 *= v32su_2;
+  if (foo_v32su_4[3])
+    v32su_2 &= (v32su){};
+  return v32su_2[1];
+}


-- 
Alexandre Oliva, happy hacker            https://FSFLA.org/blogs/lxo/
   Free Software Activist                   GNU Toolchain Engineer
More tolerance and less prejudice are key for inclusion and diversity
Excluding neuro-others for not behaving ""normal"" is *not* inclusive

Reply via email to