From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id B198D3858D35 for ; Tue, 16 Nov 2021 13:53:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B198D3858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 7921E212C9; Tue, 16 Nov 2021 13:53:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1637070815; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cYy+wBdZdODPolUSj2cNniy9oKXae4kthrx5t1uCo9c=; b=zjLnzkBM04Ol6ptpKUUjkQesKoE8AMgNovy1rPCq/Q16Spmr90Q+/rDxdRdKXrLruKfQwI FaNEUiSzXEnPhf9mGTIXJCWxoJ/pcnSzglDocG3Z8ZPra1vaZ2eC/eKFlwcsvb/luUTdS2 JTtnHQW5B3k1rQ25ya/WAsnEjGtLnHA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1637070815; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cYy+wBdZdODPolUSj2cNniy9oKXae4kthrx5t1uCo9c=; b=jENsTZnxSFVe47gbMYqZvQ7ENGISuuPVwa2OLTFC5zHg0fXD9XyxqK6qLG5Cle4tWOocdE KpCMCJUkDytVI6Dg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 625D013C22; Tue, 16 Nov 2021 13:53:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +a73Ft+3k2FsCQAAMHmgww (envelope-from ); Tue, 16 Nov 2021 13:53:35 +0000 Message-ID: <0ce410d3-148d-b640-4da6-a443795d4b16@suse.cz> Date: Tue, 16 Nov 2021 14:53:35 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.0 Subject: Re: [PATCH] Loop unswitching: support gswitch statements. Content-Language: en-US To: Richard Biener Cc: Andrew MacLeod , GCC Patches References: <7791e850-f74d-8c1c-f67c-e02f3f6e007d@redhat.com> <5c6c91d4-ed8b-8d98-2cd9-bafc84e6f2a4@suse.cz> <8da24825-19ec-56a6-a68c-5c37c7acc3e1@redhat.com> <59763e1a-8432-5f23-c399-a9b4dd6c6dff@suse.cz> From: =?UTF-8?Q?Martin_Li=c5=a1ka?= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Tue, 16 Nov 2021 13:53:38 -0000 On 11/11/21 08:15, Richard Biener wrote: > If you look at simplify_using_entry_checks then this is really really simple, > so I'd try to abstract this, recording sth like a unswitch_predicate where > we store the condition we unswitch on plus maybe cache the constant > range of a VAR cmp CST variable condition on the true/false edge. We > can then try to simplify each gcond/gswitch based on such an unswitch_predicate > (when we ever scan the loop once to discover all opportunities we'd have a > set of unswitch_predicates to try simplifying against). As said the integer > range thing would be an improvement over the current state so even that > can be done as followup but I guess for gswitch support that's going to be > the thing to use. I started working on the unswitch_predicate where I recond also true/false-edge irange of an expression we unswitch on. I noticed one significant problem, let's consider: for (int i = 0; i < size; i++) { double tmp; if (order == 1) tmp = -8 * a[i]; else { if (order == 2) tmp = -4 * b[i]; else tmp = a[i]; } r[i] = 3.4f * tmp + d[i]; } We can end up with first unswitching candidate being 'if (order == 2)' (I have a real benchmark where it happens). So I collect ranges and they are [2,2] for true edge and [-INF, 0], [3, INF] (because we came to the condition through order != 1 cond). Then the loop is cloned and we have if (order == 2) loop_version_1 else loop_version_2 but in loop_version_2 we wrongly fold 'if (order == 1)' to false because it's reflected in the range. So the question is, can one iterate get_loop_body stmts in some dominator order? Thanks, Martin