public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/98190] [11 Regression] GCC11 miscompiles code using _Bool when inlining: bfxil instruction misused since r11-165
Date: Wed, 09 Dec 2020 09:41:18 +0000	[thread overview]
Message-ID: <bug-98190-4-mPj5DZ1q8i@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-98190-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #12 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to rsandifo@gcc.gnu.org from comment #10)
> If we can't assert, I guess the rule is that we need to extend
> whenever we're storing to the MSB of the inner register.  We can
> do that either by extending the source value and the range to
> the outer register, or by assigning to the inner register and
> then extending it separately.

So perhaps:
--- gcc/expr.c.jj       2020-12-09 00:00:08.622548080 +0100
+++ gcc/expr.c  2020-12-09 10:36:12.198801940 +0100
@@ -5451,6 +5451,33 @@ expand_assignment (tree to, tree from, b
                                               mode1, to_rtx, to, from,
                                               reversep))
            result = NULL;
+          else if (SUBREG_P (to_rtx)
+                  && SUBREG_PROMOTED_VAR_P (to_rtx))
+           {
+             /* If to_rtx is a promoted subreg, this must be a store to the
+                whole variable, otherwise to_rtx would need to be MEM.
+                We need to zero or sign extend the value afterwards.  */
+             gcc_assert (known_eq (bitpos, 0)
+                         && known_eq (bitsize,
+                                      GET_MODE_BITSIZE (GET_MODE (to_rtx))));
+             if (TREE_CODE (to) == MEM_REF && !REF_REVERSE_STORAGE_ORDER (to))
+               result = store_expr (from, to_rtx, 0, nontemporal, false);
+             else
+               {
+                 result = store_field (to_rtx, bitsize, bitpos,
+                                       bitregion_start, bitregion_end,
+                                       mode1, from, get_alias_set (to),
+                                       nontemporal, reversep);
+                 rtx to_rtx1
+                   = lowpart_subreg (subreg_unpromoted_mode (to_rtx),
+                                     SUBREG_REG (to_rtx),
+                                     subreg_promoted_mode (to_rtx));
+                 to_rtx1 = convert_to_mode (subreg_promoted_mode (to_rtx),
+                                            to_rtx1,
+                                            SUBREG_PROMOTED_SIGN (to_rtx));
+                 emit_move_insn (SUBREG_REG (to_rtx), to_rtx1);
+               }
+           }
          else
            result = store_field (to_rtx, bitsize, bitpos,
                                  bitregion_start, bitregion_end,

then?  As in, if store_expr can handle it, use that, otherwise perform the
extension at the end.

As for BIT_INSERT_EXPR, I'm not sure if SSA_NAMEs can get promoted SUBREGs or
not, but in any case it wouldn't be this code path, it would be store_expr
which handles the promoted SUBREGs already, because destination would not be a
MEM_REF with non-mem decl or reversed order, nor handled_component_p, nor
ARRAY_TYPE destination.

  parent reply	other threads:[~2020-12-09  9:41 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-08  0:22 [Bug c/98190] New: GCC 11.0 miscompiles code using _Bool when inlining: bfxil instruction misused? vstinner at redhat dot com
2020-12-08  0:29 ` [Bug middle-end/98190] " pinskia at gcc dot gnu.org
2020-12-08  0:31 ` pinskia at gcc dot gnu.org
2020-12-08  0:33 ` vstinner at redhat dot com
2020-12-08  0:37 ` pinskia at gcc dot gnu.org
2020-12-08 13:08 ` jakub at gcc dot gnu.org
2020-12-08 13:55 ` [Bug middle-end/98190] [11 Regression] GCC11 miscompiles code using _Bool when inlining: bfxil instruction misused since r11-165 jakub at gcc dot gnu.org
2020-12-08 14:52 ` rguenth at gcc dot gnu.org
2020-12-08 19:07 ` jakub at gcc dot gnu.org
2020-12-08 19:16 ` jakub at gcc dot gnu.org
2020-12-09  9:04 ` rsandifo at gcc dot gnu.org
2020-12-09  9:16 ` rguenther at suse dot de
2020-12-09  9:41 ` jakub at gcc dot gnu.org [this message]
2020-12-09 15:03 ` rguenther at suse dot de
2020-12-09 16:30 ` rsandifo at gcc dot gnu.org
2020-12-10  8:22 ` jakub at gcc dot gnu.org
2020-12-10 11:39 ` rguenther at suse dot de
2020-12-11 10:12 ` cvs-commit at gcc dot gnu.org
2020-12-11 11:50 ` jakub at gcc dot gnu.org

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-98190-4-mPj5DZ1q8i@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).