public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Uros Bizjak <uros@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-9847] combine: Fix ICE in try_combine on pr112494.c [PR112560]
Date: Mon,  8 Apr 2024 20:22:49 +0000 (GMT)	[thread overview]
Message-ID: <20240408202249.8DCB13858D28@sourceware.org> (raw)

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

commit r14-9847-geaccdba315b86d374a4e72b9dd8fefb0fc3cc5ee
Author: Uros Bizjak <ubizjak@gmail.com>
Date:   Mon Apr 8 20:54:30 2024 +0200

    combine: Fix ICE in try_combine on pr112494.c [PR112560]
    
    The compiler, configured with --enable-checking=yes,rtl,extra ICEs with:
    
    internal compiler error: RTL check: expected elt 0 type 'e' or 'u', have 'E' (rtx unspec) in try_combine, at combine.cc:3237
    
    This is
    
    3236                      /* Just replace the CC reg with a new mode.  */
    3237                      SUBST (XEXP (*cc_use_loc, 0), newpat_dest);
    3238                      undobuf.other_insn = cc_use_insn;
    
    in combine.cc, where *cc_use_loc is
    
    (unspec:DI [
            (reg:CC 17 flags)
        ] UNSPEC_PUSHFL)
    
    combine assumes CC must be used inside of a comparison and uses XEXP (..., 0)
    without checking on the RTX type of the argument.
    
    Replace cc_use_loc with the entire new RTX only in case cc_use_loc satisfies
    COMPARISON_P predicate.  Otherwise scan the entire cc_use_loc RTX for CC reg
    to be updated with a new mode.
    
            PR rtl-optimization/112560
    
    gcc/ChangeLog:
    
            * combine.cc (try_combine): Replace cc_use_loc with the entire
            new RTX only in case cc_use_loc satisfies COMPARISON_P predicate.
            Otherwise scan the entire cc_use_loc RTX for CC reg to be updated
            with a new mode.
            * config/i386/i386.md (@pushf<mode>2): Allow all CC modes for
            operand 1.

Diff:
---
 gcc/combine.cc          | 16 +++++++++++++---
 gcc/config/i386/i386.md |  4 ++--
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/gcc/combine.cc b/gcc/combine.cc
index 745391016d0..71c9abc145c 100644
--- a/gcc/combine.cc
+++ b/gcc/combine.cc
@@ -3222,8 +3222,7 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, rtx_insn *i0,
 #endif
 	      /* Cases for modifying the CC-using comparison.  */
 	      if (compare_code != orig_compare_code
-		  /* ??? Do we need to verify the zero rtx?  */
-		  && XEXP (*cc_use_loc, 1) == const0_rtx)
+		  && COMPARISON_P (*cc_use_loc))
 		{
 		  /* Replace cc_use_loc with entire new RTX.  */
 		  SUBST (*cc_use_loc,
@@ -3233,8 +3232,19 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, rtx_insn *i0,
 		}
 	      else if (compare_mode != orig_compare_mode)
 		{
+		  subrtx_ptr_iterator::array_type array;
+
 		  /* Just replace the CC reg with a new mode.  */
-		  SUBST (XEXP (*cc_use_loc, 0), newpat_dest);
+		  FOR_EACH_SUBRTX_PTR (iter, array, cc_use_loc, NONCONST)
+		    {
+		      rtx *loc = *iter;
+		      if (REG_P (*loc)
+			  && REGNO (*loc) == REGNO (newpat_dest))
+			{
+			  SUBST (*loc, newpat_dest);
+			  iter.skip_subrtxes ();
+			}
+		    }
 		  undobuf.other_insn = cc_use_insn;
 		}
 	    }
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index bb2c72f3473..10ae3113ae8 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -2219,9 +2219,9 @@
 
 (define_insn "@pushfl<mode>2"
   [(set (match_operand:W 0 "push_operand" "=<")
-	(unspec:W [(match_operand:CC 1 "flags_reg_operand")]
+	(unspec:W [(match_operand 1 "flags_reg_operand")]
 		  UNSPEC_PUSHFL))]
-  ""
+  "GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_CC"
   "pushf{<imodesuffix>}"
   [(set_attr "type" "push")
    (set_attr "mode" "<MODE>")])

                 reply	other threads:[~2024-04-08 20:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240408202249.8DCB13858D28@sourceware.org \
    --to=uros@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).