From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 86AB7394849E; Fri, 10 Feb 2023 17:46:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 86AB7394849E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676051203; bh=BV0NZfLj+K8j1wNBCw5NyDTUVrnnT2F4sLn1B2+If/E=; h=From:To:Subject:Date:In-Reply-To:References:From; b=y71Etmt2dRX/vYRvkCIbhLvzqfe3Mask7qlZU70lwtCPrT42ti+/B7a4DJgDDmuyX t6SC+f8jV6xGgiaQtHiSRJlx72u0etWZExPSKtbHOnifHr4kxN9qxrUqwy997xWuN4 UEHDZQnLJjCoDBZJH/qAr/+Ktn/lg3OusB6YF6sQ= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/108692] [11/12 Regression] Miscompilation of orc_test.c since r11-5160 Date: Fri, 10 Feb 2023 17:46:42 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 13.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: 11.4 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=3D108692 --- Comment #6 from CVS Commits --- The releases/gcc-12 branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:00136f439e2849af2bfd9934d79a8297ab09a1d9 commit r12-9152-g00136f439e2849af2bfd9934d79a8297ab09a1d9 Author: Jakub Jelinek Date: Wed Feb 8 18:41:21 2023 +0100 vect-patterns: Fix up vect_widened_op_tree [PR108692] The following testcase is miscompiled on aarch64-linux since r11-5160. Given [local count: 955630225]: # i_22 =3D PHI # r_23 =3D PHI ... a.0_5 =3D (unsigned char) a_15; _6 =3D (int) a.0_5; b.1_7 =3D (unsigned char) b_17; _8 =3D (int) b.1_7; c_18 =3D _6 - _8; _9 =3D ABS_EXPR ; r_19 =3D _9 + r_23; ... where SSA_NAMEs 15/17 have signed char, 5/7 unsigned char and rest is i= nt we first pattern recognize c_18 as patt_34 =3D (a.0_5) w- (b.1_7); which is still correct, 5/7 are unsigned char subtracted in wider type, but then vect_recog_sad_pattern turns it into SAD_EXPR which is incorrect, because 15/17 are signed char and so it is sum of absolute signed differences rather than unsigned sum of absolute unsigned differences. The reason why this happens is that vect_recog_sad_pattern calls vect_widened_op_tree with MINUS_EXPR, WIDEN_MINUS_EXPR on the patt_34 =3D (a.0_5) w- (b.1_7); statement's vinfo and vect_widened_op_t= ree calls vect_look_through_possible_promotion on the operands of the WIDEN_MINUS_EXPR, which looks through the further casts. vect_look_through_possible_promotion has careful code to stop when there would be nested casts that need to be preserved, but the problem here is that the WIDEN_*_EXPR operation itself has an implicit cast on the operands already - in this case of WIDEN_MINUS_EXPR the unsigned char 5/7 SSA_NAMEs are widened to unsigned short before the subtraction, and vect_look_through_possible_promotion obviously isn't told about tha= t. Now, I think when we see those WIDEN_{MULT,MINUS,PLUS}_EXPR codes, we h= ad to look through possible promotions already when creating those and so vect_look_through_possible_promotion again isn't really needed, all we = need to do is arrange what that function will do if the operand isn't result of any cast. Other option would be let vect_look_through_possible_promotion know about the implicit promotion from the WIDEN_*_EXPR, but I'm afraid that would be much harder. 2023-02-08 Jakub Jelinek PR tree-optimization/108692 * tree-vect-patterns.cc (vect_widened_op_tree): If rhs_code is widened_code which is different from code, don't call vect_look_through_possible_promotion but instead just check op = is SSA_NAME with integral type for which vect_is_simple_use is true and call set_op on this_unprom. * gcc.dg/pr108692.c: New test. (cherry picked from commit 6ad1c1027628f094260037536f6b6fcdb63b5add)=