summaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
AgeCommit message (Collapse)Author
2025-11-05[LSCFG][profcheck] Add dummy branch weights for the dummy switch to dead ↵Mircea Trofin
exits (#164714) As noted in the doc comment of `handleDeadExits`​, the dummy switch is just an artifact of the constraints placed by the fact that we operate in a loop pass. Adding weights here is unnecessary, but the complexity is low, and it helps keep things easy for profile propagation verification (in a sense, the overall complexity would be higher if we special-cased this somehow). Issue #147390
2025-07-22[LoopSimplifyCFG] Add check for missing loop preheader (#149743)Justus Klausecker
Closes #147869 Closes #149679 Adds a check for a missing loop preheader during analysis. This fixes a nullptr dereference that happened whenever LoopSimplify was unable to generate a preheader because the loop was entered by an indirectbr instruction (as stated in the LoopSimplify.cpp doc comment).
2025-04-18[Transforms] Construct SmallVector with iterator ranges (NFC) (#136259)Kazu Hirata
2025-02-21[LoopSimplifyCFG] Fix SCEV invalidation after removing dead exit (#127536)Aleksandr Popov
Fixes #127534
2025-01-24[NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at many call-sites ↵Jeremy Morse
(#123737) 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 getFirstNonPHI use the iterator-returning version. This patch changes a bunch of call-sites calling getFirstNonPHI to use getFirstNonPHIIt, which returns an iterator. All these call sites are where it's obviously safe to fetch the iterator then dereference it. A follow-up patch will contain less-obviously-safe changes. We'll eventually deprecate and remove the instruction-pointer getFirstNonPHI, but not before adding concise documentation of what considerations are needed (very few). --------- Co-authored-by: Stephen Tozer <Melamoto@gmail.com>
2024-03-12[LoopSimplifyCFG] Drop no longer needed DependenceAnalysis.h includeBjorn Pettersson
2023-11-21[NewPM] Remove LoopSimplifyCFGLegacyPass (#72930)Aiden Grossman
This pass isn't used anywhere in upstream and thus has no test coverage. For these reasons, remove it.
2023-06-05Revert "[LCSSA] Remove unused ScalarEvolution argument (NFC)"Nikita Popov
This reverts commit 5362a0d859d8e96b3f7c0437b7866e17a818a4f7. In preparation for reverting a dependent revision.
2023-05-02[LCSSA] Remove unused ScalarEvolution argument (NFC)Nikita Popov
After D149435, LCSSA formation no longer needs access to ScalarEvolution, so remove the argument from the utilities.
2022-11-26[Scalar] Use std::optional in LoopSimplifyCFG.cpp (NFC)Kazu Hirata
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-21Don't use Optional::getPointer (NFC)Kazu Hirata
Since std::optional does not offer getPointer(), this patch replaces X.getPointer() with &*X to make the migration from llvm::Optional to std::optional easier. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716 Differential Revision: https://reviews.llvm.org/D138466
2022-10-20[LoopSimplifyCFG] Forget loop and block dispos after merging blocks.Florian Hahn
This fixes another case where block and loop dispositions weren't properly invalidate after changing the CFG. Fixes #58489.
2022-10-10[LoopSimplifyCFG] Clear SCEV dispositions when removing dead blocks.Florian Hahn
When removing loops & blocks we also need to clear the SCEV dispositions as they may now contain incorrect values. Fixes #58262.
2022-10-07[LoopSimplifyCFG] Invalidate SCEV dispositions.Florian Hahn
Clear all dispositions if there are any dead blocks (which will get removed later) and also clear dispositions for removed instructions. Clearing all dispositions in case there are dead blocks happens first, which should avoid traversing SCEV use-lists for invalidating dispositions for individual values. Fixes #58179.
2022-08-07[Transforms] Fix comment typos (NFC)Kazu Hirata
2022-07-19[LoopSimplifyCFG] Prevent use-def dominance breach by handling dead exits. ↵Max Kazantsev
PR56243 One of the transforms in LoopSimplifyCFG demands that the LCSSA form is truly maintained for all values, tokens included, otherwise it may end up creating a use that is not dominated by def (and Phi creation for tokens is impossible). Detect this situation and prevent transform for it early. Differential Revision: https://reviews.llvm.org/D129984 Reviewed By: efriedma
2022-07-18[LoopSimplifyCFG] Revert accidental changeNikita Popov
This change was included in an unrelated change b57d61384c9938e3dfa54b55bf8b2a0a05e67e28 and was of course not intended for commit...
2022-07-18[ConstantRangeTest] Move nowrap binop tests to generic infrastructure (NFC)Nikita Popov
Move testing for add/sub with nowrap flags to TestBinaryOpExhaustive, rather than separate homegrown exhaustive testing functions.
2022-06-26[llvm] Don't use Optional::hasValue (NFC)Kazu Hirata
This patch replaces Optional::hasValue with the implicit cast to bool in conditionals only.
2022-06-26[LoopSimplifyCFG] use poison when replacing dead instructions instead of ↵Nuno Lopes
undef [NFC]
2022-06-25Revert "Don't use Optional::hasValue (NFC)"Kazu Hirata
This reverts commit aa8feeefd3ac6c78ee8f67bf033976fc7d68bc6d.
2022-06-25Don't use Optional::hasValue (NFC)Kazu Hirata
2022-06-20Don't use Optional::hasValue (NFC)Kazu Hirata
2022-03-18[LoopSimplifyCFG] Check predecessors of exits before marking them dead.Florian Hahn
LoopSimplifyCFG may process loops that are not in loop-simplify/canonical form. For loops not in canonical form, exit blocks may be reachable from non-loop blocks and we cannot consider them as dead if they only are not reachable from the loop itself. Unfortunately the smallest test I could come up with requires running multiple passes: -passes='loop-mssa(loop-instsimplify,loop-simplifycfg,simple-loop-unswitch)' The reason is that loops are canonicalized at the beginning of loop pipelines, so a later transform has to break canonical form in a way that breaks LoopSimplifyCFG's dead-exit analysis. Alternatively we could try to require all loop passes to maintain canonical form. That in turn would also require additional verification. Fixes #54023, #49931. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D121925
2022-03-03Cleanup includes: Transform/Scalarserge-sans-paille
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-01-28[BasicBlockUtils] Fix typo in API name (NFC)Nikita Popov
detatch -> detach. As this requires touching all uses, also lower-case it in accordance with the style guide.
2021-11-23[llvm][NFC] Inclusive language: Reword replace uses of sanity in ↵Zarko Todorovski
llvm/lib/Transform comments and asserts Reworded some comments and asserts to avoid usage of `sanity check/test` Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D114372
2021-10-11[LoopSimplifyCFG] Do not require MSSA. Continue to preserve if available.Alina Sbirlea
LoopSimplifyCFG does not need MSSA, but should preserve it if it's available. This is a legacy PM change, aimed to denoise the test changes in D109958. Differential Revision: https://reviews.llvm.org/D111578
2021-08-16[MemorySSA] Remove -enable-mssa-loop-dependency optionNikita Popov
This option has been enabled by default for quite a while now. The practical impact of removing the option is that MSSA use cannot be disabled in default pipelines (both LPM and NPM) and in manual LPM invocations. NPM can still choose to enable/disable MSSA using loop vs loop-mssa. The next step will be to require MSSA for LICM and drop the AST-based implementation entirely. Differential Revision: https://reviews.llvm.org/D108075
2021-01-06[DominatorTree] Add support for mixed pre/post CFG views.Alina Sbirlea
Add support for mixed pre/post CFG views. Update usages of the MemorySSAUpdater to use the new DT API by requesting the DT updates to be done by the MSSAUpdater. Differential Revision: https://reviews.llvm.org/D93371
2020-12-17[NFC] Reduce include files dependency and AA header cleanup (part 2).dfukalov
Continuing work started in https://reviews.llvm.org/D92489: Removed a bunch of includes from "AliasAnalysis.h" and "LoopPassManager.h". Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D92852
2020-09-22[LoopInfo] empty() -> isInnermost(), add isOutermost()Stefanos Baziotis
Differential Revision: https://reviews.llvm.org/D82895
2020-07-29[LoopSimplifyCFG] Delete landing pads in dead exit blocksYevgeny Rouban
In addition to removing phi nodes this patch removes any landing pad that the dead exit block might have. Without this fix Verifier complains about a new switch instruction jumps to a block with a landing pad. Differential Revision: https://reviews.llvm.org/D84320
2020-06-05MemorySSAUpdater.h - reduce unnecessary includes to forward declarations. NFC.Simon Pilgrim
Remove unnecessary MemoryAccess forward declaration as its already included from MemorySSA.h Move implicit include dependencies down to source files.
2020-04-04[IVDescriptors] Remove IRBuilder.h include; NFCNikita Popov
IVDescriptors.h itself does not reference IRBuilder at all. Move the include into transformation passes that do.
2020-02-04[NFCI] Update according to style.Alina Sbirlea
clang-tidy + clang-format
2019-11-20[MemorySSA] Update analysis when the terminator is a memory instruction.Alina Sbirlea
Update MemorySSA when moving the terminator instruction, as that may be a memory touching instruction. Resolves PR44029.
2019-11-14Add missing includes needed to prune LLVMContext.h include, NFCReid Kleckner
These are a pre-requisite to removing #include "llvm/Support/Options.h" from LLVMContext.h: https://reviews.llvm.org/D70280
2019-11-13Sink all InitializePasses.h includesReid Kleckner
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-17[MemorySSA] Loop passes should mark MSSA preserved when available.Alina Sbirlea
This patch applies only to the new pass manager. Currently, when MSSA Analysis is available, and pass to each loop pass, it will be preserved by that loop pass. Hence, mark the analysis preserved based on that condition, vs the current `EnableMSSALoopDependency`. This leaves the global flag to affect only the entry point in the loop pass manager (in FunctionToLoopPassAdaptor). llvm-svn: 369181
2019-07-12[MemorySSA] Use SetVector to avoid nondeterminism.Alina Sbirlea
Summary: Use a SetVector for DeadBlockSet. Resolves PR42574. Reviewers: george.burgess.iv, uabelho, dblaikie Subscribers: jlebar, Prazek, mgrang, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64601 llvm-svn: 365970
2019-06-11Only passes that preserve MemorySSA must mark it as preserved.Alina Sbirlea
Summary: The method `getLoopPassPreservedAnalyses` should not mark MemorySSA as preserved, because it's being called in a lot of passes that do not preserve MemorySSA. Instead, mark the MemorySSA analysis as preserved by each pass that does preserve it. These changes only affect the new pass mananger. Reviewers: chandlerc Subscribers: mehdi_amini, jlebar, Prazek, george.burgess.iv, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D62536 llvm-svn: 363091
2019-04-29[LoopSimplifyCFG] Suppress expensive DomTree verificationYevgeny Rouban
This patch makes verification level lower for builds with inexpensive checks. Differential Revision: https://reviews.llvm.org/D61055 llvm-svn: 359446
2019-02-21[LoopSimplifyCFG] Update MemorySSA after r353911.Alina Sbirlea
Summary: MemorySSA is not properly updated in LoopSimplifyCFG after recent changes. Use SplitBlock utility to resolve that and clear all updates once handleDeadExits is finished. All updates that follow are removal of edges which are safe to handle via the removeEdge() API. Also, deleting dead blocks is done correctly as is, i.e. delete from MemorySSA before updating the CFG and DT. Reviewers: mkazantsev, rtereshin Subscribers: sanjoy, jlebar, Prazek, george.burgess.iv, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D58524 llvm-svn: 354613
2019-02-21[LoopSimplifyCFG] Add missing MSSA edge deletionMax Kazantsev
When we create fictive switch in preheader, we should take care about MSSA and delete edge between old preheader and header. llvm-svn: 354547
2019-02-19[NFC] API for signaling that the current loop is being deletedMax Kazantsev
We are planning to be able to delete the current loop in LoopSimplifyCFG in the future. Add API to notify the loop pass manager that it happened. llvm-svn: 354314
2019-02-19[NFC] Store loop header in a local to keep it available after the loop is ↵Max Kazantsev
deleted llvm-svn: 354313
2019-02-17[NFC] Teach getInnermostLoopFor walk up the loop treesMax Kazantsev
This should be NFC in current use case of this method, but it will help to use it for solving more compex tasks in follow-up patches. llvm-svn: 354227
2019-02-17[NFC] Fix name and clarifying comment for factored-out functionMax Kazantsev
llvm-svn: 354220
2019-02-17[NFC] Factor out a function for future reuseMax Kazantsev
llvm-svn: 354218