public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/115674] New: "Checking if number is within interval" missed optimization when number is from a smaller int type
@ 2024-06-27  4:58 Explorer09 at gmail dot com
  2024-06-27  5:04 ` [Bug middle-end/115674] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: Explorer09 at gmail dot com @ 2024-06-27  4:58 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115674
           Summary: "Checking if number is within interval" missed
                    optimization when number is from a smaller int type
           Product: gcc
           Version: 14.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Explorer09 at gmail dot com
  Target Milestone: ---

```c
#include <stdbool.h>
#include <stdint.h>
bool func1(uint8_t x) {
    uint32_t value;
    value = x;
    if (value < 0xC2 || value > 0xF4) {
        return false;
    }
    return true;
}

bool func2(uint8_t x) {
    uint32_t value;
    value = x;
    if ((uint8_t)value < 0xC2 || (uint8_t)value > 0xF4) {
        return false;
    }
    return true;
}
```

x86_64 gcc with -Os option produces:

```x86asm
func1:
    movzx   edi, dil
    sub     edi, 194
    cmp     edi, 50
    setbe   al
    ret
func2:
    add     edi, 62
    cmp     dil, 50
    setbe   al
    ret
```

For x86-64, the expected result is func1 transformed to func2.

For ARM and RISC-V targets, I expect the other way around, that is, transform
func2 to func1, so that it saves a "bitwise AND 0xFF" operation.

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

* [Bug middle-end/115674] "Checking if number is within interval" missed optimization when number is from a smaller int type
  2024-06-27  4:58 [Bug rtl-optimization/115674] New: "Checking if number is within interval" missed optimization when number is from a smaller int type Explorer09 at gmail dot com
@ 2024-06-27  5:04 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-27  5:04 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|tree-optimization           |middle-end

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Worse:
  _1 = x_3(D) + 62;
  _6 = _1 <= 50;

Decent code:
  value_4 = (uint32_t) x_3(D);
  _1 = value_4 + 4294967102;
  _7 = _1 <= 50;

I think there is a dup somewhere ...

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

end of thread, other threads:[~2024-06-27  5:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-27  4:58 [Bug rtl-optimization/115674] New: "Checking if number is within interval" missed optimization when number is from a smaller int type Explorer09 at gmail dot com
2024-06-27  5:04 ` [Bug middle-end/115674] " 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).