From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 5FD5C3858D20 for ; Wed, 10 Apr 2024 09:44:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5FD5C3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5FD5C3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=89.208.246.23 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712742292; cv=none; b=OK3jg5L8XNwWp4giy28Fy5CmiPwyRM43/I6YwRcqGib+/WzXtFbWKfiAeT58DcttrKfWA+1t8flJezM2Rg1E/kJjQuowJ79MJkY1Qr0MMmG6FubsiLtAxY/ddTqNvRUuEg8u7eQ9Fzhb9a8Hg5sKHrqlsfJXrqudnWN9faSFsh4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712742292; c=relaxed/simple; bh=eItWj7ttGlrfgIB+8ZC0Cgdoh6XdxupCNknBKQbXNGE=; h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version; b=SLCQWoPFiR976OXQWLa6DF1ZADu4LCuNrg/4rJmBIuenTlHcHAuFb5HTva7sPfp8JMpTqCdC+FDDuclQe/WNUnEw9SJWQ1R6sVdpeYfkxz8ug3DKkbhCJe8I1lsH5+OGM0yfrZuBw57PxPSAF0MxKAokf23S+PbMUwgv5ORK0Ks= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1712742284; bh=eItWj7ttGlrfgIB+8ZC0Cgdoh6XdxupCNknBKQbXNGE=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=C1exKoUrbWbIF4MBaBvvPxjm/AcFNDvy8KSTn8ajhi5Jr/FA4a9AR0ym6SsfkVwqH 7XYXemkIVEqw3UrwkP2fAXL01L4OTRoT5rueDVXj09/ed3CNgO6Czc2MzQUepaAiCQ wm+TBUdEv7qPVCIu1AQEWnfifooVWRSGzomdDhbc= Received: from [127.0.0.1] (unknown [IPv6:2001:470:683e::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 31C1467536; Wed, 10 Apr 2024 05:44:44 -0400 (EDT) Message-ID: Subject: Re: optimizer discards sign information From: Xi Ruoyao To: LIU Hao , Alexander Monakov , stefan@franke.ms Cc: gcc-help@gcc.gnu.org Date: Wed, 10 Apr 2024 17:44:42 +0800 In-Reply-To: <0c105596-ecca-4936-84b0-b2f081b47bf2@126.com> References: <016501da8b24$735d5170$5a17f450$@franke.ms> <5379650ad2582ae97c40ef1a78ded354033d2f71.camel@xry111.site> <0c105596-ecca-4936-84b0-b2f081b47bf2@126.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.0 MIME-Version: 1.0 X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,LIKELY_SPAM_FROM,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Wed, 2024-04-10 at 17:40 +0800, LIU Hao wrote: > =E5=9C=A8 2024-04-10 17:19, Xi Ruoyao via Gcc-help =E5=86=99=E9=81=93: > > $ cc t.c -O2 -fsanitize=3Dundefined > > $ ./a.out > > t.c:7:15: runtime error: signed integer overflow: 65535 * 65535 > > cannot be represented in type 'int' > > fffe0001 >=20 > Undefined behavior is not a valid point, as it never happens. You only get a "different result" when an undefined behavior happens, thus it **is** a valid point to say there is no wrong-code issue. > It's a real bug. There are many PRs on bugzilla. You may argue it's a missed-optimization, but we were discussing about wrong-code or not. > The sign extension could have been eliminated completely: >=20 > =C2=A0=C2=A0=C2=A0 movzx eax, si > =C2=A0=C2=A0=C2=A0 movzx edi, di > =C2=A0=C2=A0=C2=A0 imul eax, edi > =C2=A0=C2=A0=C2=A0 ret >=20 >=20 > And here is a similar issue: >=20 > =C2=A0=C2=A0=C2=A0 typedef unsigned long long int u64; > =C2=A0=C2=A0=C2=A0 typedef unsigned int u32; >=20 > =C2=A0=C2=A0=C2=A0 u64 foo(u64 a) { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return (u32) __builtin_ctzll(a); > =C2=A0=C2=A0=C2=A0 } >=20 > which results in >=20 > =C2=A0=C2=A0=C2=A0 xor eax, eax > =C2=A0=C2=A0=C2=A0 rep bsf rax, rdi=C2=A0=C2=A0 // effectively `tzcnt rax= , rdi` > =C2=A0=C2=A0=C2=A0 cdqe=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // unnecessary sign-extension > =C2=A0=C2=A0=C2=A0 ret --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University