From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6D98B3858D37; Mon, 29 Aug 2022 10:05:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D98B3858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661767559; bh=bVFLLIQuAw2ZcTHU2l/TVc3oN1IQ1pgCct2LZzCu0JY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Lx2sDvvBO3704vZNko0gfGiengEk0StoXHSMuw3K7kPnL4d9DWubCHwTGpFDCEk0T EEzuCvmQeEUHqhfk+g2JEvX6wlxsInnuD1I+hfO4obMqqZ3+ombNwJVQt3fDQDu6DV ezMpm23UM9Zb3E8YoKgepKbvMgQvbC8f3sWKMvcs= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/106590] [12/13 Regression] x86-64 miscompilation starting with r12-8233-g1ceddd7497e15d w/ mtune=skylake Date: Mon, 29 Aug 2022 10:05:57 +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: 12.1.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: jakub at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.3 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106590 --- Comment #11 from CVS Commits --- The releases/gcc-12 branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:030063c43f30a2335d3c03182df0beb82d003816 commit r12-8720-g030063c43f30a2335d3c03182df0beb82d003816 Author: Jakub Jelinek Date: Mon Aug 15 13:56:57 2022 +0200 ifcvt: Fix up noce_convert_multiple_sets [PR106590] The following testcase is miscompiled on x86_64-linux. The problem is in the noce_convert_multiple_sets optimization. We essentially have: if (g =3D=3D 1) { g =3D 1; f =3D 23; } else { g =3D 2; f =3D 20; } and for each insn try to create a conditional move sequence. There is code to detect overlap with the regs used in the condition and the destinations, so we actually try to construct: tmp_g =3D g =3D=3D 1 ? 1 : 2; f =3D g =3D=3D 1 ? 23 : 20; g =3D tmp_g; which is fine. But, we actually try to create two different conditional move sequences in each case, seq1 with the whole (eq (reg/v:HI 82 [ g ]) (const_int 1 [0x1])) condition and seq2 with cc_cmp (eq (reg:CCZ 17 flags) (const_int 0 [0])) to rely on the earlier present comparison. In each case, we compare the rtx costs and choose the cheaper sequence (seq1 if both have the same cost). The problem is that with the skylake tuning, tmp_g =3D g =3D=3D 1 ? 1 : 2; is actually expanded as tmp_g =3D (g =3D=3D 1) + 1; in seq1 (which clobbers (reg 17 flags)) and as a cmov in seq2 (which doesn't). The tuning says both have the same cost, so we pick seq1. Next we check sequences for f =3D g =3D=3D 1 ? 23 : 20; and here the seq2 cmov is cheaper, but it uses (reg 17 flags) which has been clobbered earlier. The following patch fixes that by detecting if we in the chosen sequence clobber some register mentioned in cc_cmp or rev_cc_cmp, and if yes, arranges for only seq1 (i.e. sequences that emit the comparison itself) to be used after that. 2022-08-15 Jakub Jelinek PR rtl-optimization/106590 * ifcvt.cc (check_for_cc_cmp_clobbers): New function. (noce_convert_multiple_sets_1): If SEQ sets or clobbers any regs mentioned in cc_cmp or rev_cc_cmp, don't consider seq2 for any further conditional moves. * gcc.dg/torture/pr106590.c: New test. (cherry picked from commit 3a74a7bf62f47ed0d19866576378724be932ee17)=