From patchwork Fri Apr 5 13:12:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 88102 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E5E933844744 for ; Fri, 5 Apr 2024 13:13:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id 081FF3858431 for ; Fri, 5 Apr 2024 13:12:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 081FF3858431 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 081FF3858431 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712322778; cv=none; b=MD5MCgTS2EYm/0KfDcnwVLcl5APX2aMdg2nAppCc5QGzUVeLHX+KkwKUOvnCuBpsByQI1Uc7PO1mS4kks+pzdthha60HEfBtf/SJ3Go59mcTlRU3+qvMUilel1erygFZhBiAJYiqKhGtiunR7Slqyvoviw23VVkJSNiQCJa6ZfU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712322778; c=relaxed/simple; bh=lTByuxMfXbZ7NdHg/NEv8h+Kj3af97TeBCQLrZcfqbg=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version:Message-Id; b=RAwYhUNihPb23cOBDl1tjPGJHHR35zUdDkb5lJEZcPgfiQxQlOmlLniS2R2NVz0uOpKdtFUG2Eo3YCj83un4qCHRI6Of6xv7I2f/xugwKb9mQVyfeedjaDOR7bb7TTtPGk3L+11LrdgbpCncqHGWcTzwBFT1RtM9dIPZjW/T/Ic= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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-out2.suse.de (Postfix) with ESMTPS id BB4D01F7A0; Fri, 5 Apr 2024 13:12:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712322769; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=eySkaaU+UxycnLpE7sIjpSyWFaVzW7M5KaBaRW8zQiw=; b=ik3HhIA8LMRMFHjdPABgMuz7yhJrfwhuhTxpvLSkjNB/ss91P55cwyJCnuOqnVixKcGh1j z8nrQ7G500CJeJwRxXLq3bTQ+ZL6g4BNCwGka57wr0tFbSlHoN2sMJQfco8lanMSf+ihaD nsEf9Mk9XgAjp+SgxrF2rV+5KvFCu2A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712322769; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=eySkaaU+UxycnLpE7sIjpSyWFaVzW7M5KaBaRW8zQiw=; b=6tNt5laj88sMw2+U5dTDZ7dazBTmKS76nfP8H0froUVe5CZP1M1i7U9IbTZ4NsvUdoEh3S hpFOBct8MGonBQDw== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ik3HhIA8; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=6tNt5laj DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712322769; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=eySkaaU+UxycnLpE7sIjpSyWFaVzW7M5KaBaRW8zQiw=; b=ik3HhIA8LMRMFHjdPABgMuz7yhJrfwhuhTxpvLSkjNB/ss91P55cwyJCnuOqnVixKcGh1j z8nrQ7G500CJeJwRxXLq3bTQ+ZL6g4BNCwGka57wr0tFbSlHoN2sMJQfco8lanMSf+ihaD nsEf9Mk9XgAjp+SgxrF2rV+5KvFCu2A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712322769; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=eySkaaU+UxycnLpE7sIjpSyWFaVzW7M5KaBaRW8zQiw=; b=6tNt5laj88sMw2+U5dTDZ7dazBTmKS76nfP8H0froUVe5CZP1M1i7U9IbTZ4NsvUdoEh3S hpFOBct8MGonBQDw== 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 8D3A8139F1; Fri, 5 Apr 2024 13:12:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id qjzPINH4D2ZXKAAAn2gu4w (envelope-from ); Fri, 05 Apr 2024 13:12:49 +0000 Date: Fri, 5 Apr 2024 15:12:49 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: Jan Hubicka Subject: [PATCH 1/3] Pass reliable down to infer_loop_bounds_from_array MIME-Version: 1.0 Message-Id: <20240405131249.8D3A8139F1@imap2.dmz-prg2.suse.org> X-Spam-Level: X-Spamd-Result: default: False [-1.52 / 50.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; BAYES_HAM(-0.01)[46.19%]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; MISSING_XM_UA(0.00)[]; RCVD_TLS_ALL(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap2.dmz-prg2.suse.org:helo,imap2.dmz-prg2.suse.org:rdns,suse.de:dkim]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Rspamd-Queue-Id: BB4D01F7A0 X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Score: -1.52 X-Spam-Status: No, score=-11.5 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 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+patchwork=sourceware.org@gcc.gnu.org The following passes down whether a stmt is always executed from infer_loop_bounds_from_undefined to infer_loop_bounds_from_array. The parameters were already documented. The patch doesn't remove possibly redundant checks from idx_infer_loop_bounds yet. Boostrapped on x86_64-unknown-linux-gnu, testing in progress. * tree-ssa-loop-niter.cc (ilb_data::reliable): New. (idx_infer_loop_bounds): Initialize upper from reliable. (infer_loop_bounds_from_ref): Get and pass through reliable flag. (infer_loop_bounds_from_array): Likewise. (infer_loop_bounds_from_undefined): Pass reliable flag to infer_loop_bounds_from_array. --- gcc/tree-ssa-loop-niter.cc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc index c6d010f6d89..0a77c1bb544 100644 --- a/gcc/tree-ssa-loop-niter.cc +++ b/gcc/tree-ssa-loop-niter.cc @@ -4123,6 +4123,7 @@ struct ilb_data { class loop *loop; gimple *stmt; + bool reliable; }; static bool @@ -4131,7 +4132,7 @@ idx_infer_loop_bounds (tree base, tree *idx, void *dta) struct ilb_data *data = (struct ilb_data *) dta; tree ev, init, step; tree low, high, type, next; - bool sign, upper = true, has_flexible_size = false; + bool sign, upper = data->reliable, has_flexible_size = false; class loop *loop = data->loop; if (TREE_CODE (base) != ARRAY_REF) @@ -4224,12 +4225,14 @@ idx_infer_loop_bounds (tree base, tree *idx, void *dta) STMT is guaranteed to be executed in every iteration of LOOP.*/ static void -infer_loop_bounds_from_ref (class loop *loop, gimple *stmt, tree ref) +infer_loop_bounds_from_ref (class loop *loop, gimple *stmt, tree ref, + bool reliable) { struct ilb_data data; data.loop = loop; data.stmt = stmt; + data.reliable = reliable; for_each_index (&ref, idx_infer_loop_bounds, &data); } @@ -4238,7 +4241,7 @@ infer_loop_bounds_from_ref (class loop *loop, gimple *stmt, tree ref) executed in every iteration of LOOP. */ static void -infer_loop_bounds_from_array (class loop *loop, gimple *stmt) +infer_loop_bounds_from_array (class loop *loop, gimple *stmt, bool reliable) { if (is_gimple_assign (stmt)) { @@ -4248,10 +4251,10 @@ infer_loop_bounds_from_array (class loop *loop, gimple *stmt) /* For each memory access, analyze its access function and record a bound on the loop iteration domain. */ if (REFERENCE_CLASS_P (op0)) - infer_loop_bounds_from_ref (loop, stmt, op0); + infer_loop_bounds_from_ref (loop, stmt, op0, reliable); if (REFERENCE_CLASS_P (op1)) - infer_loop_bounds_from_ref (loop, stmt, op1); + infer_loop_bounds_from_ref (loop, stmt, op1, reliable); } else if (is_gimple_call (stmt)) { @@ -4260,13 +4263,13 @@ infer_loop_bounds_from_array (class loop *loop, gimple *stmt) lhs = gimple_call_lhs (stmt); if (lhs && REFERENCE_CLASS_P (lhs)) - infer_loop_bounds_from_ref (loop, stmt, lhs); + infer_loop_bounds_from_ref (loop, stmt, lhs, reliable); for (i = 0; i < n; i++) { arg = gimple_call_arg (stmt, i); if (REFERENCE_CLASS_P (arg)) - infer_loop_bounds_from_ref (loop, stmt, arg); + infer_loop_bounds_from_ref (loop, stmt, arg, reliable); } } } @@ -4410,7 +4413,7 @@ infer_loop_bounds_from_undefined (class loop *loop, basic_block *bbs) { gimple *stmt = gsi_stmt (bsi); - infer_loop_bounds_from_array (loop, stmt); + infer_loop_bounds_from_array (loop, stmt, reliable); if (reliable) {