aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Scalar/LoopSink.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-03-19[Transforms] Use *Set::insert_range (NFC) (#132056)Kazu Hirata1-1/+1
DenseSet, SmallPtrSet, SmallSet, SetVector, and StringSet recently gained C++23-style insert_range. This patch replaces: Dest.insert(Src.begin(), Src.end()); with: Dest.insert_range(Src); This patch does not touch custom begin like succ_begin for now.
2025-01-24[NFC][DebugInfo] Use iterator moveBefore at many call-sites (#123583)Jeremy Morse1-2/+2
As part of the "RemoveDIs" project, BasicBlock::iterator now carries a debug-info bit that's needed when getFirstNonPHI and similar feed into instruction insertion positions. Call-sites where that's necessary were updated a year ago; but to ensure some type safety however, we'd like to have all calls to moveBefore use iterators. This patch adds a (guaranteed dereferenceable) iterator-taking moveBefore, and changes a bunch of call-sites where it's obviously safe to change to use it by just calling getIterator() on an instruction pointer. A follow-up patch will contain less-obviously-safe changes. We'll eventually deprecate and remove the instruction-pointer insertBefore, but not before adding concise documentation of what considerations are needed (very few).
2024-07-30[LoopSink] Exit loop finding BBs to sink into early when possible (NFC) ↵Teresa Johnson1-0/+16
(#101115) As noted in the comments, findBBsToSinkInto is O(UseBBs.size() * ColdLoopBBs.size()) A very large function with a huge loop was incurring a high compile time in this code. The size of the ColdLoopBBs set was over 14K. There is a limit on the size of the UseBBs set, but not the ColdLoopBBs (and adding a limit for the latter actually slowed down some later passes). This change exits the loop early once we detect that there is no further refinement possible for the BBsToSinkInto set. This is possible because the ColdLoopBBs set is sorted in ascending magnitude of frequency. This cut down the LoopSinkPass time by around 33% (78s to just over 50s).
2023-11-20[NewPM] Remove LoopSinkLegacy Pass (#72811)Aiden Grossman1-57/+0
This pass isn't used anywhere and thus has no test coverage. For these reasons, remove it.
2023-10-05Use BlockFrequency type in more places (NFC) (#68266)Matthias Braun1-1/+1
The `BlockFrequency` class abstracts `uint64_t` frequency values. Use it more consistently in various APIs and disable implicit conversion to make usage more consistent and explicit. - Use `BlockFrequency Freq` parameter for `setBlockFreq`, `getProfileCountFromFreq` and `setBlockFreqAndScale` functions. - Return `BlockFrequency` in `getEntryFreq()` functions. - While on it change some `const BlockFrequency& Freq` parameters to plain `BlockFreqency Freq`. - Mark `BlockFrequency(uint64_t)` constructor as explicit. - Add missing `BlockFrequency::operator!=`. - Remove `uint64_t BlockFreqency::getMaxFrequency()`. - Add `BlockFrequency BlockFrequency::max()` function.
2023-08-16[LoopSink] Don't sort BBs if there is only 1 of them (NFC)Danila Kutenin1-3/+5
This was trigerred by the debug check when comp(a, a) was called. On line 216 it's checked that LoopBlockNumber should contain all if there are more than 1. NFC for end users Differential Revision: https://reviews.llvm.org/D157954
2023-06-23[LoopSink] Allow sinking to PHI-use (2nd attempt)Wenlei He1-6/+22
This change allows sinking defs from loop preheader with PHI-use into loop body. Loop sink can now see through PHI-use and select incoming blocks of value being used as candidate sink destination. It makes loop sink more effective so more LICM can be undone if proven unprofitable with profile info. It addresses the motivating case in D87551, without resorting to profile guided LICM which breaks canonicalization. This is the 2nd attempt after D152772.
2023-06-21Revert "[LoopSink] Allow sinking to PHI-use"Alexander Kornienko1-18/+4
This reverts commit 54711a6a5872d5f97da4c0a1bd7e58d0546ca701. The commit is causing a clang crash: https://reviews.llvm.org/D152772#4437254
2023-06-13[LoopSink] Allow sinking to PHI-useWenlei He1-4/+18
This change allows sinking defs from loop preheader with PHI-use into loop body. Loop sink can now see through PHI-use and select incoming blocks of value being used as candidate sink destination. It makes loop sink more effective so more LICM can be undone if proven unprofitable with profile info. It addresses the motivating case in D87551, without resorting to profile guided LICM which breaks canonicalization. Differential Revision: https://reviews.llvm.org/D152772
2023-03-24[LICM] Require MSSA in SinkAndHoistLICMFlags (NFC)Nikita Popov1-1/+1
Nowadays MSSA is required for LICM/LoopSink, so drop the checks for whether its available or not.
2023-02-28[LoopSink] Don't fetch analyses without profile data (NFCI)Nikita Popov1-5/+5
The loop sink pass only does something if the function has profile data. Move the check for that before analyses are fetched, to avoid computing things like BFI or MSSA unnecessarily.
2023-01-05Move from llvm::makeArrayRef to ArrayRef deduction guides - llvm/ partserge-sans-paille1-1/+1
Use deduction guides instead of helper functions. The only non-automatic changes have been: 1. ArrayRef(some_uint8_pointer, 0) needs to be changed into ArrayRef(some_uint8_pointer, (size_t)0) to avoid an ambiguous call with ArrayRef((uint8_t*), (uint8_t*)) 2. CVSymbol sym(makeArrayRef(symStorage)); needed to be rewritten as CVSymbol sym{ArrayRef(symStorage)}; otherwise the compiler is confused and thinks we have a (bad) function prototype. There was a few similar situation across the codebase. 3. ADL doesn't seem to work the same for deduction-guides and functions, so at some point the llvm namespace must be explicitly stated. 4. The "reference mode" of makeArrayRef(ArrayRef<T> &) that acts as no-op is not supported (a constructor cannot achieve that). Per reviewers' comment, some useless makeArrayRef have been removed in the process. This is a follow-up to https://reviews.llvm.org/D140896 that introduced the deduction guides. Differential Revision: https://reviews.llvm.org/D140955
2022-10-07Recommit "[SCEV] Support clearing Block/LoopDispositions for a single value."Florian Hahn1-3/+4
This reverts commit 92f698f01fa0bb8967233a6391ada2d51849fa68. The updated version of the patch includes handling for non-SCEVable types. A test case has been added in ec86e9a99bca802.
2022-10-07Revert "[SCEV] Support clearing Block/LoopDispositions for a single value."Florian Hahn1-4/+3
This reverts commit 9e931439ddb9b6b8f655940b9d8ed6db50c2a7e2. This commit causes a crash when TSan, e.g. with https://lab.llvm.org/buildbot/#/builders/70/builds/28309/steps/10/logs/stdio Reverting while I extract a reproducer and submit a fix.
2022-10-07[SCEV] Support clearing Block/LoopDispositions for a single value.Florian Hahn1-3/+4
Extend forgetBlockAndLoopDisposition to allow clearing information for a single value. This can be useful when only a single value is changed, e.g. because the instruction is moved. We also need to clear the cached values for all SCEV users, because they may depend on the starting value's disposition. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D134614
2022-09-19[SCEV][NFC] Remove unused parameter from forgetLoopDispositionsMax Kazantsev1-1/+1
Let's be honest about it, we don't drop loop dispositions for particular loops. Remove the parameter that misleadingly makes it apparent that we do.
2022-08-07[Transforms] Fix comment typos (NFC)Kazu Hirata1-2/+2
2022-04-08[LICM] Pass MemorySSAUpdater by referene (NFC)Nikita Popov1-1/+1
Make it clearer that this is a required dependency.
2022-04-08[LoopSink] Require MemorySSANikita Popov1-64/+18
This makes MemorySSA in LoopSink required, and removes the AST-based implementation, as well as the related support code in LICM. Differential Revision: https://reviews.llvm.org/D123288
2022-04-07[LoopSink] Use MemorySSA with legacy pass managerNikita Popov1-1/+1
LoopSink with the legacy pass manager still uses AST, because we can't compute MemorySSA conditionally. I think now that the legacy pass manager will be removed soon(TM) we don't need to care about compile-time impact here anymore. Additionally, since MemorySSA is no longer eagerly optimized, the impact is actually not that high anymore (~0.2% geomean regression on CTMark). This just makes legacy PM and new PM behavior line up -- as a followup I'll drop these options entirely and make MemorySSA use mandatory. Differential Revision: https://reviews.llvm.org/D123216
2022-03-20[Transform] Apply clang-tidy fixes for readability-redundant-smartptr-get (NFC)Kazu Hirata1-2/+2
2022-03-06[LoopSink] Do not try to sink phi nodes.Florian Hahn1-0/+2
Skip phi nodes in the preheader. They may not be considered loop invariant by the assertion below. Reviewed By: reames Differential Revision: https://reviews.llvm.org/D121010
2022-03-03Cleanup includes: Transform/Scalarserge-sans-paille1-6/+0
Estimated impact on preprocessor output line: before: 1062981579 after: 1062494547 Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D120817
2022-03-01Cleanup includes: TransformsUtilsserge-sans-paille1-0/+1
Estimation on the impact on preprocessor output: before: 1065307662 after: 1064800684 Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D120741
2021-11-02[Transforms] Use make_early_inc_range (NFC)Kazu Hirata1-5/+4
2021-02-28[llvm] Use set_is_subset (NFC)Kazu Hirata1-5/+4
2021-01-29[llvm] Use isa instead of dyn_cast (NFC)Kazu Hirata1-1/+1
2021-01-15Set option default for enabling memory ssa for new pass manager loop sink ↵Jamie Schmeiser1-1/+1
pass to true. Summary: Set the default for the option enabling memory ssa use in the loop sink pass to true for the new pass manager. Author: Jamie Schmeiser <schmeise@ca.ibm.com> Reviewed By: asbirlea (Alina Sbirlea) Differential Revision: https://reviews.llvm.org/D92486
2020-12-27[Transforms] Use llvm::append_range (NFC)Kazu Hirata1-2/+1
2020-11-20Reland: Expand existing loopsink testing to also test loopsinking using new ↵Jamie Schmeiser1-25/+120
pass manager and fix LICM bug. Summary: Expand existing loopsink testing to also test loopsinking using new pass manager. Enable memoryssa for loopsink with new pass manager. This combination exposed a bug that was previously fixed for loopsink without memoryssa. When sinking an instruction into a loop, the source block may not be part of the loop but still needs to be checked for pointer invalidation. This is the fix for bugzilla #39695 (PR 54659) expanded to also work with memoryssa. Respond to review comments. Enable Memory SSA in legacy Loop Sink pass under EnableMSSALoopDependency option control. Update tests accordingly. Respond to review comments. Add options controlling whether memoryssa is used for loop sink, defaulting to off. Expand testing based on these options. Respond to review comments. Properly indicated preserved analyses. This relanding addresses a compile-time performance problem by moving test for profile data earlier to avoid unnecessary computations. Author: Jamie Schmeiser <schmeise@ca.ibm.com> Reviewed By: asbirlea (Alina Sbirlea) Differential Revision: https://reviews.llvm.org/D90249
2020-11-18Revert "Revert "Revert "Expand existing loopsink testing to also test ↵Jamie Schmeiser1-108/+21
loopsinking using new pass manager and fix LICM bug.""" This reverts commit e29292969b92aa15afba734d4f6863fc405f087c. This apparently causes a regression in compile time (ie, it slows down).
2020-11-18Revert "Revert "Expand existing loopsink testing to also test loopsinking ↵Jamie Schmeiser1-21/+108
using new pass manager and fix LICM bug."" This reverts commit 562addba652e8bdabe49f9123fd92c21b7a0d640. Reverted change too quickly, the failing test cases passed on the next build. So reverting revert (to include the changes).
2020-11-18Revert "Expand existing loopsink testing to also test loopsinking using new ↵Jamie Schmeiser1-108/+21
pass manager and fix LICM bug." This reverts commit d4ba28bddc89a14885218b9eaa4fbf6654c2a5bd.
2020-11-18Expand existing loopsink testing to also test loopsinking using new pass ↵Jamie Schmeiser1-21/+108
manager and fix LICM bug. Summary: Expand existing loopsink testing to also test loopsinking using new pass manager. Enable memoryssa for loopsink with new pass manager. This combination exposed a bug that was previously fixed for loopsink without memoryssa. When sinking an instruction into a loop, the source block may not be part of the loop but still needs to be checked for pointer invalidation. This is the fix for bugzilla #39695 (PR 54659) expanded to also work with memoryssa. Respond to review comments. Enable Memory SSA in legacy Loop Sink pass under EnableMSSALoopDependency option control. Update tests accordingly. Respond to review comments. Add options controlling whether memoryssa is used for loop sink, defaulting to off. Expand testing based on these options. Respond to review comments. Properly indicated preserved analyses. Author: Jamie Schmeiser <schmeise@ca.ibm.com> Reviewed By: asbirlea (Alina Sbirlea) Differential Revision: https://reviews.llvm.org/D90249
2019-11-13Sink all InitializePasses.h includesReid Kleckner1-1/+2
This file lists every pass in LLVM, and is included by Pass.h, which is very popular. Every time we add, remove, or rename a pass in LLVM, it caused lots of recompilation. I found this fact by looking at this table, which is sorted by the number of times a file was changed over the last 100,000 git commits multiplied by the number of object files that depend on it in the current checkout: recompiles touches affected_files header 342380 95 3604 llvm/include/llvm/ADT/STLExtras.h 314730 234 1345 llvm/include/llvm/InitializePasses.h 307036 118 2602 llvm/include/llvm/ADT/APInt.h 213049 59 3611 llvm/include/llvm/Support/MathExtras.h 170422 47 3626 llvm/include/llvm/Support/Compiler.h 162225 45 3605 llvm/include/llvm/ADT/Optional.h 158319 63 2513 llvm/include/llvm/ADT/Triple.h 140322 39 3598 llvm/include/llvm/ADT/StringRef.h 137647 59 2333 llvm/include/llvm/Support/Error.h 131619 73 1803 llvm/include/llvm/Support/FileSystem.h Before this change, touching InitializePasses.h would cause 1345 files to recompile. After this change, touching it only causes 550 compiles in an incremental rebuild. Reviewers: bkramer, asbirlea, bollu, jdoerfert Differential Revision: https://reviews.llvm.org/D70211
2019-08-01[IR] Value: add replaceUsesWithIf() utilityRoman Lebedev1-6/+3
Summary: While there is always a `Value::replaceAllUsesWith()`, sometimes the replacement needs to be conditional. I have only cleaned a few cases where `replaceUsesWithIf()` could be used, to both add test coverage, and show that it is actually useful. Reviewers: jdoerfert, spatel, RKSimon, craig.topper Reviewed By: jdoerfert Subscribers: dschuff, sbc100, jgravelle-google, hiraditya, aheejin, george.burgess.iv, asbirlea, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65528 llvm-svn: 367548
2019-04-23Use llvm::stable_sortFangrui Song1-4/+3
While touching the code, simplify if feasible. llvm-svn: 358996
2019-04-19[LICM & MemorySSA] Make limit flags pass tuning options.Alina Sbirlea1-1/+1
Summary: Make the flags in LICM + MemorySSA tuning options in the old and new pass managers. Subscribers: mehdi_amini, jlebar, Prazek, george.burgess.iv, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60490 llvm-svn: 358772
2019-02-11[LICM&MSSA] Limit store hoisting.Alina Sbirlea1-1/+1
Summary: If there is no clobbering access for a store inside the loop, that store can only be hoisted if there are no interfearing loads. A more general verification introduced here: there are no loads that are not optimized to an access outside the loop. Addresses PR40586. Reviewers: george.burgess.iv Subscribers: sanjoy, jlebar, Prazek, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D57967 llvm-svn: 353734
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2019-01-10Use MemorySSA in LICM to do sinking and hoisting.Alina Sbirlea1-1/+1
Summary: Step 2 in using MemorySSA in LICM: Use MemorySSA in LICM to do sinking and hoisting, all under "EnableMSSALoopDependency" flag. Promotion is disabled. Enable flag in LICM sink/hoist tests to test correctness of this change. Moved one test which relied on promotion, in order to test all sinking tests. Reviewers: sanjoy, davide, gberry, george.burgess.iv Subscribers: llvm-commits, Prazek Differential Revision: https://reviews.llvm.org/D40375 llvm-svn: 350879
2018-11-20[LoopSink] Add preheader to alias setGuozhi Wei1-0/+1
This patch fixes PR39695. The original LoopSink only considers memory alias in loop body. But PR39695 shows that instructions following sink candidate in preheader should also be checked. This is a conservative patch, it simply adds whole preheader block to alias set. It may lose some optimization opportunity, but I think that is very rare because: 1 in the most common case st/ld to the same address, the load should already be optimized away. 2 usually preheader is not very large. Differential Revision: https://reviews.llvm.org/D54659 llvm-svn: 347325
2018-11-07[LoopSink] Do not sink instructions into non-cold blocksMandeep Singh Grang1-0/+7
Summary: This fixes PR39570. Reviewers: danielcdh, rnk, bkramer Reviewed By: rnk Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D54181 llvm-svn: 346337
2018-09-27llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)Fangrui Song1-5/+3
Summary: The convenience wrapper in STLExtras is available since rL342102. Reviewers: dblaikie, javed.absar, JDevlieghere, andreadb Subscribers: MatzeB, sanjoy, arsenm, dschuff, mehdi_amini, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, eraman, aheejin, kbarton, JDevlieghere, javed.absar, gbedwell, jrtc27, mgrang, atanasyan, steven_wu, george.burgess.iv, dexonsmith, kristina, jsji, llvm-commits Differential Revision: https://reviews.llvm.org/D52573 llvm-svn: 343163
2018-08-29LoopSink: Don't sink into blocks without an insertion point (PR38462)Hans Wennborg1-0/+8
In the PR, LoopSink was trying to sink into a catchswitch block, which doesn't have a valid insertion point. Differential Revision: https://reviews.llvm.org/D51307 llvm-svn: 340900
2018-08-02[LICM] Factor out fault legality from canHoistOrSinkInst [NFC]Philip Reames1-1/+1
This method has three callers, each of which wanted distinct handling: 1) Sinking into a loop is moving an instruction known to execute before a loop into the loop. We don't need to worry about introducing a fault at all in this case. 2) Hoisting from a loop into a preheader already duplicated the check in the caller. 3) Sinking from the loop into an exit block was the only true user of the code within the routine. For the moment, this has just been lifted into the caller, but up next is examining the logic more carefully. Whitelisting of loads and calls - while consistent with the previous code - is rather suspicious. Either way, a behavior change is worthy of it's own patch. llvm-svn: 338671
2018-07-06[LoopSink] Make the enforcement of determinism deterministic.Benjamin Kramer1-4/+6
LoopBlockNumber is a DenseMap<BasicBlock*, int>, comparing the result of find() will compare a pair<BasicBlock*, int>. That's of course depending on pointer ordering which varies from run to run. Reverse iteration doesn't find this because we're copying to a vector first. This bug has been there since 2016 but only recently showed up on clang selfhost with FDO and ThinLTO, which is also why I didn't manage to get a reasonable test case for this. Add an assert that would've caught this. llvm-svn: 336439
2018-06-04Move Analysis/Utils/Local.h back to TransformsDavid Blaikie1-1/+1
Review feedback from r328165. Split out just the one function from the file that's used by Analysis. (As chandlerc pointed out, the original change only moved the header and not the implementation anyway - which was fine for the one function that was used (since it's a template/inlined in the header) but not in general) llvm-svn: 333954
2018-05-14Rename DEBUG macro to LLVM_DEBUG.Nicola Zaghen1-3/+3
The DEBUG() macro is very generic so it might clash with other projects. The renaming was done as follows: - git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g' - git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM - Manual change to APInt - Manually chage DOCS as regex doesn't match it. In the transition period the DEBUG() macro is still present and aliased to the LLVM_DEBUG() one. Differential Revision: https://reviews.llvm.org/D43624 llvm-svn: 332240
2018-04-13[Transforms] Change std::sort to llvm::sort in response to r327219Mandeep Singh Grang1-4/+4
Summary: r327219 added wrappers to std::sort which randomly shuffle the container before sorting. This will help in uncovering non-determinism caused due to undefined sorting order of objects having the same key. To make use of that infrastructure we need to invoke llvm::sort instead of std::sort. Note: This patch is one of a series of patches to replace *all* std::sort to llvm::sort. Refer the comments section in D44363 for a list of all the required patches. Reviewers: kcc, pcc, danielcdh, jmolloy, sanjoy, dberlin, ruiu Reviewed By: ruiu Subscribers: ruiu, llvm-commits Differential Revision: https://reviews.llvm.org/D45142 llvm-svn: 330059