From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E9C3838930C3; Wed, 29 Apr 2020 09:00:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E9C3838930C3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1588150822; bh=9laCImhsd7QwH2tM1Qv8d8s/l5q5Pa7l2RnUW99B2zs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=oEuZXVTkHb/UnXB2SQ2JAjz9WalH+03uVBhmKt0vnxLb4o6cKSdHQjhk3HCJAbwKC 0z7kO1v6Jd3Pg0t0CXrrzAmbsvfBObRxZNMWOtM5bVF18+eSBOfMGQf3AZUjkWOxDv dExmNTRNudYegti+Sxw8fSVvEgMw9YVKyAjxLVhc= From: "ubizjak at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/94838] Failure to optimize out useless zero-ing after register was already zero-ed Date: Wed, 29 Apr 2020 09:00:22 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 10.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: ubizjak at gmail dot com X-Bugzilla-Status: NEW 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: component Message-ID: In-Reply-To: References: 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: Wed, 29 Apr 2020 09:00:23 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94838 Uro=C5=A1 Bizjak changed: What |Removed |Added ---------------------------------------------------------------------------- Component|target |rtl-optimization --- Comment #5 from Uro=C5=A1 Bizjak --- (In reply to Gabriel Ravier from comment #0) > int f(bool b, int *p) > { > return b && *p; > } >=20 > GCC generates this with -O3: >=20 > f(bool, int*): > xor eax, eax > test dil, dil > je .L1 > mov edx, DWORD PTR [rsi] > xor eax, eax ; This can be removed, since eax is already 0 here > test edx, edx > setne al > .L1: > ret The first xor is return value load and the second is from peephole2 pass th= at converts: 11: NOTE_INSN_BASIC_BLOCK 3 12: flags:CCZ=3Dcmp([si:DI],0) REG_DEAD si:DI 13: NOTE_INSN_DELETED 32: ax:QI=3Dflags:CCZ!=3D0 REG_DEAD flags:CCZ 33: ax:SI=3Dzero_extend(ax:QI) to: 11: NOTE_INSN_BASIC_BLOCK 3 40: {ax:SI=3D0;clobber flags:CC;} 43: dx:SI=3D[si:DI] 44: flags:CCZ=3Dcmp(dx:SI,0) 42: strict_low_part(ax:QI)=3Dflags:CCZ!=3D0 The follow-up cprop-hardreg pass does not notice that we already have zero loaded to a register. There is nothing that target-dependent part can do here. A follow-up RTL hardreg propagation pass should fix this.=