From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 26B903858CDA; Sun, 14 Aug 2022 15:48:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26B903858CDA From: "absoler at smail dot nju.edu.cn" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/106615] New: redundant load and store introduced in if-true-branch Date: Sun, 14 Aug 2022 15:48:42 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: absoler at smail dot nju.edu.cn X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 14 Aug 2022 15:48:43 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106615 Bug ID: 106615 Summary: redundant load and store introduced in if-true-branch Product: gcc Version: 12.1.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: --- Given the code: int g_36 =3D 0x0B137D37L; int *g_35 =3D &g_36; int g_44[2] =3D {0x964071C1L,0x964071C1L}; unsigned char func_1(void); int * func_16(int * p_17, unsigned long int p_18); int * func_19(int * p_20); unsigned char func_1() { func_16(func_19(g_35), g_44[1]); } int* func_16(int *a, unsigned long int b) { unsigned int c=3D1; *a =3D g_44; if ((g_44[0] =3D c) <=3D b) ; else *a =3D 0; } int* func_19(int32_t *d) { g_44[1] |=3D g_36 ; return d; } when it's compiled on gcc-12.1 with option -O1, the generated asm code of func_16 will be: 0000000000401186 : 401186: b8 60 40 40 00 mov $0x404060,%eax 40118b: 89 07 mov %eax,(%rdi) 40118d: c7 05 c9 2e 00 00 01 movl $0x1,0x2ec9(%rip) # 404060 401194: 00 00 00=20 401197: b8 00 00 00 00 mov $0x0,%eax 40119c: 48 85 f6 test %rsi,%rsi 40119f: 74 02 je 4011a3 4011a1: 8b 07 mov (%rdi),%eax=20=20=20=20 # rdi keep the address of g_36 4011a3: 89 07 mov %eax,(%rdi) 4011a5: c3 retq=20=20 We can see g_36 will be loaded to %eax and stored back as is when the if-condition is true. This operation should be redundant?=