public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/115086] New: bic is not used when the non-not part is a constant
@ 2024-05-14  9:45 pinskia at gcc dot gnu.org
  2024-05-14  9:49 ` [Bug target/115086] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-14  9:45 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115086
           Summary: bic is not used when the non-not part is a constant
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---
            Target: aarch64

Take:
```
int g2(int a,int c)
{
  int b = 4 & ~c;
  return b;
}
```

Currently GCC produces:
```
g2:
        mvn     w0, w1
        and     w0, w0, 4
        ret
```
But producing bic is better for most (if not all) modern cores due to the
instruction that generates the constant would be "free". That is GCC should
produce:
```
g2:
        mov     w8, 4
        bic     w0, w8, w1
        ret
```

Which is what clang/LLVM produces.

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

* [Bug target/115086] bic is not used when the non-not part is a constant
  2024-05-14  9:45 [Bug target/115086] New: bic is not used when the non-not part is a constant pinskia at gcc dot gnu.org
@ 2024-05-14  9:49 ` pinskia at gcc dot gnu.org
  2024-05-14  9:50 ` rearnsha at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-14  9:49 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-05-14
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=112304
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Trying 7 -> 13:
    7: r105:SI=~r106:SI
      REG_DEAD r106:SI
   13: x0:SI=r105:SI&0x4
      REG_DEAD r105:SI
Failed to match this instruction:
(set (reg/i:SI 0 x0)
    (and:SI (not:SI (reg:SI 106))
        (const_int 4 [0x4])))

So similar to what I did for csinc, PR 112304 so I will handle this.

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

* [Bug target/115086] bic is not used when the non-not part is a constant
  2024-05-14  9:45 [Bug target/115086] New: bic is not used when the non-not part is a constant pinskia at gcc dot gnu.org
  2024-05-14  9:49 ` [Bug target/115086] " pinskia at gcc dot gnu.org
@ 2024-05-14  9:50 ` rearnsha at gcc dot gnu.org
  2024-05-15  5:11 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rearnsha at gcc dot gnu.org @ 2024-05-14  9:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Richard Earnshaw <rearnsha at gcc dot gnu.org> ---
And perhaps more importantly the mov can even be hoisted outside of a loop.

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

* [Bug target/115086] bic is not used when the non-not part is a constant
  2024-05-14  9:45 [Bug target/115086] New: bic is not used when the non-not part is a constant pinskia at gcc dot gnu.org
  2024-05-14  9:49 ` [Bug target/115086] " pinskia at gcc dot gnu.org
  2024-05-14  9:50 ` rearnsha at gcc dot gnu.org
@ 2024-05-15  5:11 ` pinskia at gcc dot gnu.org
  2024-05-15  7:38 ` pinskia at gcc dot gnu.org
  2024-05-15 10:37 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-15  5:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Richard Earnshaw from comment #2)
> And perhaps more importantly the mov can even be hoisted outside of a loop.

That won't be happening right away, see
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112304#c4 where cinc has the same
issue. In this case it is very similar in that we don't pull the constant from
the and (rather than add) inside LIM. Basically we don't have an early
"combine" to even generate the and/not pattern, forwprop could but I Have not
looked into why it does not and then we could do a split afterwards and LIM
might be able to pull it out. I will definitely look into that but that will
step 2 of this and the other issue.

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

* [Bug target/115086] bic is not used when the non-not part is a constant
  2024-05-14  9:45 [Bug target/115086] New: bic is not used when the non-not part is a constant pinskia at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2024-05-15  5:11 ` pinskia at gcc dot gnu.org
@ 2024-05-15  7:38 ` pinskia at gcc dot gnu.org
  2024-05-15 10:37 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-15  7:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So looking into this a little bit. There are many different patterns which
might need to be fixed. Maybe there is a better way of implementing this into
forwprop. Let see if that is doable. But that won't be until next week.

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

* [Bug target/115086] bic is not used when the non-not part is a constant
  2024-05-14  9:45 [Bug target/115086] New: bic is not used when the non-not part is a constant pinskia at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2024-05-15  7:38 ` pinskia at gcc dot gnu.org
@ 2024-05-15 10:37 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-15 10:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #4)
> So looking into this a little bit. There are many different patterns which
> might need to be fixed. Maybe there is a better way of implementing this
> into forwprop. Let see if that is doable. But that won't be until next week.

I have a better idea than forwprop which I mentioned in a different bug report.
Basically add an andnot optab and expand using that if we can match it. the
open question is should we add an internal function and match it in
isel/math-opt pass and expand the internal function that way or add the code to
expand to match it. Either way the optab will be the same. 

Note that will fix even the pull the constant out of the loop issue too.

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

end of thread, other threads:[~2024-05-15 10:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-14  9:45 [Bug target/115086] New: bic is not used when the non-not part is a constant pinskia at gcc dot gnu.org
2024-05-14  9:49 ` [Bug target/115086] " pinskia at gcc dot gnu.org
2024-05-14  9:50 ` rearnsha at gcc dot gnu.org
2024-05-15  5:11 ` pinskia at gcc dot gnu.org
2024-05-15  7:38 ` pinskia at gcc dot gnu.org
2024-05-15 10:37 ` 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).