From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id AF9573840117 for ; Tue, 13 Dec 2022 10:01:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AF9573840117 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 6F1F82255B; Tue, 13 Dec 2022 10:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1670925692; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=InJuPJVLgaFJs+dmBebzpf106zpf8EKAMetUPkv68w4=; b=uzFYkLfevHyHCQMtAgrDB4oh2sx3Bo9VW89l4s+OihUSpcRqBBzaCvt9c+W7QKvwNZhAn5 5YNWcgZPxfeL80hIYizMmh6pbrtVukHr/RylqJOUcIP5iTKOQKfINIqaPXN0TGV9j8mZNz MHrmJqEQUYtAYl18Uw+foIjH6t/qxuE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1670925692; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=InJuPJVLgaFJs+dmBebzpf106zpf8EKAMetUPkv68w4=; b=frldSYXPp1WVhYfe6PtHAGnG1kH5ZSCVAAgbnUCyhZx66AaUYJ3trDi+yDP6dlUTM5kRYt N0/+aYYq7BovoEDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 5E8E3138F9; Tue, 13 Dec 2022 10:01:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QFcMF3xNmGPYVAAAMHmgww (envelope-from ); Tue, 13 Dec 2022 10:01:32 +0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Richard Biener Mime-Version: 1.0 (1.0) Subject: Re: [PATCH] vect-patterns: Fix up vect_recog_rotate_pattern [PR108064] Date: Tue, 13 Dec 2022 11:01:21 +0100 Message-Id: <5511004D-6462-4A88-BF9E-57183202BDA1@suse.de> References: Cc: gcc-patches@gcc.gnu.org In-Reply-To: To: Jakub Jelinek X-Mailer: iPhone Mail (20B110) X-Spam-Status: No, score=-5.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: > Am 13.12.2022 um 10:28 schrieb Jakub Jelinek via Gcc-patches : >=20 > =EF=BB=BFHi! >=20 > Since vect_recog_rotate_pattern has been extended to work also > on signed types in r13-1100 we miscompile the testcase below. > vect_recog_rotate_pattern actually emits correct scalar code into > the pattern def sequence (in particular cast to utype, doing the > 2 shifts in utype so that the right shift is logical and not arithmetic, > or and then cast back to the signed type), but it didn't supply vectype > for most of those pattern statements, which means that the generic handlin= g > fills it up later with the vectype provided by vect_recog_rotate_pattern. > The problem is that it is vectype of the result of the whole pattern, > i.e. vector of signed values in this case, while the conversion to utype, > 2 shifts and or (everything with utype lhs in scalar code) should have > uvectype as STMT_VINFO_VECTYPE. What an interesting trap=E2=80=A6 > Fixed with following patch, bootstrapped/regtested on x86_64-linux and > i686-linux, ok for trunk? Ok. Thanks, Richard=20 > 2022-12-13 Jakub Jelinek >=20 > PR tree-optimization/108064 > * tree-vect-patterns.cc (vect_recog_rotate_pattern): Pass uvectype > as 4th argument to append_pattern_def_seq for statements with lhs > with utype type. >=20 > * gcc.c-torture/execute/pr108064.c: New test. >=20 > --- gcc/tree-vect-patterns.cc.jj 2022-12-05 11:10:37.000000000 +0100 > +++ gcc/tree-vect-patterns.cc 2022-12-12 13:14:23.356628767 +0100 > @@ -3113,7 +3113,7 @@ vect_recog_rotate_pattern (vec_info *vin > { > def =3D vect_recog_temp_ssa_var (utype, NULL); > def_stmt =3D gimple_build_assign (def, NOP_EXPR, oprnd0); > - append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt); > + append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt, uvectype); > oprnd0 =3D def; > } >=20 > @@ -3137,7 +3137,7 @@ vect_recog_rotate_pattern (vec_info *vin > { > def =3D vect_recog_temp_ssa_var (utype, NULL); > def_stmt =3D gimple_build_assign (def, NOP_EXPR, oprnd1); > - append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt); > + append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt, uvectype); > } > stype =3D TREE_TYPE (def); >=20 > @@ -3185,13 +3185,13 @@ vect_recog_rotate_pattern (vec_info *vin > def_stmt =3D gimple_build_assign (var1, rhs_code =3D=3D LROTATE_EXPR > ? LSHIFT_EXPR : RSHIFT_EXPR, > oprnd0, def); > - append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt); > + append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt, uvectype); >=20 > var2 =3D vect_recog_temp_ssa_var (utype, NULL); > def_stmt =3D gimple_build_assign (var2, rhs_code =3D=3D LROTATE_EXPR > ? RSHIFT_EXPR : LSHIFT_EXPR, > oprnd0, def2); > - append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt); > + append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt, uvectype); >=20 > /* Pattern detected. */ > vect_pattern_detected ("vect_recog_rotate_pattern", last_stmt); > @@ -3202,7 +3202,7 @@ vect_recog_rotate_pattern (vec_info *vin >=20 > if (!useless_type_conversion_p (type, utype)) > { > - append_pattern_def_seq (vinfo, stmt_vinfo, pattern_stmt); > + append_pattern_def_seq (vinfo, stmt_vinfo, pattern_stmt, uvectype);= > tree result =3D vect_recog_temp_ssa_var (type, NULL); > pattern_stmt =3D gimple_build_assign (result, NOP_EXPR, var); > } > --- gcc/testsuite/gcc.c-torture/execute/pr108064.c.jj 2022-12-12 13:22:= 29.875542508 +0100 > +++ gcc/testsuite/gcc.c-torture/execute/pr108064.c 2022-12-12 13:21:32.= 516377957 +0100 > @@ -0,0 +1,28 @@ > +/* PR tree-optimization/108064 */ > + > +static inline short > +foo (short value) > +{ > + return ((value >> 8) & 0xff) | ((value & 0xff) << 8); > +} > + > +__attribute__((noipa)) > +void > +bar (short *d, const short *s) > +{ > + for (unsigned long i =3D 0; i < 4; i++) > + d[i] =3D foo (s[i]); > +} > + > +int > +main () > +{ > + short a[4] __attribute__((aligned (16))) =3D { 0xff, 0, 0, 0 }; > + short b[4] __attribute__((aligned (16))); > + short c[4] __attribute__((aligned (16))); > + > + bar (b, a); > + bar (c, b); > + if (a[0] !=3D c[0]) > + __builtin_abort (); > +} >=20 > Jakub >=20