PR target/106278: Keep REG_EQUAL notes consistent during TImode STV.

Message ID 01b601d897a2$f1e6cac0$d5b46040$@nextmovesoftware.com
State New
Headers
Series PR target/106278: Keep REG_EQUAL notes consistent during TImode STV. |

Commit Message

Roger Sayle July 14, 2022, 4:58 p.m. UTC
  This patch resolves PR target/106278 a regression on x86_64 caused by my
recent TImode STV improvements.  Now that TImode STV can handle comparisons
such as "(set (regs:CC) (compare:CC (reg:TI) ...))" the convert_insn method
sensibly checks that the mode of the SET_DEST is TImode before setting
it to V1TImode [to avoid V1TImode appearing on the hard reg CC_FLAGS.

Hence the current code looks like:

      if (GET_MODE (dst) == TImode)
        {
          tmp = find_reg_equal_equiv_note (insn);
          if (tmp && GET_MODE (XEXP (tmp, 0)) == TImode)
            PUT_MODE (XEXP (tmp, 0), V1TImode);
          PUT_MODE (dst, V1TImode);
          fix_debug_reg_uses (dst);
        }
      break;

which checks GET_MODE (dst) before calling PUT_MODE, and when a
change is made updating the REG_EQUAL_NOTE tmp if it exists.

The logical flaw (oversight) is that due to RTL sharing, the destination
of this set may already have been updated to V1TImode, as this chain is
being converted, but we still need to update any REG_EQUAL_NOTE that
still has TImode.  Hence the correct code is actually:


      if (GET_MODE (dst) == TImode)
        {
          PUT_MODE (dst, V1TImode);
          fix_debug_reg_uses (dst);
        }
      if (GET_MODE (dst) == V1TImode)
        {
          tmp = find_reg_equal_equiv_note (insn);
          if (tmp && GET_MODE (XEXP (tmp, 0)) == TImode)
            PUT_MODE (XEXP (tmp, 0), V1TImode);
        }
      break;

While fixing this behavior, I noticed I had some indentation whitespace
issues and some vestigial dead code in this function/method that I've
taken the liberty of cleaning up (as obvious) in this patch.

This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
and make -k check, both with and without --target_board=unix{-m32},
with no new failures.  Ok for mainline?


2022-07-14  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
        PR target/106278
        * config/i386/i386-features.cc (general_scalar_chain::convert_insn):
        Fix indentation whitespace.
        (timode_scalar_chain::fix_debug_reg_uses): Likewise.
        (timode_scalar_chain::convert_insn): Delete dead code.
        Update TImode REG_EQUAL_NOTE even if the SET_DEST is already V1TI.
        Fix indentation whitespace.
        (convertible_comparison_p): Likewise.
        (timode_scalar_to_vector_candidate_p): Likewise.

gcc/testsuite/ChangeLog
        PR target/106278
        * gcc.dg/pr106278.c: New test case.


Thanks in advance,
Roger
--
  

Comments

Uros Bizjak July 14, 2022, 7:05 p.m. UTC | #1
On Thu, Jul 14, 2022 at 6:58 PM Roger Sayle <roger@nextmovesoftware.com> wrote:
>
>
> This patch resolves PR target/106278 a regression on x86_64 caused by my
> recent TImode STV improvements.  Now that TImode STV can handle comparisons
> such as "(set (regs:CC) (compare:CC (reg:TI) ...))" the convert_insn method
> sensibly checks that the mode of the SET_DEST is TImode before setting
> it to V1TImode [to avoid V1TImode appearing on the hard reg CC_FLAGS.
>
> Hence the current code looks like:
>
>       if (GET_MODE (dst) == TImode)
>         {
>           tmp = find_reg_equal_equiv_note (insn);
>           if (tmp && GET_MODE (XEXP (tmp, 0)) == TImode)
>             PUT_MODE (XEXP (tmp, 0), V1TImode);
>           PUT_MODE (dst, V1TImode);
>           fix_debug_reg_uses (dst);
>         }
>       break;
>
> which checks GET_MODE (dst) before calling PUT_MODE, and when a
> change is made updating the REG_EQUAL_NOTE tmp if it exists.
>
> The logical flaw (oversight) is that due to RTL sharing, the destination
> of this set may already have been updated to V1TImode, as this chain is
> being converted, but we still need to update any REG_EQUAL_NOTE that
> still has TImode.  Hence the correct code is actually:
>
>
>       if (GET_MODE (dst) == TImode)
>         {
>           PUT_MODE (dst, V1TImode);
>           fix_debug_reg_uses (dst);
>         }
>       if (GET_MODE (dst) == V1TImode)
>         {
>           tmp = find_reg_equal_equiv_note (insn);
>           if (tmp && GET_MODE (XEXP (tmp, 0)) == TImode)
>             PUT_MODE (XEXP (tmp, 0), V1TImode);
>         }
>       break;
>
> While fixing this behavior, I noticed I had some indentation whitespace
> issues and some vestigial dead code in this function/method that I've
> taken the liberty of cleaning up (as obvious) in this patch.

While it is desired to fix cosmetic issues, those kinds of changes
unnecessarily make review of the patch more difficult.

> This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
> and make -k check, both with and without --target_board=unix{-m32},
> with no new failures.  Ok for mainline?

OK, but please do not mix cleanups with the functional changes.
Cleanups should be separated to a follow-up patch.

Thanks,
Uros.

>
>
> 2022-07-14  Roger Sayle  <roger@nextmovesoftware.com>
>
> gcc/ChangeLog
>         PR target/106278
>         * config/i386/i386-features.cc (general_scalar_chain::convert_insn):
>         Fix indentation whitespace.
>         (timode_scalar_chain::fix_debug_reg_uses): Likewise.
>         (timode_scalar_chain::convert_insn): Delete dead code.
>         Update TImode REG_EQUAL_NOTE even if the SET_DEST is already V1TI.
>         Fix indentation whitespace.
>         (convertible_comparison_p): Likewise.
>         (timode_scalar_to_vector_candidate_p): Likewise.
>
> gcc/testsuite/ChangeLog
>         PR target/106278
>         * gcc.dg/pr106278.c: New test case.
>
>
> Thanks in advance,
> Roger
> --
>
  

Patch

diff --git a/gcc/config/i386/i386-features.cc b/gcc/config/i386/i386-features.cc
index f1b03c3..813b203 100644
--- a/gcc/config/i386/i386-features.cc
+++ b/gcc/config/i386/i386-features.cc
@@ -1054,13 +1054,13 @@  general_scalar_chain::convert_insn (rtx_insn *insn)
   else if (REG_P (dst) && GET_MODE (dst) == smode)
     {
       /* Replace the definition with a SUBREG to the definition we
-         use inside the chain.  */
+	 use inside the chain.  */
       rtx *vdef = defs_map.get (dst);
       if (vdef)
 	dst = *vdef;
       dst = gen_rtx_SUBREG (vmode, dst, 0);
       /* IRA doesn't like to have REG_EQUAL/EQUIV notes when the SET_DEST
-         is a non-REG_P.  So kill those off.  */
+	 is a non-REG_P.  So kill those off.  */
       rtx note = find_reg_equal_equiv_note (insn);
       if (note)
 	remove_note (insn, note);
@@ -1246,7 +1246,7 @@  timode_scalar_chain::fix_debug_reg_uses (rtx reg)
     {
       rtx_insn *insn = DF_REF_INSN (ref);
       /* Make sure the next ref is for a different instruction,
-         so that we're not affected by the rescan.  */
+	 so that we're not affected by the rescan.  */
       next = DF_REF_NEXT_REG (ref);
       while (next && DF_REF_INSN (next) == insn)
 	next = DF_REF_NEXT_REG (next);
@@ -1336,21 +1336,19 @@  timode_scalar_chain::convert_insn (rtx_insn *insn)
   rtx dst = SET_DEST (def_set);
   rtx tmp;
 
-  if (MEM_P (dst) && !REG_P (src))
-    {
-      /* There are no scalar integer instructions and therefore
-	 temporary register usage is required.  */
-    }
   switch (GET_CODE (dst))
     {
     case REG:
       if (GET_MODE (dst) == TImode)
 	{
+	  PUT_MODE (dst, V1TImode);
+	  fix_debug_reg_uses (dst);
+	}
+      if (GET_MODE (dst) == V1TImode)
+	{
 	  tmp = find_reg_equal_equiv_note (insn);
 	  if (tmp && GET_MODE (XEXP (tmp, 0)) == TImode)
 	    PUT_MODE (XEXP (tmp, 0), V1TImode);
-	  PUT_MODE (dst, V1TImode);
-	  fix_debug_reg_uses (dst);
 	}
       break;
     case MEM:
@@ -1410,8 +1408,8 @@  timode_scalar_chain::convert_insn (rtx_insn *insn)
       if (MEM_P (dst))
 	{
 	  tmp = gen_reg_rtx (V1TImode);
-          emit_insn_before (gen_rtx_SET (tmp, src), insn);
-          src = tmp;
+	  emit_insn_before (gen_rtx_SET (tmp, src), insn);
+	  src = tmp;
 	}
       break;
 
@@ -1434,8 +1432,8 @@  timode_scalar_chain::convert_insn (rtx_insn *insn)
       if (MEM_P (dst))
 	{
 	  tmp = gen_reg_rtx (V1TImode);
-          emit_insn_before (gen_rtx_SET (tmp, src), insn);
-          src = tmp;
+	  emit_insn_before (gen_rtx_SET (tmp, src), insn);
+	  src = tmp;
 	}
       break;
 
@@ -1448,8 +1446,8 @@  timode_scalar_chain::convert_insn (rtx_insn *insn)
       if (MEM_P (dst))
 	{
 	  tmp = gen_reg_rtx (V1TImode);
-          emit_insn_before (gen_rtx_SET (tmp, src), insn);
-          src = tmp;
+	  emit_insn_before (gen_rtx_SET (tmp, src), insn);
+	  src = tmp;
 	}
       break;
 
@@ -1585,7 +1583,7 @@  convertible_comparison_p (rtx_insn *insn, enum machine_mode mode)
   /* *cmp<dwi>_doubleword.  */
   if ((CONST_INT_P (op1)
        || ((REG_P (op1) || MEM_P (op1))
-           && GET_MODE (op1) == mode))
+	   && GET_MODE (op1) == mode))
       && (CONST_INT_P (op2)
 	  || ((REG_P (op2) || MEM_P (op2))
 	      && GET_MODE (op2) == mode)))
@@ -1745,7 +1743,7 @@  timode_scalar_to_vector_candidate_p (rtx_insn *insn)
 
   if (GET_MODE (dst) != TImode
       || (GET_MODE (src) != TImode
-          && !CONST_SCALAR_INT_P (src)))
+	  && !CONST_SCALAR_INT_P (src)))
     return false;
 
   if (!REG_P (dst) && !MEM_P (dst))
diff --git a/gcc/testsuite/gcc.dg/pr106278.c b/gcc/testsuite/gcc.dg/pr106278.c
new file mode 100644
index 0000000..ab312b3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr106278.c
@@ -0,0 +1,22 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+void __assert_fail();
+struct a {
+  int b;
+  int c;
+  int d;
+  int : 2;
+};
+int e, f;
+struct a g, i;
+const struct a h;
+int main() {
+  struct a j;
+  g = h;
+  if (e)
+    __assert_fail();
+  if (f)
+    j = h;
+  i = j;
+  return 0;
+}