From patchwork Thu Feb 29 08:21:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 208242 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp248397dyb; Thu, 29 Feb 2024 00:22:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWW7SDYMh9hNpuwfXusXe2yaKd0m3dvyMH7aUbQ7ShHkHcaoSU8Hw6JPzsBGyjgGDdDOSykkFuXTQyFK1c4A3Wx5X+8dg== X-Google-Smtp-Source: AGHT+IGWC/jH5pRTxNd1strVNHTZv6jBrQIMK7HTI2y1VmXPxP0cslM98vQtgkPTzD/11Hura/C6 X-Received: by 2002:ac8:4e86:0:b0:42e:7d88:8ca4 with SMTP id 6-20020ac84e86000000b0042e7d888ca4mr1507247qtp.30.1709194935810; Thu, 29 Feb 2024 00:22:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709194935; cv=pass; d=google.com; s=arc-20160816; b=BXkm5nWmsCZ7Uq9H9MkypjZmvOj/Ta5ZD2LsrYnYp5ggCMvMegNQMu6E5FxXGevu0z Q/APDGHQvuWkRgAP/XPM4JXdWRZn3qOOdyS+0XSVDJcuJS5rm/qNxhB3JO8jM9uwzE4m Mjp/nm0WIp5fH15LnH5wwV/WFVJFlsHBJBNtLfqjTt15f3VTdEgcPlD6if72HsH/Ppst l7PABJE9JnS9HEfUDCrof6xr2QMF4RDiJD2KazzS69GDSWlENljptlvXahLS8SOKRGDl ReIqakRsGcVorIJ+tkmST2YC6hd755zFag1C3UTdMWaGfZZNRMnDQ1gpuUGxWvMEjG/R XKXA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:message-id:mime-version:subject :cc:to:from:date:dkim-signature:dkim-signature:dkim-signature :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=MJj5wrL4NvrWuwDCKFUPaxwxNp9r8KJDkWDQ8pitxig=; fh=MOt1wu73TArXwdr0NaH7Zl6ZAV8cWdo030UrjuL3Ysg=; b=ltWlb8TE3LFYhAIhc3A8SHMrMqSGAA5HInHHrQVQ/6aDie619WFK5V3wsx0W5R39B2 6AIphd4XUqv6xJcuIf8vZi5KDQpjk4yEL6ZIlH8TPjk+/GJ2/PmxWUsjfEqeqptfSRZu YKRm0cHEqO6xNKr/O8Q/nxz4VEQLLFX2iQIMZg7MuIlpol5/Pxrt2Mr/FW1eQ3YyNSDG qFUlpm/cg3kUh9hX/AABjRwWfpXHCH9Lg95cv6zaK6AUwu1l4FjmN8WsV8tV+6FEInid h06cKqhmRsPZdOInc4822rwkSYfHNjSFzXqzbbAEOMGIs9jqzXHtGfhPKKmBjhsZ9Fav TRJQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=NJyijaCM; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=NJyijaCM; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=CXeDug5j; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id b14-20020ac8754e000000b0042eb23f9699si884702qtr.610.2024.02.29.00.22.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 00:22:15 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=NJyijaCM; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=NJyijaCM; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=CXeDug5j; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 823803858C32 for ; Thu, 29 Feb 2024 08:22:15 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 A743F3858CDA for ; Thu, 29 Feb 2024 08:21:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A743F3858CDA 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 A743F3858CDA 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=1709194875; cv=none; b=sbv4WPcbJcvF2hfhUpPETdgYQ/sMLnw75rgYKOaPB60oL+qkAHaPVC7VSaWhGSM/ib4ix75Tt5RexXM3FkvT5Y+0KVTVAWWHPm553b9ybRTvTxqV82eJvkeTRJtniF6sbQYdVBfqHpcMdeY0SRLfhsE9/y8LYkT1SA2dETgpr9I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709194875; c=relaxed/simple; bh=O4XcKn/p9LTeRpd3K+e9BUFh6I74siZufoyxGNtCqEQ=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version:Message-Id; b=QSdX/mXrIk+Gch4K63jZQNiP7Cmz/MMofnYMQiya+7kE/Nifl70B8EuzomLg21CC3a07h/TmnBAJYymw3m/I0QTqFY5cUn1rIYNzR9aKwifMMykSpqyone70/Pf7Ek0RyfM7QG0KY1Bn3hsik8+/d4MEC7ZGgKzJzAEbzp2FTl0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 29C0C2238D; Thu, 29 Feb 2024 08:21:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709194871; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=MJj5wrL4NvrWuwDCKFUPaxwxNp9r8KJDkWDQ8pitxig=; b=NJyijaCMyYogNAZgiUUh1SWkOul10i2CDJAQq11GtyztE53KXCigK7ZFBQlg1m5hj7UdnQ 0L+h1BuhluW+C8nRZgS+Xl3b4WohTyFV3cERM6y9BLIcFSUsX/RLtR9Pg+EkTgwwnlwg9u 1OISQnP1rRgiLzAqvawfikc9XH9H32I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709194871; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=MJj5wrL4NvrWuwDCKFUPaxwxNp9r8KJDkWDQ8pitxig=; b=CXeDug5jC0ZYWpVUFiYcLtYS+hIkazi9msjVvBwMS3U58Fd3/TchW5kQTLaAAdMRa+F4qy yl02Nodo8WcfudBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709194871; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=MJj5wrL4NvrWuwDCKFUPaxwxNp9r8KJDkWDQ8pitxig=; b=NJyijaCMyYogNAZgiUUh1SWkOul10i2CDJAQq11GtyztE53KXCigK7ZFBQlg1m5hj7UdnQ 0L+h1BuhluW+C8nRZgS+Xl3b4WohTyFV3cERM6y9BLIcFSUsX/RLtR9Pg+EkTgwwnlwg9u 1OISQnP1rRgiLzAqvawfikc9XH9H32I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709194871; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=MJj5wrL4NvrWuwDCKFUPaxwxNp9r8KJDkWDQ8pitxig=; b=CXeDug5jC0ZYWpVUFiYcLtYS+hIkazi9msjVvBwMS3U58Fd3/TchW5kQTLaAAdMRa+F4qy yl02Nodo8WcfudBA== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 024291329E; Thu, 29 Feb 2024 08:21:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id wmODOnY+4GX8VAAAn2gu4w (envelope-from ); Thu, 29 Feb 2024 08:21:10 +0000 Date: Thu, 29 Feb 2024 09:21:02 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: richard.sandiford@arm.com, Jakub Jelinek Subject: [PATCH] tree-optimization/114151 - handle POLY_INT_CST in get_range_pos_neg MIME-Version: 1.0 Message-Id: <20240229082111.024291329E@imap2.dmz-prg2.suse.org> Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -1.30 X-Spamd-Result: default: False [-1.30 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.00)[25.23%] X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792220788864865687 X-GMAIL-MSGID: 1792220788864865687 The following switches the logic in chrec_fold_multiply to get_range_pos_neg since handling POLY_INT_CST possibly mixed with non-poly ranges will make the open-coding awkward and while not a perfect fit it should work. In turn the following makes get_range_pos_neg aware of POLY_INT_CSTs. I couldn't make it work with poly_wide_int since the compares always fail to build but poly_widest_int works fine and it should be semantically the same. I've also changed get_range_pos_neg to use get_range_query (cfun), problematical passes shouldn't have a range query activated so it shouldn't make a difference there. This doesn't make a difference for the PR but not considering POLY_INT_CSTs was a mistake. Bootstrap and regtest running on x86_64-unknown-linux-gnu, OK? Thanks, Richard. PR tree-optimization/114151 * tree.cc (get_range_pos_neg): Handle POLY_INT_CST, use the passes range-query if available. * tree-chre.cc (chrec_fold_multiply): Use get_range_pos_neg to see if both operands have the same range. --- gcc/tree-chrec.cc | 14 ++------------ gcc/tree.cc | 12 +++++++----- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/gcc/tree-chrec.cc b/gcc/tree-chrec.cc index 2e6c7356d3b..450d018ce6f 100644 --- a/gcc/tree-chrec.cc +++ b/gcc/tree-chrec.cc @@ -442,18 +442,8 @@ chrec_fold_multiply (tree type, if (!ANY_INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_WRAPS (type) || integer_zerop (CHREC_LEFT (op0)) - || (TREE_CODE (CHREC_LEFT (op0)) == INTEGER_CST - && TREE_CODE (CHREC_RIGHT (op0)) == INTEGER_CST - && (tree_int_cst_sgn (CHREC_LEFT (op0)) - == tree_int_cst_sgn (CHREC_RIGHT (op0)))) - || (get_range_query (cfun)->range_of_expr (rl, CHREC_LEFT (op0)) - && !rl.undefined_p () - && (rl.nonpositive_p () || rl.nonnegative_p ()) - && get_range_query (cfun)->range_of_expr (rr, - CHREC_RIGHT (op0)) - && !rr.undefined_p () - && ((rl.nonpositive_p () && rr.nonpositive_p ()) - || (rl.nonnegative_p () && rr.nonnegative_p ())))) + || (get_range_pos_neg (CHREC_LEFT (op0)) + | get_range_pos_neg (CHREC_RIGHT (op0))) != 3) { tree left = chrec_fold_multiply (type, CHREC_LEFT (op0), op1); tree right = chrec_fold_multiply (type, CHREC_RIGHT (op0), op1); diff --git a/gcc/tree.cc b/gcc/tree.cc index f801712c9dd..fcc914f0f7a 100644 --- a/gcc/tree.cc +++ b/gcc/tree.cc @@ -14408,13 +14408,15 @@ get_range_pos_neg (tree arg) int prec = TYPE_PRECISION (TREE_TYPE (arg)); int cnt = 0; - if (TREE_CODE (arg) == INTEGER_CST) + if (poly_int_tree_p (arg)) { - wide_int w = wi::sext (wi::to_wide (arg), prec); - if (wi::neg_p (w)) + poly_widest_int w = wi::sext (wi::to_poly_widest (arg), prec); + if (known_lt (w, 0)) return 2; - else + else if (known_ge (w, 0)) return 1; + else + return 3; } while (CONVERT_EXPR_P (arg) && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (arg, 0))) @@ -14434,7 +14436,7 @@ get_range_pos_neg (tree arg) if (TREE_CODE (arg) != SSA_NAME) return 3; value_range r; - while (!get_global_range_query ()->range_of_expr (r, arg) + while (!get_range_query (cfun)->range_of_expr (r, arg) || r.undefined_p () || r.varying_p ()) { gimple *g = SSA_NAME_DEF_STMT (arg);