From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sourceware.org (Postfix) with ESMTPS id B9DFD385843A for ; Wed, 14 Sep 2022 21:42:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B9DFD385843A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=inria.fr Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=inria.fr DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version:content-transfer-encoding; bh=TSl4X/jQ9PsNekcTaQCFULelgSRitpoais2QXLSB4Ls=; b=XgxVv+qoD3U6v8sUsThvnl3H1Bq5OosyJoO8++WdzdTG2hNgTXw6xPFT mzqt4wZVbDDnVg6LCMZDJYt55vPMZ4jSrioLm11d6j8BbX6+xnHUJgPLi KhVQ+O4ODDJrvMr6B0/sDtaMp5je+BFLFk9MFDeTsxBKkaMRbjn18DMqd 0=; Authentication-Results: mail2-relais-roc.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=marc.glisse@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="5.93,315,1654552800"; d="scan'208";a="52833554" Received: from 85-171-187-240.rev.numericable.fr (HELO hippo) ([85.171.187.240]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Sep 2022 23:42:03 +0200 Date: Wed, 14 Sep 2022 23:42:02 +0200 (CEST) From: Marc Glisse To: Roger Sayle cc: 'GCC Patches' Subject: Re: [PATCH] Optimize (X< Message-ID: <4855eb8c-22fd-17f5-fa97-eacd33d015dc@inria.fr> References: <002d01d8c79f$dc5fe830$951fb890$@nextmovesoftware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-7; format=flowed Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_SHORT,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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: On Tue, 13 Sep 2022, Roger Sayle wrote: > This patch tweaks the match.pd transformation previously added to fold > (X< (wrapping) types, to also allow signed integer types provided that they > don't trap and the overflow needn't be preserved for sanitization. > i.e. this should now apply (by default) for "int x,y;", but is disabled > with -ftrapv. In https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html , I read: "Bitwise operators act on the representation of the value including both the sign and value bits, where the sign bit is considered immediately above the highest-value value bit. Signed ¡>>¢ acts on negative numbers by sign extension. As an extension to the C language, GCC does not use the latitude given in C99 and C11 only to treat certain aspects of signed ¡<<¢ as undefined." To me, this means that for instance INT_MIN<<1 is well defined and evaluates to 0. But with this patch we turn (INT_MIN<<1)+(INT_MIN<<1) into (INT_MIN+INT_MIN)<<1, which is UB. If we decide not to support this extension anymore, I think we need to change the documentation first. -- Marc Glisse