From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 83301385780E for ; Wed, 20 Jan 2021 13:24:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 83301385780E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rguenther@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 70E54ABDA; Wed, 20 Jan 2021 13:24:57 +0000 (UTC) Date: Wed, 20 Jan 2021 14:24:57 +0100 (CET) From: Richard Biener To: Jakub Jelinek cc: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Re: [PATCH] Handle overflow in dependence analysis lambda ops gracefully In-Reply-To: <20210120121947.GQ4020736@tucnak> Message-ID: References: <20210120113358.GP4020736@tucnak> <20210120121947.GQ4020736@tucnak> User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Jan 2021 13:25:00 -0000 On Wed, 20 Jan 2021, Jakub Jelinek wrote: > On Wed, Jan 20, 2021 at 01:15:12PM +0100, Richard Biener wrote: > > OK, fixed. Guess we could also use __builtin_mul_overflow directly > > if supported via a GCC_VERSION check. Looks like it's present > > since GCC 5 at least. So sth like (incremental) > > > > diff --git a/gcc/hwint.h b/gcc/hwint.h > > index 53f4ed5dcad..6d2d491acfa 100644 > > --- a/gcc/hwint.h > > +++ b/gcc/hwint.h > > @@ -354,12 +354,19 @@ add_hwi (HOST_WIDE_INT a, HOST_WIDE_INT b, bool > > *overflow) > > inline HOST_WIDE_INT > > mul_hwi (HOST_WIDE_INT a, HOST_WIDE_INT b, bool *overflow) > > { > > +#if GCC_VERSION < 5001 > > unsigned HOST_WIDE_INT result = a * (unsigned HOST_WIDE_INT)b; > > - if (a != 0 && (HOST_WIDE_INT)result / a != b) > > + if ((a == -1 && b == HOST_WIDE_INT_MIN) > > + || (a != 0 && (HOST_WIDE_INT)result / a != b)) > > *overflow = true; > > else > > *overflow = false; > > return result; > > +#else > > + HOST_WIDE_INT result; > > + *overflow = __builtin_mul_overflow (a, b, &result); > > + return result; > > +#endif > > } > > > > for the add case we should match all of the function I guess. > > Yeah, sure. > Maybe bump somewhat the GCC_VERSION number in there, we've had bugs in > __builtin_mul_overflow expansion too. Wow, a bugzilla search finds wrong-code that's only fixed in 9.3+. So I guess I'll check for GCC 11+ then and not worry for stage1, non-bootstrapped GCC or crosses with host != GCC 11. Richard.