public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110009] New: Another missing ABS detection
@ 2023-05-28  0:18 pinskia at gcc dot gnu.org
  2023-05-28  9:36 ` [Bug tree-optimization/110009] " gjl at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-28  0:18 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110009
           Summary: Another missing ABS detection
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
            Blocks: 109907
  Target Milestone: ---

Take:
```
unsigned
f1 (int v)
{
  unsigned int d_6;
  int b_5;
  unsigned int v1_2;
  unsigned int _7;
  int _9;

  b_5 = v>>(sizeof(v)*8 - 1);
  _9 = b_5 | 1;
  d_6 = (unsigned int) _9;
  v1_2 = (unsigned int) v;
  _7 = v1_2 * d_6;
  return _7;
}
```
This currently does not get converted to `return ABSU<v>`.

I found this while implementing a different match pattern and found that the
testcase pr103245-1.c was failing.

This blocks PR 109907 because the patch which is to fix a regression from the
patch of bug 109907 comment #25 introduces this.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109907
[Bug 109907] Missed optimization for bit extraction (uses shift instead of
single bit-test)

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

* [Bug tree-optimization/110009] Another missing ABS detection
  2023-05-28  0:18 [Bug tree-optimization/110009] New: Another missing ABS detection pinskia at gcc dot gnu.org
@ 2023-05-28  9:36 ` gjl at gcc dot gnu.org
  2023-05-28 14:38 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: gjl at gcc dot gnu.org @ 2023-05-28  9:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #0)
