public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/112395] New: `CST1| (x & CST0)` -> `0x1e | x` iff `x&CST0` known zero bits outside of CST1 is known to be 0
@ 2023-11-05 19:53 pinskia at gcc dot gnu.org
  2023-11-05 19:54 ` [Bug tree-optimization/112395] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-05 19:53 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112395
           Summary: `CST1| (x & CST0)` -> `0x1e | x` iff `x&CST0` known
                    zero bits outside of CST1 is known to be 0
           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
  Target Milestone: ---

As reported at :
https://gcc.gnu.org/pipermail/gcc-patches/2023-November/635206.html

An exmaple is:
```

unsigned f(unsigned x){
   if(x>=32)__builtin_unreachable();
   return 30|(x&1); // --> 30|x
}
```

30 is 0x1e and x has a range of [0, 31] (which has a nonzero bits of 0x1f).
The &1 part can be removed from 30|(x&1) as 30 will set every bit except for
the first bit.


I think the following will work.
```
(simplify
 (bit_ior (bit_and:s @0 INTEGER_CST@1) INTEGER_CST@2)
 (if (wi::bit_and_not (wi::bit_and_not (tree_nonzero_bits (@0), wi::to_wide
(@1)), wi::to_wide (@0)) == 0)
 (bit_ior @0 @2))
```

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

* [Bug tree-optimization/112395] `CST1| (x & CST0)` -> `0x1e | x` iff `x&CST0` known zero bits outside of CST1 is known to be 0
  2023-11-05 19:53 [Bug tree-optimization/112395] New: `CST1| (x & CST0)` -> `0x1e | x` iff `x&CST0` known zero bits outside of CST1 is known to be 0 pinskia at gcc dot gnu.org
@ 2023-11-05 19:54 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-05 19:54 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-11-05
             Status|UNCONFIRMED                 |ASSIGNED

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

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

end of thread, other threads:[~2023-11-05 19:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-05 19:53 [Bug tree-optimization/112395] New: `CST1| (x & CST0)` -> `0x1e | x` iff `x&CST0` known zero bits outside of CST1 is known to be 0 pinskia at gcc dot gnu.org
2023-11-05 19:54 ` [Bug tree-optimization/112395] " 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).