public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "absoler at smail dot nju.edu.cn" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/114173] New: miss optimization of redundant load operation, may confused by type conversion
Date: Thu, 29 Feb 2024 16:27:00 +0000	[thread overview]
Message-ID: <bug-114173-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 114173
           Summary: miss optimization of redundant load operation, may
                    confused by type conversion
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: absoler at smail dot nju.edu.cn
  Target Milestone: ---

Hi, here's the code:

```
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int int16_t;
typedef unsigned short int uint16_t;
typedef signed int int32_t;
typedef unsigned int uint32_t;
typedef signed long int int64_t;
typedef unsigned long int uint64_t;
/* --- Struct/Union Declarations --- */

struct S1 {
   uint32_t  f0;
   int32_t  f1;
   uint16_t  f2;
};


/* --- GLOBAL VARIABLES --- */
int32_t g_6 = 0xA0CEC519L;
int32_t g_63[10] =
{0x62155B98L,0xEEA2DBBAL,0xEEA2DBBAL,0x62155B98L,0xEEA2DBBAL,0xEEA2DBBAL,0x62155B98L,0xEEA2DBBAL,0xEEA2DBBAL,0x62155B98L};
struct S1 g_304 =
{0x917144CEL,-8L,0x6D84L,-2L,0xD005B892436443A6LL,0xF5L,0x7EDC5F4166794133LL};

/* --- FORWARD DECLARATIONS --- */
void func_1() {
  int32_t b = 1;
  int32_t c;
  int8_t d;
  if (d = c = (uint16_t)((uint8_t)g_63[4] + b) - b) {
    uint16_t *e = &g_304.f0;
    *e = c;
  }
}

```

compiled with gcc-13.2.0 -O3, generated binary is:
https://godbolt.org/z/P9scnWqsa
```
00000000004015f0 <func_1>:
func_1():
/root/loadtest3/test/output2.c:43
  4015f0:       cmpb   $0x0,0x2ab9(%rip)        # 4040b0 <g_63+0x10>
  4015f7:       movzbl 0x2ab2(%rip),%eax        # 4040b0 <g_63+0x10>
  4015fe:       je     401607 <func_1+0x17>
/root/loadtest3/test/output2.c:45
  401600:       mov    %ax,0x2a79(%rip)        # 404080 <g_304>
/root/loadtest3/test/output2.c:47
  401607:       retq   
  401608:       nopl   0x0(%rax,%rax,1)
```

the compare and load instructions can swap and $eax can be used in the compare,
instead of a memory access

             reply	other threads:[~2024-02-29 16:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-29 16:27 absoler at smail dot nju.edu.cn [this message]
2024-02-29 22:44 ` [Bug target/114173] " 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-114173-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).