public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/106594] [13 Regression] sign-extensions no longer merged into addressing mode
Date: Mon, 06 Mar 2023 07:51:05 +0000	[thread overview]
Message-ID: <bug-106594-4-rgkrfoiai0@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-106594-4@http.gcc.gnu.org/bugzilla/>

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu.org

--- Comment #18 from Richard Biener <rguenth at gcc dot gnu.org> ---
OK, sorry for chiming in here ;)  I see that expand_compound_operation handles
sign_extends that can be expressed as zero_extends as the cheaper variant of

 a) the zero_extend
 b) the original sign_extend
 c) what expand_compound_operation recursively makes out of the zero_extend

while zero_extend seems to be always expanded to shifts (if possible)
as canonicalization(?) without considering costs.

So either that canonicalization isn't a canonicalization and thus at the
end of expand_compound_operation we should cost the shift sequence against
x and return x if that was cheaper _or_ the sign_extend case should not
leak non-canonical zero_extend and thus should not consider the bare
zero_extend but only the recursively treated one (supposed the sign_extend
is fine to be kept and not canonicalized to zero_extend).

Thus the problem in combines expand_compound_operation is confusion about
canonicalization vs. transform to a cheaper variant?  The comment of
the function suggests it should do canonicalization and instead
make_compound_operation would be the more appropriate place to do
costing?  (but I see none in the latter ...)

That said, the regression is caused by alternate input to the combine pass,
not by combine itself and from the looks at the IL snippets in comment#2
it might be just nonzero-bits knowledge that differs?

So for expand_compound_operation either

diff --git a/gcc/combine.cc b/gcc/combine.cc
index 053879500b7..bb151446ef3 100644
--- a/gcc/combine.cc
+++ b/gcc/combine.cc
@@ -7335,6 +7335,10 @@ expand_compound_operation (rtx x)
   if (GET_CODE (tem) == CLOBBER)
     return x;

+  if (set_src_cost (tem, mode, optimize_this_for_speed_p)
+      > set_src_cost (x, mode, optimize_this_for_speed_p))
+    return x;
+
   return tem;
 }

(which should enable simplification of the sign_extend checking)

or (more radical than suggested above) pruning all costing in this
function (maybe digging in history shows that's what it was before?):

diff --git a/gcc/combine.cc b/gcc/combine.cc
index 053879500b7..5966da55412 100644
--- a/gcc/combine.cc
+++ b/gcc/combine.cc
@@ -7231,20 +7231,7 @@ expand_compound_operation (rtx x)
       && ((nonzero_bits (XEXP (x, 0), inner_mode)
           & ~(((unsigned HOST_WIDE_INT) GET_MODE_MASK (inner_mode)) >> 1))
          == 0))
-    {
-      rtx temp = gen_rtx_ZERO_EXTEND (mode, XEXP (x, 0));
-      rtx temp2 = expand_compound_operation (temp);
-
-      /* Make sure this is a profitable operation.  */
-      if (set_src_cost (x, mode, optimize_this_for_speed_p)
-          > set_src_cost (temp2, mode, optimize_this_for_speed_p))
-       return temp2;
-      else if (set_src_cost (x, mode, optimize_this_for_speed_p)
-               > set_src_cost (temp, mode, optimize_this_for_speed_p))
-       return temp;
-      else
-       return x;
-    }
+    x = gen_rtx_ZERO_EXTEND (mode, XEXP (x, 0));

   /* We can optimize some special cases of ZERO_EXTEND.  */
   if (GET_CODE (x) == ZERO_EXTEND)

  parent reply	other threads:[~2023-03-06  7:51 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-12 11:23 [Bug tree-optimization/106594] New: " tnfchris at gcc dot gnu.org
2022-08-12 12:04 ` [Bug tree-optimization/106594] " rguenth at gcc dot gnu.org
2022-08-12 12:44 ` tnfchris at gcc dot gnu.org
2022-08-12 14:01 ` roger at nextmovesoftware dot com
2022-08-12 14:48 ` tnfchris at gcc dot gnu.org
2022-08-12 17:01 ` roger at nextmovesoftware dot com
2022-08-13 11:34 ` [Bug rtl-optimization/106594] " roger at nextmovesoftware dot com
2022-08-14 12:07 ` tnfchris at gcc dot gnu.org
2022-08-17  1:05 ` hp at gcc dot gnu.org
2022-10-19  7:11 ` rguenth at gcc dot gnu.org
2022-10-19  7:52 ` roger at nextmovesoftware dot com
2023-01-17  4:06 ` roger at nextmovesoftware dot com
2023-02-27 10:00 ` tnfchris at gcc dot gnu.org
2023-02-27 10:03 ` ktkachov at gcc dot gnu.org
2023-03-04 22:26 ` segher at gcc dot gnu.org
2023-03-05  8:06 ` roger at nextmovesoftware dot com
2023-03-05 12:00 ` roger at nextmovesoftware dot com
2023-03-05 15:23 ` segher at gcc dot gnu.org
2023-03-05 19:23 ` tnfchris at gcc dot gnu.org
2023-03-06  7:51 ` rguenth at gcc dot gnu.org [this message]
2023-03-06 10:38 ` rsandifo at gcc dot gnu.org
2023-03-06 11:07 ` jakub at gcc dot gnu.org
2023-03-07 11:32 ` roger at nextmovesoftware dot com
2023-03-13  9:30 ` roger at nextmovesoftware dot com
2023-04-17 11:41 ` jakub at gcc dot gnu.org
2023-04-17 12:58 ` jakub at gcc dot gnu.org
2023-04-26  6:56 ` [Bug rtl-optimization/106594] [13/14 " rguenth at gcc dot gnu.org
2023-07-27  9:23 ` rguenth at gcc dot gnu.org
2023-10-30 16:19 ` segher at gcc dot gnu.org
2024-05-21  9:12 ` [Bug rtl-optimization/106594] [13/14/15 " 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-106594-4-rgkrfoiai0@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).