aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/PredicateInfo.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-08-17[llvm] Remove unused includes (NFC) (#154051)Kazu Hirata1-1/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-08-12[SCCP][PredicateInfo] Do not predicate argument of lifetime intrinsicNikita Popov1-0/+5
Replacing the argument with a no-op bitcast violates a verifier constraint, even if only temporarily. Any replacement based on it would result in a violation even after the copy has been removed. Fixes https://github.com/llvm/llvm-project/issues/153013.
2025-08-11[PredicateInfo] Handle trunc nuw i1 condition. (#152988)Andreas Jonson1-0/+9
proof: https://alive2.llvm.org/ce/z/mxtn4L
2025-08-11[PredicateInfo] Use bitcast instead of ssa.copy (#151174)Nikita Popov1-43/+12
PredicateInfo needs some no-op to which the predicate can be attached. Currently this is an ssa.copy intrinsic. This PR replaces it with a no-op bitcast. Using a bitcast is more efficient because we don't have the overhead of an overloaded intrinsic. It also makes things slightly simpler overall.
2025-08-04[llvm] Use llvm::iterator_range::empty (NFC) (#151905)Kazu Hirata1-1/+1
2025-07-23[llvm] Remove unused includes (NFC) (#150265)Kazu Hirata1-1/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-06-26[PredicateInfo] Use BumpPtrAllocator for predicates (NFC) (#145692)Nikita Popov1-11/+14
Currently predicates are allocated on the heap and tracked with an intrusive list. Use a bump pointer allocator instead, which is more efficient. The list is no longer needed, as we don't have to track predicates for freeing. The bump pointer allocator is provided as a parameter for PredicateInfo to allow reusing the same allocator for all functions during IPSCCP.
2025-06-23[PredicateInfo] Cache ssa.copy declarations (NFC) (#145020)Nikita Popov1-17/+20
This pass creates a lot of ssa.copy intrinsics, typically for a small set of types. Determining the function type, performing intrinsic name mangling and looking up the declaration has noticeable overhead in this case. Improve this by caching the declarations by type. I've made this a separate map from CreatedDeclarations, which only tracks the declarations that were newly inserted (but not pre-existing ones).
2025-06-23[PredicateInfo] Don't store Def in ValueDFS (NFC) (#145022)Nikita Popov1-18/+22
Def is only actually used during renaming, and having it in ValueDFS causes unnecessary confusion. Remove it from ValueDFS and instead use a separate StackEntry structure for renaming, which holds the ValueDFS and the Def.
2025-06-23[PredicateInfo] Don't use depth first walk (NFCI) (#145016)Nikita Popov1-6/+8
The order in which we collect the predicates does not matter, as they will be sorted anyway. As such, avoid the expensive depth first walk over the dominator tree and instead use plain iteration over the function. (To be a bit more precise, the predicates and uses for a specific value are sorted, so this change has no impact on that. It can change the order in which values are processed in the first place, but that order is not semantically relevant.)
2025-06-20[PredicateInfo] Clean up DFS sorting (NFC) (#144943)Nikita Popov1-70/+35
The comparison function for ValueDFS was confused in a number of ways. Most significantly, it had a bunch of logic based on Def -- however, Def is always null during sorting, it only gets set later. At this point defs only have PInfo set. Clean up the implementation to remove various dead code.
2025-06-20[PredicateInfo] Avoid duplicate stack in scope check (NFC)Nikita Popov1-13/+8
popStackUntilDFSScope() is going to check this itself, there is no need to do it in advance as well.
2025-06-20[PredicateInfo] Remove redundant EdgeOnly member (NFC)Nikita Popov1-11/+8
EdgeOnly indicates a phi def, which can already be identified by LN_Last with non-null PInfo. Most of the code already reasons in terms of LN_Last instead of EdgeOnly.
2025-06-20[PredicateInfo] Remove unnecessary EdgeUsesOnly set (NFC) (#144912)Nikita Popov1-9/+1
As far as I can tell, this set is pointless: It just represents whether the target block has multiple predecessors, and the way it is constructed and queried, we're not even reducing the number of getSinglePredecessor() calls or something like that.
2025-06-19[PredicateInfo] Avoid duplicate hash lookup (NFC)Nikita Popov1-8/+4
Use try_emplace to either look up the existing entry or insert it.
2025-05-24[PredicateInfo] Update comments for PredicateAssume (NFC) (#139269)GnSight1-5/+5
Previously, PredicateAssume was modified to materialize after the assume statement rather than before it (See 353fa44). Update relevant comments to match this.
2024-11-04[Utils] Remove unused includes (NFC) (#114748)Kazu Hirata1-1/+0
Identified with misc-include-cleaner.
2024-10-11[NFC] Rename `Intrinsic::getDeclaration` to `getOrInsertDeclaration` (#111752)Rahul Joshi1-2/+2
Rename the function to reflect its correct behavior and to be consistent with `Module::getOrInsertFunction`. This is also in preparation of adding a new `Intrinsic::getDeclaration` that will have behavior similar to `Module::getFunction` (i.e, just lookup, no creation).
2024-01-27[Transforms] Use a range-based for loop (NFC)Kazu Hirata1-3/+1
2023-11-25[NewPM] Remove PredicateInfoPrinterLegacyPass (#73407)Aiden Grossman1-33/+0
This pass isn't used anywhere upstream and thus has no test coverage. For these reasons, remove it.
2022-12-12Transforms/Utils: llvm::Optional => std::optionalFangrui Song1-1/+1
2022-12-02[Transforms] Use std::nullopt instead of None (NFC)Kazu Hirata1-3/+3
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. 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-08-27[Transforms] Qualify auto in range-based for loops (NFC)Kazu Hirata1-1/+1
Identified with readability-qualified-auto.
2022-08-07[llvm] Qualify auto (NFC)Kazu Hirata1-2/+2
Identified with readability-qualified-auto.
2022-03-01Cleanup includes: TransformsUtilsserge-sans-paille1-8/+0
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-07-28[PredicateInfo] Use Intrinsic::getDeclaration now that it handles unnamed types.Jeroen Dobbelaere1-19/+13
This is a second attempt to fix the EXPENSIVE_CHECKS issue that was mentioned In D91661#2875179 by @jroelofs. (The first attempt was in D105983) D91661 more or less completely reverted D49126 and by doing so also removed the cleanup logic of the created declarations and calls. This patch is a replacement for D91661 (which must itself be reverted first). It replaces the custom declaration creation with the generic version and shows the test impact. It also tracks the number of NamedValues to detect if a new prototype was added instead of looking at the available users of a prototype. Reviewed By: jroelofs Differential Revision: https://reviews.llvm.org/D106147
2021-07-28Revert "Revert of D49126 [PredicateInfo] Use custom mangling to support ↵Jeroen Dobbelaere1-4/+56
ssa_copy with unnamed types." This reverts commit 77080a1eb6061df2dcfae8ac84b85ad4d1e02031. This change introduced issues detected with EXPENSIVE_CHECKS. Reverting to restore the needed function cleanup. A next patch will then just improve on the name mangling.
2021-03-20Revert of D49126 [PredicateInfo] Use custom mangling to support ssa_copy ↵Jeroen Dobbelaere1-56/+4
with unnamed types. Now that intrinsic name mangling can cope with unnamed types, the custom name mangling in PredicateInfo (introduced by D49126) can be removed. (See D91250, D48541) Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D91661
2021-02-26[Transforms/Utils] Use range-based for loops (NFC)Kazu Hirata1-6/+5
2021-02-11Revert "[AssumptionCache] Avoid dangling llvm.assume calls in the cache"Michael Kruse1-5/+4
This reverts commit b7d870eae7fdadcf10d0f177faa7409c2e37d776 and the subsequent fix "[Polly] Fix build after AssumptionCache change (D96168)" (commit e6810cab09fcbc87b6e5e4d226de0810e2f2ea38). It caused indeterminism in the output, such that e.g. the polly-x86_64-linux buildbot failed accasionally.
2021-02-08[Transforms/Utils] Drop unnecessary const from a return type (NFC)Kazu Hirata1-4/+2
Identified with const-return-type.
2021-02-06[AssumptionCache] Avoid dangling llvm.assume calls in the cacheJohannes Doerfert1-4/+5
PR49043 exposed a problem when it comes to RAUW llvm.assumes. While D96106 would fix it for GVNSink, it seems a more general concern. To avoid future problems this patch moves away from the vector of weak reference model used in the assumption cache. Instead, we track the llvm.assume calls with a callback handle which will remove itself from the cache if the call is deleted. Fixes PR49043. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D96168
2021-01-20[PredicateInfo] Handle logical and/orNikita Popov1-3/+3
Teach PredicateInfo to handle logical and/or the same way as bitwise and/or. This allows handling logical and/or inside IPSCCP and NewGVN.
2021-01-20[PredicateInfo] Generalize processing of conditionsNikita Popov1-99/+76
Branch/assume conditions in PredicateInfo are currently handled in a rather ad-hoc manner, with some arbitrary limitations. For example, an `and` of two `icmp`s will be handled, but an `and` of an `icmp` and some other condition will not. That also includes the case where more than two conditions and and'ed together. This patch makes the handling more general by looking through and/ors up to a limit and considering all kinds of conditions (though operands will only be taken for cmps of course). Differential Revision: https://reviews.llvm.org/D94447
2020-07-23[PredicateInfo][SCCP] Remove assertion (PR46814)Nikita Popov1-1/+4
As long as RenamedOp is not guaranteed to be accurate, we cannot assert here and should just return false. This was already done for the other conditions in this function. Fixes https://bugs.llvm.org/show_bug.cgi?id=46814.
2020-07-19[PredicateInfo] Add a method to interpret predicate as cmp constraintNikita Popov1-0/+47
Both users of predicteinfo (NewGVN and SCCP) are interested in getting a cmp constraint on the predicated value. They currently implement separate logic for this. This patch adds a common method for this in PredicateBase. This enables a missing bit of PredicateInfo handling in SCCP: Now the predicate on the condition itself is also used. For switches it means we know that the switched-on value is the same as the case value. For assumes/branches we know that the condition is true or false. Differential Revision: https://reviews.llvm.org/D83640
2020-07-14[NFC] Add 'override' keyword where missing in include/ and lib/.Logan Smith1-4/+4
This fixes warnings raised by Clang's new -Wsuggest-override, in preparation for enabling that warning in the LLVM build. This patch also removes the virtual keyword where redundant, but only in places where doing so improves consistency within a given file. It also removes a couple unnecessary virtual destructor declarations in derived classes where the destructor inherited from the base class is already virtual. Differential Revision: https://reviews.llvm.org/D83709
2020-07-13[PredicateInfo] Place predicate info after assumeNikita Popov1-4/+6
Place the ssa.copy instructions for assumes after the assume, instead of before it. Both options are valid, but placing them afterwards prevents assumes from being replaced with assume(true). This fixes https://bugs.llvm.org/show_bug.cgi?id=37541 in NewGVN and will avoid a similar issue in SCCP when we handle more predicate infos. Differential Revision: https://reviews.llvm.org/D83631
2020-07-09[PredicateInfo] Print RenamedOp (NFC)Nikita Popov1-3/+6
Make it easier to debug renaming issues.
2020-07-09[PredicateInfo] Add additional RenamedOp field to PB.Florian Hahn1-0/+3
OriginalOp of a predicate always refers to the original IR value that was renamed. So for nested predicates of the same value, it will always refer to the original IR value. For the use in SCCP however, we need to find the renamed value that is currently used in the condition associated with the predicate. This patch adds a new RenamedOp field to do exactly that. NewGVN currently relies on the existing behavior to merge instruction metadata. A test case to check for exactly that has been added in 195fa4bfae10. Reviewers: efriedma, davide, nikic Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D78133
2020-06-23[Transforms] Ensure we include CommandLine.h if we declare any cl::opt flagsSimon Pilgrim1-0/+1
2020-04-20[PredicateInfo] Use new Instruction::comesBefore instead of OI (NFC).Florian Hahn1-15/+9
The recently added Instruction::comesBefore can be used instead of OrderedInstructions. Reviewers: rnk, nikic, efriedma Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D78452
2020-04-18[PredicateInfo] Factor out PredicateInfoBuilder (NFC)Nikita Popov1-33/+89
When running IPSCCP on a module with many small functions, memory usage is dominated by PredicateInfo, which is a huge structure (partially due to some unfortunate nested SmallVector use). However, most of it is actually only temporary state needed to build predicate info, and does not need to be retained after initial construction. This patch factors out the predicate building logic and state into a separate PrediceInfoBuilder, with the extra bonus that it does not need to live in the header anymore. Differential Revision: https://reviews.llvm.org/D78326
2019-11-13Sink all InitializePasses.h includesReid Kleckner1-0/+1
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-10-07Second attempt to add iterator_range::empty()Jordan Rose1-2/+2
Doing this makes MSVC complain that `empty(someRange)` could refer to either C++17's std::empty or LLVM's llvm::empty, which previously we avoided via SFINAE because std::empty is defined in terms of an empty member rather than begin and end. So, switch callers over to the new method as it is added. https://reviews.llvm.org/D68439 llvm-svn: 373935
2019-08-15[llvm] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere1-3/+3
Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. llvm-svn: 369013
2019-07-25[PredicateInfo] Replace pointer comparisons with deterministic compares.Florian Hahn1-9/+40
Currently there are a few pointer comparisons in ValueDFS_Compare, which can cause non-deterministic ordering when materializing values. There are 2 cases this patch fixes: 1. Order defs before uses used to compare pointers, which guarantees defs before uses, but causes non-deterministic ordering between 2 uses or 2 defs, depending on the allocation order. By converting the pointers to booleans, we can circumvent that problem. 2. comparePHIRelated was comparing the basic block pointers of edges, which also results in a non-deterministic order and is also not really meaningful for ordering. By ordering by their destination DFS numbers we guarantee a deterministic order. For the example below, we can end up with 2 different uselist orderings, when running `opt -mem2reg -ipsccp` hundreds of times. Because the non-determinism is caused by allocation ordering, we cannot reproduce it with ipsccp alone. declare i32 @hoge() local_unnamed_addr #0 define dso_local i32 @ham(i8* %arg, i8* %arg1) #0 { bb: %tmp = alloca i32 %tmp2 = alloca i32, align 4 br label %bb19 bb4: ; preds = %bb20 br label %bb6 bb6: ; preds = %bb4 %tmp7 = call i32 @hoge() store i32 %tmp7, i32* %tmp %tmp8 = load i32, i32* %tmp %tmp9 = icmp eq i32 %tmp8, 912730082 %tmp10 = load i32, i32* %tmp br i1 %tmp9, label %bb11, label %bb16 bb11: ; preds = %bb6 unreachable bb13: ; preds = %bb20 br label %bb14 bb14: ; preds = %bb13 %tmp15 = load i32, i32* %tmp br label %bb16 bb16: ; preds = %bb14, %bb6 %tmp17 = phi i32 [ %tmp10, %bb6 ], [ 0, %bb14 ] br label %bb19 bb18: ; preds = %bb20 unreachable bb19: ; preds = %bb16, %bb br label %bb20 bb20: ; preds = %bb19 indirectbr i8* null, [label %bb4, label %bb13, label %bb18] } Reviewers: davide, efriedma Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D64866 llvm-svn: 367049
2019-07-25[PredicateInfo] Use SmallVector instead of SmallPtrSet.Florian Hahn1-13/+8
We do not need the SmallPtrSet to avoid adding duplicates to OpsToRename, because we already keep a ValueInfo mapping. If we see an op for the first time, Infos will be empty and we can also add it to OpsToRename. We process operands by visiting BBs depth-first and then iterate over all instructions & users, so the order should be deterministic. Therefore we can skip one round of sorting, which we purely needed for guaranteeing a deterministic order when iterating over the SmallPtrSet. Reviewers: efriedma, davide Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D64816 llvm-svn: 367028
2019-05-15[PredicateInfo] Do not process unreachable operands.Taewook Oh1-1/+2
Summary: We should excluded unreachable operands from processing as their DFS visitation order is undefined. When `renameUses` function sorts `OpsToRename` (https://fburl.com/d2wubn60), the comparator assumes that the parent block of the operand has a corresponding dominator tree node. This is not the case for unreachable operands and crashes the compiler. Reviewers: dberlin, mgrang, davide Subscribers: efriedma, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D61154 llvm-svn: 360796
2019-04-23Use llvm::stable_sortFangrui Song1-1/+1
While touching the code, simplify if feasible. llvm-svn: 358996