From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by sourceware.org (Postfix) with ESMTPS id E38503858D33 for ; Tue, 21 Nov 2023 11:05:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E38503858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ispras.ru ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E38503858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=83.149.199.84 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700564740; cv=none; b=OhBj4bSyR1bCs6TtpFFWh/ZmqR38qypD7wgd8gd+oCK/M24RIMGi9Xbuv4uGZoopvsWTqSMeJrLGbCKFEhUu5aLC1rC5qHcqcVsG1Xq6fIEfQL2aUYVmisfe5DcKkNIvuLnz3xf0Kiwtwr+RryNUczV5SBJTPmH674GoIsSGSKk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700564740; c=relaxed/simple; bh=UePlcVkDYT0Wa1YtGG6YVrfjl8leUmuaKynWe6tOuSo=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=YSjdRbppISty2BzR+NBPgLCFeDQKD5FXOQ1vRwmYLpcGzETQja7J/7sONwBHnnCjxC3wPbWYDRE+WoO7i1Mw1p+xcooumr6DhJgTpzKUNOHx3I3Hz0YDpcn9hwt7WzoLrGsCV5PQJhq5U7wjqe0neSx1mYMhns6Pmxr4Ds1M81U= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.10.3.121] (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTPS id 9560940737BC; Tue, 21 Nov 2023 11:05:37 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 9560940737BC Date: Tue, 21 Nov 2023 14:05:37 +0300 (MSK) From: Alexander Monakov To: Maxim Kuvyrkov cc: GCC Patches , Bernd Schmidt , Vladimir Makarov , Jeff Law Subject: Re: [PATCH 1/1] sched-deps.cc (find_modifiable_mems): Avoid exponential behavior In-Reply-To: <478E2CE6-61BA-49E2-BD70-112A3653DFE0@linaro.org> Message-ID: References: <20231120120649.672893-1-maxim.kuvyrkov@linaro.org> <20231120120649.672893-2-maxim.kuvyrkov@linaro.org> <8587bddb-e348-a637-2fe2-8318bb09b3be@ispras.ru> <478E2CE6-61BA-49E2-BD70-112A3653DFE0@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,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 Tue, 21 Nov 2023, Maxim Kuvyrkov wrote: > >>>> This patch avoids sched-deps.cc:find_inc() creating exponential number > >>>> of dependencies, which become memory and compilation time hogs. > >>>> Consider example (simplified from PR96388) ... > >>>> === > >>>> sp=sp-4 // sp_insnA > >>>> mem_insnA1[sp+A1] > >>>> ... > >>>> mem_insnAN[sp+AN] > >>>> sp=sp-4 // sp_insnB > >>>> mem_insnB1[sp+B1] > >>>> ... > >>>> mem_insnBM[sp+BM] > >>>> === > >>>> ... in this example find_modifiable_mems() will arrange for mem_insnA* > >>>> to be able to pass sp_insnA, and, while doing this, will create > >>>> dependencies between all mem_insnA*s and sp_insnB -- because sp_insnB > >>>> is a consumer of sp_insnA. After this sp_insnB will have N new > >>>> backward dependencies. > >>>> Then find_modifiable_mems() gets to mem_insnB*s and starts to create > >>>> N new dependencies for _every_ mem_insnB*. This gets us N*M new > >>>> dependencies. > >> > >> [For avoidance of doubt, below discussion is about the general implementation > >> of find_modifiable_mems() and not about the patch.] > > > > I was saying the commit message is hard to read (unless it's just me). > > > >>> It's a bit hard to read this without knowing which value of 'backwards' > >>> is assumed. > > Oh, sorry, I misunderstood your comment. > > In the above example I want to describe outcome that current code generates, > without going into details about exactly how it does it. I'm not sure how to > make it more readable, and would appreciate suggestions. I think it would be easier to follow if you could fix a specific value of 'backwards' up front, and then ensure all following statements are consistent with that, like I did in my explanation. Please feel free to pick up my text into the commit message, if it helps. > >>> Say 'backwards' is true and we are inspecting producer sp_insnB of mem_insnB1. > >>> This is a true dependency. We know we can break it by adjusting B1 by -4, but > >>> we need to be careful not to move such modified mem_insnB1 above sp_insnA, so > >>> we need to iterate over *incoming true dependencies* of sp_insnB and add them. > >>> > >>> But the code seems to be iterating over *all incoming dependencies*, so it > >>> will e.g. take anti-dependency mem_insnA1 -> sp_insnB and create a true > >>> dependency mem_insnA1 -> mem_insnB1'. This seems utterly inefficient, if my > >>> understanding is correct. > >> > >> Yeap, your understanding is correct. However, this is what > >> find_modifiable_mems() has to do to avoid complicated analysis of second-level > >> dependencies. > > > > What is the reason it cannot simply skip anti-dependencies in the > > 'if (backwards)' loop, and true dependencies in the 'else' loop? > > I /think/, this should be possible. However, rather than improving current > implementation my preference is to rework it by integrating with the main > dependency analysis. This should provide both faster and more precise > dependency analysis, which would generate breakable addr/mem dependencies. I see, thank you. Alexander