public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/101806] New: Extra zero extends for some arguments in some cases
@ 2021-08-06 21:10 pinskia at gcc dot gnu.org
  2021-08-06 21:13 ` [Bug rtl-optimization/101806] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-06 21:10 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101806
           Summary: Extra zero extends for some arguments in some cases
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---
            Target: aarch64-*-*

Take:
bool g(bool a, bool b)
{
  return ~a & b;
}
---- CUT ---
Currently we produce:
        and     w1, w1, 255
        and     w0, w0, 255
        bic     w0, w1, w0
        and     w0, w0, 1

---- CUT ---
But we should produce:
        bic     w0, w1, w0
        and     w0, w0, 1

The zero extends are not needed.
This happens because combine does the correct thing until it tries to figure
out the cutting point:Trying 2, 8 -> 16:
    2: r98:SI=zero_extend(x0:QI)
      REG_DEAD x0:QI
    8: r102:SI=~r98:SI&r99:SI
      REG_DEAD r98:SI
      REG_DEAD r99:SI
   16: x0:SI=r102:SI&0x1
      REG_DEAD r102:SI
Failed to match this instruction:
(set (reg:SI 0 x0)
    (and:SI (and:SI (not:SI (reg:SI 0 x0 [ a ]))
            (reg/v:SI 99 [ b ]))
        (const_int 1 [0x1])))
Successfully matched this instruction:
(set (reg:SI 102)
    (not:SI (reg:SI 0 x0 [ a ])))
Failed to match this instruction:
(set (reg:SI 0 x0)
    (and:SI (and:SI (reg:SI 102)
            (reg/v:SI 99 [ b ]))
        (const_int 1 [0x1])))

If we had chose (and:SI (not:SI (reg:SI 0 x0 [ a ])) (reg/v:SI 99 [ b ]))
instead, we would have gotten the correct thing.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug rtl-optimization/101806] Extra zero extends for some arguments in some cases
  2021-08-06 21:10 [Bug rtl-optimization/101806] New: Extra zero extends for some arguments in some cases pinskia at gcc dot gnu.org
@ 2021-08-06 21:13 ` pinskia at gcc dot gnu.org
  2022-10-27  3:21 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-06 21:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
It happens to work on x86-64(with -march=skylake-avx512) becausewe get a
zero_extend instead of an and there. I still don't understand how x86 is able
to figure out the &1 part.

Trying 11, 9 -> 12:
   11: r94:SI=zero_extend(r97:SI#0)
      REG_DEAD r97:SI
    9: r92:SI=zero_extend(r96:SI#0)
      REG_DEAD r96:SI
   12: {r95:SI=~r92:SI&r94:SI;clobber flags:CC;}
      REG_DEAD r92:SI
      REG_UNUSED flags:CC
      REG_DEAD r94:SI
Failed to match this instruction:
(parallel [
        (set (reg:SI 95)
            (zero_extend:SI (and:QI (not:QI (subreg:QI (reg:SI 96) 0))
                    (subreg:QI (reg:SI 97) 0))))
        (clobber (reg:CC 17 flags))
    ])
Failed to match this instruction:
(set (reg:SI 95)
    (zero_extend:SI (and:QI (not:QI (subreg:QI (reg:SI 96) 0))
            (subreg:QI (reg:SI 97) 0))))
Successfully matched this instruction:
(set (reg:QI 94 [ b ])
    (and:QI (not:QI (subreg:QI (reg:SI 96) 0))
        (subreg:QI (reg:SI 97) 0)))
Successfully matched this instruction:
(set (reg:SI 95)
    (zero_extend:SI (reg:QI 94 [ b ])))

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug rtl-optimization/101806] Extra zero extends for some arguments in some cases
  2021-08-06 21:10 [Bug rtl-optimization/101806] New: Extra zero extends for some arguments in some cases pinskia at gcc dot gnu.org
  2021-08-06 21:13 ` [Bug rtl-optimization/101806] " pinskia at gcc dot gnu.org
@ 2022-10-27  3:21 ` pinskia at gcc dot gnu.org
  2022-12-25  5:30 ` pinskia at gcc dot gnu.org
  2023-05-12 17:48 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-27  3:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think this will be fixed/improved by
https://gcc.gnu.org/pipermail/gcc-patches/2022-September/602089.html .

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug rtl-optimization/101806] Extra zero extends for some arguments in some cases
  2021-08-06 21:10 [Bug rtl-optimization/101806] New: Extra zero extends for some arguments in some cases pinskia at gcc dot gnu.org
  2021-08-06 21:13 ` [Bug rtl-optimization/101806] " pinskia at gcc dot gnu.org
  2022-10-27  3:21 ` pinskia at gcc dot gnu.org
@ 2022-12-25  5:30 ` pinskia at gcc dot gnu.org
  2023-05-12 17:48 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-25  5:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Even a simple:
unsigned char g(unsigned char a, unsigned char b)
{
  return ((~a) & b)&1;
}

Produces the extra zero extend.

But it is ok with:
unsigned char g(unsigned char *a, unsigned char *b)
{
  return ((~*a) & *b)&1;
}

It looks like it is hard register related too ...

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug rtl-optimization/101806] Extra zero extends for some arguments in some cases
  2021-08-06 21:10 [Bug rtl-optimization/101806] New: Extra zero extends for some arguments in some cases pinskia at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2022-12-25  5:30 ` pinskia at gcc dot gnu.org
@ 2023-05-12 17:48 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-12 17:48 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 109832 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-05-12 17:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-06 21:10 [Bug rtl-optimization/101806] New: Extra zero extends for some arguments in some cases pinskia at gcc dot gnu.org
2021-08-06 21:13 ` [Bug rtl-optimization/101806] " pinskia at gcc dot gnu.org
2022-10-27  3:21 ` pinskia at gcc dot gnu.org
2022-12-25  5:30 ` pinskia at gcc dot gnu.org
2023-05-12 17:48 ` pinskia at gcc dot gnu.org

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).