From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B34D7393BC17; Wed, 19 May 2021 12:00:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B34D7393BC17 From: "zsojka at seznam dot cz" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/100672] wrong code with vector shift and unary minus Date: Wed, 19 May 2021 12:00:10 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: zsojka at seznam dot cz X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- 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 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, 19 May 2021 12:00:10 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100672 --- Comment #10 from Zdenek Sojka --- (In reply to Zdenek Sojka from comment #9) > (In reply to Richard Biener from comment #8) > > (In reply to Zdenek Sojka from comment #7) > > > (In reply to Richard Biener from comment #2) > > > > Maybe sth is wrong with the testcase? clang also results in an abo= rt. Isn't > > > > right-shift of negative values undefined? > > > >=20 > > >=20 > > > Thank you for having a look. > > >=20 > > > I believe the behavior is fully defined. The vectors are unsigned, an= d the > > > conversion to unsigned is done by adding 2**64; this behaves the same: > > >=20 > > > $ cat testcase.c > > > typedef unsigned long long __attribute__((__vector_size__ (32))) V; > > >=20 > > > V > > > foo (V v) > > > { > > > return -(v >> 1); > >=20 > > but this is a logical right shift, thus gives 0x7ff...e, ... > > and negating that doesn't yield 1. > >=20 >=20 > Shame on me. You are very right. I did the mistake while reducing the testcase. The original testcase had positive arguments: $ cat testcase.c typedef unsigned long long __attribute__((__vector_size__ (32))) V; V foo (V v) { return -(v >> 1); } int main (void) { V v =3D foo ((V) { 2, 4, 6, 8 }); if (v[0] !=3D 0xffffffffffffffff || v[1] !=3D 0xfffffffffffffffe || v[2] !=3D 0xfffffffffffffffd || v[3] !=3D 0xfffffffffffffffc) __builtin_abort (); return 0; } I wanted to prevent the long 0xfffff... constants, but broke the testcase i= n he process. Thank you for correcting me.=