public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/95097] New: Missed optimization with bitfield value ranges
@ 2020-05-13  3:00 bugdal at aerifal dot cx
  2020-05-13  4:05 ` [Bug tree-optimization/95097] " egallager at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: bugdal at aerifal dot cx @ 2020-05-13  3:00 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95097
           Summary: Missed optimization with bitfield value ranges
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bugdal at aerifal dot cx
  Target Milestone: ---

#include <stdint.h>
struct foo {
        uint32_t x:20;
};
int bar(struct foo f)
{
        if (f.x) {
                uint32_t y = (uint32_t)f.x*4096;
                if (y<200) return 1;
                else return 2;
        }
        return 3;
}

Here, truth of the condition f.x implies y>=4096, but GCC does not DCE the
y<200 test and return 1 codepath.

I actually had this come up in real world code, where I was considering use of
an inline function with nontrivial low size cases when a "page count" bitfield
is zero, where I expected these nontrivial cases to be optimized out based on
already having tested that the page count being nonzero, but GCC was unable to
do it. LLVM/clang does it.

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

* [Bug tree-optimization/95097] Missed optimization with bitfield value ranges
  2020-05-13  3:00 [Bug tree-optimization/95097] New: Missed optimization with bitfield value ranges bugdal at aerifal dot cx
@ 2020-05-13  4:05 ` egallager at gcc dot gnu.org
  2020-05-13  6:08 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: egallager at gcc dot gnu.org @ 2020-05-13  4:05 UTC (permalink / raw)
  To: gcc-bugs

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

Eric Gallager <egallager at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2020-05-13
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
             Blocks|                            |85316
           Keywords|                            |missed-optimization
                 CC|                            |egallager at gcc dot gnu.org

--- Comment #1 from Eric Gallager <egallager at gcc dot gnu.org> ---
Confirmed via godbolt: https://godbolt.org/z/FexRgJ


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85316
[Bug 85316] [meta-bug] VRP range propagation missed cases

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

* [Bug tree-optimization/95097] Missed optimization with bitfield value ranges
  2020-05-13  3:00 [Bug tree-optimization/95097] New: Missed optimization with bitfield value ranges bugdal at aerifal dot cx
  2020-05-13  4:05 ` [Bug tree-optimization/95097] " egallager at gcc dot gnu.org
@ 2020-05-13  6:08 ` pinskia at gcc dot gnu.org
  2020-05-13  6:31 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-05-13  6:08 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|85316                       |
           Severity|normal                      |enhancement

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The problem is if (f.x) gets lowered too early.
This is not directly a VPR issue either.
Changing the code slightly:
#include <stdint.h>
struct foo {
        uint32_t x:20;
};
int bar(struct foo f)
{

       uint32_t y = (uint32_t)f.x;
        if (y) {
                y *= 4096;
                if (y<200) return 1;
                else return 2;
        }
        return 3;
}

GCC is able to optimize it.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85316
[Bug 85316] [meta-bug] VRP range propagation missed cases

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

* [Bug tree-optimization/95097] Missed optimization with bitfield value ranges
  2020-05-13  3:00 [Bug tree-optimization/95097] New: Missed optimization with bitfield value ranges bugdal at aerifal dot cx
  2020-05-13  4:05 ` [Bug tree-optimization/95097] " egallager at gcc dot gnu.org
  2020-05-13  6:08 ` pinskia at gcc dot gnu.org
@ 2020-05-13  6:31 ` rguenth at gcc dot gnu.org
  2021-08-22  0:32 ` pinskia at gcc dot gnu.org
  2021-08-22  0:39 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-05-13  6:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Just to quote EVRP sees

  <bb 2> :
  _1 = VIEW_CONVERT_EXPR<unsigned int>(f);
  _2 = _1 & 1048575;
  if (_2 != 0)
    goto <bb 3>; [INV]
  else
    goto <bb 6>; [INV]

  <bb 3> :
  _3 = f.x;
  _4 = (unsigned int) _3;
  y_8 = _4 * 4096;
  if (y_8 <= 199)

thus the f.x != 0 test has been folded by one of those $?%&! permature
fold-const transforms to

  if ((BIT_FIELD_REF <f, 32, 0> & 1048575) != 0)

the fix is to get rid of those (and fix the "fallout").

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

* [Bug tree-optimization/95097] Missed optimization with bitfield value ranges
  2020-05-13  3:00 [Bug tree-optimization/95097] New: Missed optimization with bitfield value ranges bugdal at aerifal dot cx
                   ` (2 preceding siblings ...)
  2020-05-13  6:31 ` rguenth at gcc dot gnu.org
@ 2021-08-22  0:32 ` pinskia at gcc dot gnu.org
  2021-08-22  0:39 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-22  0:32 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

* [Bug tree-optimization/95097] Missed optimization with bitfield value ranges
  2020-05-13  3:00 [Bug tree-optimization/95097] New: Missed optimization with bitfield value ranges bugdal at aerifal dot cx
                   ` (3 preceding siblings ...)
  2021-08-22  0:32 ` pinskia at gcc dot gnu.org
@ 2021-08-22  0:39 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-22  0:39 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED

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

end of thread, other threads:[~2021-08-22  0:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-13  3:00 [Bug tree-optimization/95097] New: Missed optimization with bitfield value ranges bugdal at aerifal dot cx
2020-05-13  4:05 ` [Bug tree-optimization/95097] " egallager at gcc dot gnu.org
2020-05-13  6:08 ` pinskia at gcc dot gnu.org
2020-05-13  6:31 ` rguenth at gcc dot gnu.org
2021-08-22  0:32 ` pinskia at gcc dot gnu.org
2021-08-22  0:39 ` 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).