From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CD7623858CDA; Tue, 7 Feb 2023 14:12:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CD7623858CDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675779160; bh=0qMx/ozeqfqr1zJ8hmCIOyany375HetYudZxnfVpbIU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=YPUkqG0t6ocmWoHcT49yESGjXMq6cO/AmmC9B0oLOvSrT5tnaa+zkVb+M0ymS+cJH 3A/wK1sNk7tcJw+5gHBNomGfE/EKPc0BzcckriU4shqJunUi1gGnLqADBZPkB8b+aS 5gpMgTz5NVpV4FrOf264/VgO3T+OBiUqhU8CQhyc= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/108692] [11/12/13 Regression] Miscompilation of orc_test.c since r11-5160 Date: Tue, 07 Feb 2023 14:12:39 +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: jakub 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 #2 from Jakub Jelinek --- So, on simplified -O2 -ftree-vectorize testcase with trunk: int foo (signed char *x, signed char *y, int n) { int i, r =3D 0; signed char a, b; for (i =3D 0; i < n; i++) { a =3D x[i]; b =3D y[i]; int c =3D (unsigned char) a - (unsigned char) b; r =3D r + (c < 0 ? -c : c); } return r; } everything looks ok to me until vect_recog_sad_pattern is called. The interesting part of the loop in question is: [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; with 15/17 having signed char type, 5/7 unsigned char and everything else i= nt. Now, when vect_recog_sad_pattern is called, it sees as diff_stmt_vinfo->stmt patt_34 =3D (a.0_5) w- (b.1_7); which is reasonable, abs_stmt_vinfo was patt_30 =3D ABS_EXPR ; where 30 is signed short, patt_33 too set to (signed short) patt_34 and 34 unsigned short. Still, the widening subtraction is done with zero extensio= ns from unsigned char operands to unsigned short. But vect_recog_sad_pattern calls 1325 if (!vect_widened_op_tree (vinfo, diff_stmt_vinfo, MINUS_EXPR, WIDEN_MINUS_EXPR, 1326 false, 2, unprom, &half_type)) 1327 return NULL; and instead of returning a.0_5 and b.1_7 as the unpromoted operands and unsigned char as half_type, it returns a_15 and b_17 as the unpromoted oper= ands and signed char as half_type. I'd think if in vect_widened_op_tree after the early checks rhs_code !=3D c= ode we shouldn't look through further promotions and just accept what we have. as=