public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111766] New: Missed optimization with __builtin_unreachable and ands
@ 2023-10-11  1:55 pinskia at gcc dot gnu.org
  2023-10-11 14:00 ` [Bug tree-optimization/111766] " amacleod at redhat dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-11  1:55 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111766
           Summary: Missed optimization with __builtin_unreachable and
                    ands
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
int
foo3n(int c, int bb)
{
  if ((bb & ~3)!=0) __builtin_unreachable(); // bb = [0,3]
  if ((bb & 1)==0) __builtin_unreachable(); // bb&1 == 0 // [0],[3]
  if(bb == 2) __builtin_trap();
  return bb;
}
```

The condition `bb == 2` is never true as (bb&1) has to be zero.

I Noticed this while looking into PR 111432.  Note clang/LLVM is able to
optimize this ...

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

* [Bug tree-optimization/111766] Missed optimization with __builtin_unreachable and ands
  2023-10-11  1:55 [Bug tree-optimization/111766] New: Missed optimization with __builtin_unreachable and ands pinskia at gcc dot gnu.org
@ 2023-10-11 14:00 ` amacleod at redhat dot com
  2023-11-03 17:14 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: amacleod at redhat dot com @ 2023-10-11 14:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Macleod <amacleod at redhat dot com> ---


Imports: bb_3(D)
Exports: _2  bb_3(D)
         _2 : bb_3(D)(I)
bb_3(D) [irange] int [0, 3] MASK 0x3 VALUE 0x0
    <bb 4> :
    _2 = bb_3(D) & 1;
    if (_2 == 0)
      goto <bb 5>; [INV]
    else
      goto <bb 6>; [INV]

_2 : [irange] int [0, 1] MASK 0x1 VALUE 0x0
4->5  (T) _2 :  [irange] int [0, 0] MASK 0x1 VALUE 0x0
4->5  (T) bb_3(D) :     [irange] int [0, 0][2, 2] MASK 0x2 VALUE 0x0
4->6  (F) _2 :  [irange] int [1, 1] MASK 0x1 VALUE 0x0
4->6  (F) bb_3(D) :     [irange] int [1, 3] MASK 0x2 VALUE 0x1

Looks like its just a lack of completeness in
operator_bitwise_and::op1_range().
on the edge from 4->6 ranger knows _2 is [1,1], but when op1_range solves for
  _2 = bb_3 & 1
we have  
  [1,1] =  int [0, 3] MASK 0x3 VALUE 0x0    &   1
and it produces int [1, 3] rather than [1,1][3,3]

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

* [Bug tree-optimization/111766] Missed optimization with __builtin_unreachable and ands
  2023-10-11  1:55 [Bug tree-optimization/111766] New: Missed optimization with __builtin_unreachable and ands pinskia at gcc dot gnu.org
  2023-10-11 14:00 ` [Bug tree-optimization/111766] " amacleod at redhat dot com
@ 2023-11-03 17:14 ` cvs-commit at gcc dot gnu.org
  2023-11-03 17:15 ` amacleod at redhat dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-03 17:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Andrew Macleod <amacleod@gcc.gnu.org>:

https://gcc.gnu.org/g:7ab79a40b546a1470abaf76bec74c63e9990fe47

commit r14-5110-g7ab79a40b546a1470abaf76bec74c63e9990fe47
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Wed Oct 25 09:46:50 2023 -0400

    Adjust operators equal and not_equal to check bitmasks against constants

    Check to see if a comparison to a constant can be determined to always
    be not-equal based on the bitmask.

            PR tree-optimization/111766
            gcc/
            * range-op.cc (operator_equal::fold_range): Check constants
            against the bitmask.
            (operator_not_equal::fold_range): Ditto.
            * value-range.h (irange_bitmask::member_p): New.

            gcc/testsuite/
            * gcc.dg/pr111766.c: New.

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

* [Bug tree-optimization/111766] Missed optimization with __builtin_unreachable and ands
  2023-10-11  1:55 [Bug tree-optimization/111766] New: Missed optimization with __builtin_unreachable and ands pinskia at gcc dot gnu.org
  2023-10-11 14:00 ` [Bug tree-optimization/111766] " amacleod at redhat dot com
  2023-11-03 17:14 ` cvs-commit at gcc dot gnu.org
@ 2023-11-03 17:15 ` amacleod at redhat dot com
  2023-11-03 17:15 ` amacleod at redhat dot com
  2023-11-03 17:29 ` sjames at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: amacleod at redhat dot com @ 2023-11-03 17:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Macleod <amacleod at redhat dot com> ---
fixed

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

* [Bug tree-optimization/111766] Missed optimization with __builtin_unreachable and ands
  2023-10-11  1:55 [Bug tree-optimization/111766] New: Missed optimization with __builtin_unreachable and ands pinskia at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-11-03 17:15 ` amacleod at redhat dot com
@ 2023-11-03 17:15 ` amacleod at redhat dot com
  2023-11-03 17:29 ` sjames at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: amacleod at redhat dot com @ 2023-11-03 17:15 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Macleod <amacleod at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #4 from Andrew Macleod <amacleod at redhat dot com> ---
oops. fixed

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

* [Bug tree-optimization/111766] Missed optimization with __builtin_unreachable and ands
  2023-10-11  1:55 [Bug tree-optimization/111766] New: Missed optimization with __builtin_unreachable and ands pinskia at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-11-03 17:15 ` amacleod at redhat dot com
@ 2023-11-03 17:29 ` sjames at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: sjames at gcc dot gnu.org @ 2023-11-03 17:29 UTC (permalink / raw)
  To: gcc-bugs

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

Sam James <sjames at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |14.0

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

end of thread, other threads:[~2023-11-03 17:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-11  1:55 [Bug tree-optimization/111766] New: Missed optimization with __builtin_unreachable and ands pinskia at gcc dot gnu.org
2023-10-11 14:00 ` [Bug tree-optimization/111766] " amacleod at redhat dot com
2023-11-03 17:14 ` cvs-commit at gcc dot gnu.org
2023-11-03 17:15 ` amacleod at redhat dot com
2023-11-03 17:15 ` amacleod at redhat dot com
2023-11-03 17:29 ` sjames 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).