> unsigned
> f1 (int v)
> {
>   [...]
>   int b_5;
> 
>   b_5 = v>>(sizeof(v)*8 - 1);

Does it depend on -fwrapv maybe.

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

* [Bug tree-optimization/110009] Another missing ABS detection
  2023-05-28  0:18 [Bug tree-optimization/110009] New: Another missing ABS detection pinskia at gcc dot gnu.org
  2023-05-28  9:36 ` [Bug tree-optimization/110009] " gjl at gcc dot gnu.org
@ 2023-05-28 14:38 ` pinskia at gcc dot gnu.org
  2023-07-12  6:26 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-28 14:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Georg-Johann Lay from comment #1)
> (In reply to Andrew Pinski from comment #0)
> > unsigned
> > f1 (int v)
> > {
> >   [...]
> >   int b_5;
> > 
> >   b_5 = v>>(sizeof(v)*8 - 1);
> 
> Does it depend on -fwrapv maybe.

No in this case there is a missing pattern to match against.

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

* [Bug tree-optimization/110009] Another missing ABS detection
  2023-05-28  0:18 [Bug tree-optimization/110009] New: Another missing ABS detection pinskia at gcc dot gnu.org
  2023-05-28  9:36 ` [Bug tree-optimization/110009] " gjl at gcc dot gnu.org
  2023-05-28 14:38 ` pinskia at gcc dot gnu.org
@ 2023-07-12  6:26 ` pinskia at gcc dot gnu.org
  2023-09-04  8:20 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-12  6:26 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-07-12
           Severity|normal                      |enhancement
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=98907

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is very close to a dup of bug 98907 except the multiply in this case has
an extra cast involved.

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

* [Bug tree-optimization/110009] Another missing ABS detection
  2023-05-28  0:18 [Bug tree-optimization/110009] New: Another missing ABS detection pinskia at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-07-12  6:26 ` pinskia at gcc dot gnu.org
@ 2023-09-04  8:20 ` pinskia at gcc dot gnu.org
  2023-09-04  8:39 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-04  8:20 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Mine.

Even the simple one:
```
int
signed_f1(int v)
{
  int b_5;
  int _7;
  int _9;

  b_5 = v>>(sizeof(v)*8 - 1);
  _9 = b_5 | 1;
  _7 = v * _9;
  return _7;
}
```

is not detected.

First version without any nop_converts added:

(simplify
 (mult:c @0 (bit_ior:c (rshift @0 INTEGER_CST@1) integer_onep))
 (if (!TYPE_UNSIGNED (TREE_TYPE (@0))
      && wi::to_wide (@1) == element_precision (type) - 1)
  (abs @0)))

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

* [Bug tree-optimization/110009] Another missing ABS detection
  2023-05-28  0:18 [Bug tree-optimization/110009] New: Another missing ABS detection pinskia at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-09-04  8:20 ` pinskia at gcc dot gnu.org
@ 2023-09-04  8:39 ` pinskia at gcc dot gnu.org
  2023-09-04  9:00 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-04  8:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
With the nop_convert added and using bitwise_equal_p :

(simplify
 (mult:c @0 (nop_convert? (bit_ior:c (rshift @1 INTEGER_CST@2) integer_onep)))
 (if (!TYPE_UNSIGNED (TREE_TYPE (@1))
      && wi::to_wide (@2) == element_precision (type) - 1
      && bitwise_equal_p (@0, @1))
  (if (TYPE_UNSIGNED (type))
   (absu @1)
   (abs @1))))

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

* [Bug tree-optimization/110009] Another missing ABS detection
  2023-05-28  0:18 [Bug tree-optimization/110009] New: Another missing ABS detection pinskia at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-09-04  8:39 ` pinskia at gcc dot gnu.org
@ 2023-09-04  9:00 ` pinskia at gcc dot gnu.org
  2023-09-04 18:09 ` pinskia at gcc dot gnu.org
  2023-09-04 18:10 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-04  9:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Vector testcases too:
```
#define vector __attribute__((vector_size(4*sizeof(int))))

vector int
signed_f1(vector int v)
{
  vector int b_5;
  vector int _7;
  vector int _9;

  b_5 = v>>(sizeof(int)*8 - 1);
  _9 = b_5 | 1;
  _7 = v * _9;
  return _7;
}

vector unsigned
unsigned_f1 (vector int v)
{
  vector unsigned int d_6;
  vector int b_5;
  vector unsigned int v1_2;
  vector unsigned int _7;
  vector int _9;

  b_5 = v>>(sizeof(int)*8 - 1);
  _9 = b_5 | 1;
  d_6 = (vector unsigned int) _9;
  v1_2 = (vector unsigned int) v;
  _7 = v1_2 * d_6;
  return _7;
}

```

Which does work with the match pattern in comment #5.

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

* [Bug tree-optimization/110009] Another missing ABS detection
  2023-05-28  0:18 [Bug tree-optimization/110009] New: Another missing ABS detection pinskia at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-09-04  9:00 ` pinskia at gcc dot gnu.org
@ 2023-09-04 18:09 ` pinskia at gcc dot gnu.org
  2023-09-04 18:10 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-04 18:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 55838
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55838&action=edit
dg-testcase

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

* [Bug tree-optimization/110009] Another missing ABS detection
  2023-05-28  0:18 [Bug tree-optimization/110009] New: Another missing ABS detection pinskia at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2023-09-04 18:09 ` pinskia at gcc dot gnu.org
@ 2023-09-04 18:10 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-04 18:10 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |98907

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #6)
> Vector testcases too:
> 
> Which does work with the match pattern in comment #5.


Except veclowering messes up ABSU, see PR 111285 for that.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98907
[Bug 98907] Failure to optimize abs pattern

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

end of thread, other threads:[~2023-09-04 18:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-28  0:18 [Bug tree-optimization/110009] New: Another missing ABS detection pinskia at gcc dot gnu.org
2023-05-28  9:36 ` [Bug tree-optimization/110009] " gjl at gcc dot gnu.org
2023-05-28 14:38 ` pinskia at gcc dot gnu.org
2023-07-12  6:26 ` pinskia at gcc dot gnu.org
2023-09-04  8:20 ` pinskia at gcc dot gnu.org
2023-09-04  8:39 ` pinskia at gcc dot gnu.org
2023-09-04  9:00 ` pinskia at gcc dot gnu.org
2023-09-04 18:09 ` pinskia at gcc dot gnu.org
2023-09-04 18:10 ` 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).