From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3E4F33858D35; Fri, 8 Mar 2024 05:31:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3E4F33858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709875865; bh=Kp2KOnYybffgky0WP2kFt062rizwGQ3p84CFDQ6OLbk=; h=From:To:Subject:Date:From; b=FiZgQUUoUHQvraBs77g6yDGwdzfA2TEM/t1la4cxxhD2Uf8FMrz9gekpeK/l760Dg zxT64FWa0yPLX2fqjLhjyvMhVkT9OesjcpfvKLUHYiE11uQ5mj8NlEBgOanekSz6UO r3Kfzkgn1PKXxheYwjhf3slqPHA0DF17hQaIx2q8= From: "652023330028 at smail dot nju.edu.cn" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/114277] New: Missed optimization: x*(x||b) => x Date: Fri, 08 Mar 2024 05:31:04 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: 652023330028 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114277 Bug ID: 114277 Summary: Missed optimization: x*(x||b) =3D> x Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: 652023330028 at smail dot nju.edu.cn Target Milestone: --- Hello, we noticed that the code below can be optimized as stated in the tit= le (x*(x||b) =3D> x), but gcc -O3 missed it. https://godbolt.org/z/W8xYrGdej int a,b; void func(int x){ a=3Dx*(x||b); } GCC -O3: func(int): mov eax, edi or eax, DWORD PTR b[rip] mov eax, 0 cmove edi, eax mov DWORD PTR a[rip], edi ret Expected code: func(int): mov DWORD PTR a[rip], edi ret Surprisingly, GCC optimizes as expected for the following slightly more com= plex code: int c; void func2(int x){ a=3Dx*(x||(b&&c)); } func2(int): mov DWORD PTR a[rip], edi ret Thank you very much for your time and effort! We look forward to hearing fr= om you.=