From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id CAF013858D1E for ; Wed, 14 Jun 2023 13:54:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CAF013858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 0EE791FDEF; Wed, 14 Jun 2023 13:54:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1686750899; 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=SF3DFeDuc3vWVAfwiHIBJNeR6NJWaFDMmRGSXP817UM=; b=2WPnfVGRa1QBo7T474gS+bmBdZAvQsCmKcDIKcPRV4FUfMYQeQExvTf0bpRKxZ9S3qYU9a zwoqErrYd1aJ1nxnTMEEzg2NpeB+u0CYlQaYTM88LSXWZpijo5ndjnSp6nG+uM+KPLFcXZ 4hDbQHzf0wUZb4ekV7vHKks2xeOgAO4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1686750899; 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=SF3DFeDuc3vWVAfwiHIBJNeR6NJWaFDMmRGSXP817UM=; b=U15adlShy9hLCSIO5upMZywAgy1k57unHYWA2Lbz1TPkrXYRZUKs37M5+9NZbAA3ogiInh Td/8l8p/AhRd6eCw== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 02EAE2C141; Wed, 14 Jun 2023 13:54:58 +0000 (UTC) Date: Wed, 14 Jun 2023 13:54:58 +0000 (UTC) From: Richard Biener To: Jakub Jelinek cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] middle-end: Move constant args folding of .UBSAN_CHECK_* and .*_OVERFLOW into fold-const-call.cc In-Reply-To: Message-ID: References: User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-4.9 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 Wed, 14 Jun 2023, Jakub Jelinek wrote: > On Wed, Jun 14, 2023 at 12:25:46PM +0000, Richard Biener wrote: > > I think that's still very much desirable so this followup looks OK. > > Maybe you can re-base it as prerequesite though? > > Rebased then (of course with the UADDC/USUBC handling removed from this > first patch, will be added in the second one). > > Ok for trunk if it passes bootstrap/regtest? OK. Thanks, Richard. > 2023-06-14 Jakub Jelinek > > * gimple-fold.cc (gimple_fold_call): Move handling of arg0 > as well as arg1 INTEGER_CSTs for .UBSAN_CHECK_{ADD,SUB,MUL} > and .{ADD,SUB,MUL}_OVERFLOW calls from here... > * fold-const-call.cc (fold_const_call): ... here. > > --- gcc/gimple-fold.cc.jj 2023-06-13 18:23:37.199793275 +0200 > +++ gcc/gimple-fold.cc 2023-06-14 15:41:51.090987708 +0200 > @@ -5702,22 +5702,6 @@ gimple_fold_call (gimple_stmt_iterator * > result = arg0; > else if (subcode == MULT_EXPR && integer_onep (arg0)) > result = arg1; > - else if (TREE_CODE (arg0) == INTEGER_CST > - && TREE_CODE (arg1) == INTEGER_CST) > - { > - if (cplx_result) > - result = int_const_binop (subcode, fold_convert (type, arg0), > - fold_convert (type, arg1)); > - else > - result = int_const_binop (subcode, arg0, arg1); > - if (result && arith_overflowed_p (subcode, type, arg0, arg1)) > - { > - if (cplx_result) > - overflow = build_one_cst (type); > - else > - result = NULL_TREE; > - } > - } > if (result) > { > if (result == integer_zero_node) > --- gcc/fold-const-call.cc.jj 2023-06-02 10:36:43.096967505 +0200 > +++ gcc/fold-const-call.cc 2023-06-14 15:40:34.388064498 +0200 > @@ -1669,6 +1669,7 @@ fold_const_call (combined_fn fn, tree ty > { > const char *p0, *p1; > char c; > + tree_code subcode; > switch (fn) > { > case CFN_BUILT_IN_STRSPN: > @@ -1738,6 +1739,46 @@ fold_const_call (combined_fn fn, tree ty > case CFN_FOLD_LEFT_PLUS: > return fold_const_fold_left (type, arg0, arg1, PLUS_EXPR); > > + case CFN_UBSAN_CHECK_ADD: > + case CFN_ADD_OVERFLOW: > + subcode = PLUS_EXPR; > + goto arith_overflow; > + > + case CFN_UBSAN_CHECK_SUB: > + case CFN_SUB_OVERFLOW: > + subcode = MINUS_EXPR; > + goto arith_overflow; > + > + case CFN_UBSAN_CHECK_MUL: > + case CFN_MUL_OVERFLOW: > + subcode = MULT_EXPR; > + goto arith_overflow; > + > + arith_overflow: > + if (integer_cst_p (arg0) && integer_cst_p (arg1)) > + { > + tree itype > + = TREE_CODE (type) == COMPLEX_TYPE ? TREE_TYPE (type) : type; > + bool ovf = false; > + tree r = int_const_binop (subcode, fold_convert (itype, arg0), > + fold_convert (itype, arg1)); > + if (!r || TREE_CODE (r) != INTEGER_CST) > + return NULL_TREE; > + if (arith_overflowed_p (subcode, itype, arg0, arg1)) > + ovf = true; > + if (TREE_OVERFLOW (r)) > + r = drop_tree_overflow (r); > + if (itype == type) > + { > + if (ovf) > + return NULL_TREE; > + return r; > + } > + else > + return build_complex (type, r, build_int_cst (itype, ovf)); > + } > + return NULL_TREE; > + > default: > return fold_const_call_1 (fn, type, arg0, arg1); > } > > > Jakub > > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman; HRB 36809 (AG Nuernberg)