From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by sourceware.org (Postfix) with ESMTPS id 65FBE3858404 for ; Thu, 15 Sep 2022 06:39:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 65FBE3858404 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-x529.google.com with SMTP id z21so25493462edi.1 for ; Wed, 14 Sep 2022 23:39:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date; bh=Xwpi0a3aROoCU6qd5gXpwTWhuEsmy1Alhqqg7Sc9bSE=; b=Ax1DOz1XnJoKuOqI56Gql+EfFuVkLFz+G8HEErVVMBIlmTnrIjY/L2pz89BlB6V0Y6 L0Deypa6H/wyH3NBJ6UXujUnHfz+6tlMDfdRNbUXbhl+4vyu5NruGZ4xfJxR97CVPfqO oe63h0HTGwMxdpRj4znEwf8gyn+uh0bk2BP5nXfQswKQeK5/VIA3tc5Ebcm90A1YBDMm 2iESrtOiSVGhmEU5FYHrXpQ1m0qNctMqjMO8mKyYTsdaVpMnihEKAZQQzmvpRUgTqG5J tsLgrWZS4OYmUfW00bV/2YAnIHwd83ISoqP7WbmnUkMqkG/pzrZ0rk9RqNGj6+yKZmKt Tdbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date; bh=Xwpi0a3aROoCU6qd5gXpwTWhuEsmy1Alhqqg7Sc9bSE=; b=hlU3E+jnNPFNzZEkcEE0QWOLn9B8AvyWKo1QXZm2lfU/nlmReOmc7M0dXUepftfLTT Z/fx1pc8J1f0j8HDCR97JWWCTWcsvWz/iSasLQoqzJrhCkWaTrXJk2yoxWCQIiRomQar UAZ8+kXjMB56pMhLDmUijPQ1LbU77i9opZADXT0BJPpA+xPenpyQlofSS6h6fNbCzOAE zcnPgDnfnpbmOfthmJ2PSsPRcR6OzOJoJkHENuJCj49FfC7GZNwnRyb/dzLCkel5914y 0GkODaCTuls3DNyYRdysr1Bil6uPWpnhrxZJSazWyAXVTUdVIrCQDe+YxxtjT86HU4F8 3DAQ== X-Gm-Message-State: ACgBeo00NLUnoWFmZB62WbySLKFYOBPetS3zpq3WVBRp5ES/IyBDrf9f m7sl1x55EbK0OOAQA6R+T/fxfVxipUdAnt9VOos= X-Google-Smtp-Source: AA6agR6n85LDs6MuoKI2iKRVuO4yO0QK3dKdHuaVILf1hoY10Qjp0NkWMJUtP18JxAXtbq/Eaeac2V7WMTrCB9fLNy0= X-Received: by 2002:a05:6402:3786:b0:451:24da:f8c9 with SMTP id et6-20020a056402378600b0045124daf8c9mr23353711edb.250.1663223968115; Wed, 14 Sep 2022 23:39:28 -0700 (PDT) MIME-Version: 1.0 References: <002d01d8c79f$dc5fe830$951fb890$@nextmovesoftware.com> <4855eb8c-22fd-17f5-fa97-eacd33d015dc@inria.fr> In-Reply-To: <4855eb8c-22fd-17f5-fa97-eacd33d015dc@inria.fr> From: Richard Biener Date: Thu, 15 Sep 2022 08:39:16 +0200 Message-ID: Subject: Re: [PATCH] Optimize (X< Cc: Roger Sayle , GCC Patches Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,KAM_SHORT,RCVD_IN_DNSWL_NONE,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: On Wed, Sep 14, 2022 at 11:42 PM Marc Glisse via Gcc-patches wrote: > > 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 =E2=80=98>>=E2=80=99 acts on ne= gative 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 =E2=80=98<<=E2=80=99 = as undefined." Oh, I wasn't aware of that. > 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) int= o > (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. Or perform the (X+Y) operation in an unsigned type. Richard. > -- > Marc Glisse