public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "Explorer09 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/115674] New: "Checking if number is within interval" missed optimization when number is from a smaller int type
Date: Thu, 27 Jun 2024 04:58:48 +0000	[thread overview]
Message-ID: <bug-115674-4@http.gcc.gnu.org/bugzilla/> (raw)

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.

             reply	other threads:[~2024-06-27  4:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-27  4:58 Explorer09 at gmail dot com [this message]
2024-06-27  5:04 ` [Bug middle-end/115674] " pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-115674-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).