From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id 67E52385842D for ; Fri, 15 Dec 2023 07:40:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 67E52385842D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 67E52385842D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702626056; cv=none; b=UOKJrEoKZlFUa7XaIVAytCKeap4uM+fFT2dbJYBQ6TvHK8Hbo32PaSL0BiO9Ni9tiogQhp4PJEXPjaapZ7ujUbTtM9Eg4vwTy63fFXVCc+LWPXBzykYiHrF/SupT+1liha+y4RAAAOxLVZfGrRi8LyjlivZ2T2sUtN9nziEAhI4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702626056; c=relaxed/simple; bh=n0OmQ7oE/8FORUDkBDGzjCx8oMXJFw83gnuLiI8MJR8=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:Message-ID:MIME-Version; b=C1ivGfqmyBwyK4T+IimwjNHFj6Vxz/XxJzDn+PlpYeaazoSfBCmQ6B7hctJWgY19gjRZyaen0uUrU22kHCFTk1PaWaUgnKAbsNU5CIFA+wEWLWqkngZPlknCyNyw8cDdRipxFJRnN5+S02jiX98DB4jSYhLe/EA3gpzhYI60ctw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.4.150] (unknown [10.168.4.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4A05822223; Fri, 15 Dec 2023 07:40:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702626051; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gqQVRC+7PW6p7kHFqm4eYuxWVSJhRw0n3cNb10dmMwM=; b=AB+tV27UgK+FhLbpxu8HCidyaST6JW7ZXKfMFJ+o6nz2e9gRlKS02i3I84ZhbKpwn12u7w BZ3Onh83jIJFFH+VYbI9L2TJkYAEApii5/ob/DaugJD4FxIEBQzMKdIsLLV2LH+dht3HtO Tkq47MyQs/XlXe8acBOlVJSBj2sMqfk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702626051; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gqQVRC+7PW6p7kHFqm4eYuxWVSJhRw0n3cNb10dmMwM=; b=8FAeqNeXqmZs5XmyRjmBE25kWDvgV6ib7NdQpkltdiPOQOnXG4T4auhJUWsLGIk6RFlUPi HhO8MtohptY8vsAA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702626051; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gqQVRC+7PW6p7kHFqm4eYuxWVSJhRw0n3cNb10dmMwM=; b=AB+tV27UgK+FhLbpxu8HCidyaST6JW7ZXKfMFJ+o6nz2e9gRlKS02i3I84ZhbKpwn12u7w BZ3Onh83jIJFFH+VYbI9L2TJkYAEApii5/ob/DaugJD4FxIEBQzMKdIsLLV2LH+dht3HtO Tkq47MyQs/XlXe8acBOlVJSBj2sMqfk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702626051; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gqQVRC+7PW6p7kHFqm4eYuxWVSJhRw0n3cNb10dmMwM=; b=8FAeqNeXqmZs5XmyRjmBE25kWDvgV6ib7NdQpkltdiPOQOnXG4T4auhJUWsLGIk6RFlUPi HhO8MtohptY8vsAA== Date: Fri, 15 Dec 2023 08:39:45 +0100 (CET) From: Richard Biener To: Jakub Jelinek cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] lower-bitint: Fix .{ADD,SUB,MUL}_OVERFLOW with _BitInt large/huge INTEGER_CST arguments [PR113003] In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Level: X-Spam-Score: -1.95 Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -1.95 X-Spamd-Result: default: False [-1.95 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.19)[-0.960]; RCPT_COUNT_TWO(0.00)[2]; NEURAL_SPAM_LONG(1.34)[0.383]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%] X-Spam-Flag: NO X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Thu, 14 Dec 2023, Jakub Jelinek wrote: > Hi! > > As shown in the testcase, .{ADD,SUB,MUL}_OVERFLOW calls are another > exception to the middle/large/huge _BitInt discovery through SSA_NAMEs > next to stores of INTEGER_CSTs to memory and their conversions to > floating point. > The calls can have normal COMPLEX_TYPE with INTEGER_TYPE elts return type > (or BITINT_TYPE with small precision) and one of the arguments can be > SSA_NAME with an INTEGER_TYPE or small BITINT_TYPE as well; still, when > there is an INTEGER_CST argument with large/huge BITINT_TYPE, we need to > lower it that way. > > Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for > trunk? OK. Richard. > 2023-12-14 Jakub Jelinek > > PR tree-optimization/113003 > * gimple-lower-bitint.cc (arith_overflow_arg_kind): New function. > (gimple_lower_bitint): Use it to catch .{ADD,SUB,MUL}_OVERFLOW > calls with large/huge INTEGER_CST arguments. > > * gcc.dg/bitint-54.c: New test. > > --- gcc/gimple-lower-bitint.cc.jj 2023-12-13 11:36:21.636633517 +0100 > +++ gcc/gimple-lower-bitint.cc 2023-12-14 13:28:17.660737468 +0100 > @@ -5641,6 +5641,37 @@ build_bitint_stmt_ssa_conflicts (gimple > def (live, lhs, graph); > } > > +/* If STMT is .{ADD,SUB,MUL}_OVERFLOW with INTEGER_CST arguments, > + return the largest bitint_prec_kind of them, otherwise return > + bitint_prec_small. */ > + > +static bitint_prec_kind > +arith_overflow_arg_kind (gimple *stmt) > +{ > + bitint_prec_kind ret = bitint_prec_small; > + if (is_gimple_call (stmt) && gimple_call_internal_p (stmt)) > + switch (gimple_call_internal_fn (stmt)) > + { > + case IFN_ADD_OVERFLOW: > + case IFN_SUB_OVERFLOW: > + case IFN_MUL_OVERFLOW: > + for (int i = 0; i < 2; ++i) > + { > + tree a = gimple_call_arg (stmt, i); > + if (TREE_CODE (a) == INTEGER_CST > + && TREE_CODE (TREE_TYPE (a)) == BITINT_TYPE) > + { > + bitint_prec_kind kind = bitint_precision_kind (TREE_TYPE (a)); > + ret = MAX (ret, kind); > + } > + } > + break; > + default: > + break; > + } > + return ret; > +} > + > /* Entry point for _BitInt(N) operation lowering during optimization. */ > > static unsigned int > @@ -5657,7 +5688,12 @@ gimple_lower_bitint (void) > continue; > tree type = TREE_TYPE (s); > if (TREE_CODE (type) == COMPLEX_TYPE) > - type = TREE_TYPE (type); > + { > + if (arith_overflow_arg_kind (SSA_NAME_DEF_STMT (s)) > + != bitint_prec_small) > + break; > + type = TREE_TYPE (type); > + } > if (TREE_CODE (type) == BITINT_TYPE > && bitint_precision_kind (type) != bitint_prec_small) > break; > @@ -5745,7 +5781,12 @@ gimple_lower_bitint (void) > continue; > tree type = TREE_TYPE (s); > if (TREE_CODE (type) == COMPLEX_TYPE) > - type = TREE_TYPE (type); > + { > + if (arith_overflow_arg_kind (SSA_NAME_DEF_STMT (s)) > + >= bitint_prec_large) > + has_large_huge = true; > + type = TREE_TYPE (type); > + } > if (TREE_CODE (type) == BITINT_TYPE > && bitint_precision_kind (type) >= bitint_prec_large) > { > @@ -6245,8 +6286,7 @@ gimple_lower_bitint (void) > { > bitint_prec_kind this_kind > = bitint_precision_kind (TREE_TYPE (t)); > - if (this_kind > kind) > - kind = this_kind; > + kind = MAX (kind, this_kind); > } > if (is_gimple_assign (stmt) && gimple_store_p (stmt)) > { > @@ -6255,8 +6295,7 @@ gimple_lower_bitint (void) > { > bitint_prec_kind this_kind > = bitint_precision_kind (TREE_TYPE (t)); > - if (this_kind > kind) > - kind = this_kind; > + kind = MAX (kind, this_kind); > } > } > if (is_gimple_assign (stmt) > @@ -6268,21 +6307,22 @@ gimple_lower_bitint (void) > { > bitint_prec_kind this_kind > = bitint_precision_kind (TREE_TYPE (t)); > - if (this_kind > kind) > - kind = this_kind; > + kind = MAX (kind, this_kind); > } > } > if (is_gimple_call (stmt)) > { > t = gimple_call_lhs (stmt); > - if (t > - && TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE > - && TREE_CODE (TREE_TYPE (TREE_TYPE (t))) == BITINT_TYPE) > + if (t && TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE) > { > - bitint_prec_kind this_kind > - = bitint_precision_kind (TREE_TYPE (TREE_TYPE (t))); > - if (this_kind > kind) > - kind = this_kind; > + bitint_prec_kind this_kind = arith_overflow_arg_kind (stmt); > + kind = MAX (kind, this_kind); > + if (TREE_CODE (TREE_TYPE (TREE_TYPE (t))) == BITINT_TYPE) > + { > + this_kind > + = bitint_precision_kind (TREE_TYPE (TREE_TYPE (t))); > + kind = MAX (kind, this_kind); > + } > } > } > if (kind == bitint_prec_small) > --- gcc/testsuite/gcc.dg/bitint-54.c.jj 2023-12-14 13:47:46.683512224 +0100 > +++ gcc/testsuite/gcc.dg/bitint-54.c 2023-12-14 13:47:20.191879500 +0100 > @@ -0,0 +1,21 @@ > +/* PR tree-optimization/113003 */ > +/* { dg-do compile { target bitint } } */ > +/* { dg-options "-std=c23 -O2" } */ > + > +#if __BITINT_MAXWIDTH__ >= 131 > +int > +foo (_BitInt(7) x) > +{ > + return __builtin_mul_overflow_p (x, 1046555807606105294475452482332716433408wb, 0); > +} > + > +#ifdef __SIZEOF_INT128__ > +int > +bar (unsigned __int128 x) > +{ > + return __builtin_sub_overflow_p (340282366920938463463374607431768211457uwb, x, 0); > +} > +#endif > +#else > +int i; > +#endif > > Jakub > > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)