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.

Reply via email to