public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ubizjak at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/112560] [14 Regression] ICE in try_combine on pr112494.c
Date: Thu, 11 Apr 2024 06:33:16 +0000	[thread overview]
Message-ID: <bug-112560-4-BLxfJCt5h2@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-112560-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112560

--- Comment #13 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to Segher Boessenkool from comment #12)
> You cannot use a :CC value as argument of an unspec, as explained before.
> 
> The result of a comparison is expressed as a comparison, in RTL.  This patch
> allows malformed RTL in more places than before, not progress at all.

During our discussion we determined that this form with UNSPEC is actually a
copy operation, so it is not an use [1] of CC register, because "use" is in the
form of cc-compared-to-0.

[1] https://gcc.gnu.org/pipermail/gcc-patches/2024-March/647426.html

Now, let's see the part my patch fixes. The original change that introduced the
functionality (See Comment #1) updates the "use" of the CC register. It assumes
exclusively cc-compared-to-0 use, but there are several patterns in various
target .md files that use naked CC register. The "???" comment suggests that
the transformation tripped on this and thus the "verify the zero_rtx" was
bolted on. The zero_rtx is inherent part of the regular CC reg "use", so this
addition _mostly_ weeded out invalid access with naked CC reg.

If the CC reg is used as the source of copy operation ("move"), with or without
UNSPEC, then the unpatched compiler will blindly use:

SUBST (XEXP (*cc_use_loc, 0), newpat_dest);

which *assumes* the certain form of the changed expression. Failed assumption
will lead to memory corruption, and this is what my patch prevents.

Patched compiler will find the sole use of the naked CC reg (due to
find_single_use) in the RTX, and update its mode at the right place. If the new
mode is not recognized by the insn pattern, then the combination is rejected.

In any case, we are trading silent memory corruption with failed combine
attempt. In my rule book, this is "progress" with bold, capital letters.

      parent reply	other threads:[~2024-04-11  6:33 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-16  7:23 [Bug middle-end/112560] New: " jakub at gcc dot gnu.org
2023-11-16  7:24 ` [Bug middle-end/112560] [14 Regression] " jakub at gcc dot gnu.org
2023-11-18  6:17 ` pinskia at gcc dot gnu.org
2023-11-18  6:17 ` pinskia at gcc dot gnu.org
2023-11-28 16:00 ` ubizjak at gmail dot com
2023-11-28 17:33 ` ubizjak at gmail dot com
2023-11-29  9:37 ` ubizjak at gmail dot com
2024-03-11 11:54 ` [Bug rtl-optimization/112560] " ubizjak at gmail dot com
2024-03-12 17:54 ` ubizjak at gmail dot com
2024-04-08 20:22 ` cvs-commit at gcc dot gnu.org
2024-04-09  8:26 ` rguenth at gcc dot gnu.org
2024-04-09  8:28 ` ubizjak at gmail dot com
2024-04-10 17:55 ` segher at gcc dot gnu.org
2024-04-10 18:34 ` ubizjak at gmail dot com
2024-04-10 22:44 ` segher at gcc dot gnu.org
2024-04-11  6:33 ` ubizjak at gmail dot com [this message]

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=bug-112560-4-BLxfJCt5h2@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).