aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis
AgeCommit message (Collapse)AuthorFilesLines
2024-08-22[Analysis] Teach ScalarEvolution::getRangeRef about more dereferenceable ↵David Sherwood1-10/+8
objects (#104778) Whilst dealing with review comments on https://github.com/llvm/llvm-project/pull/96752 I discovered that SCEV does not know about the dereferenceable attribute on function arguments so I have updated getRangeRef to make use of it by calling getPointerDereferenceableBytes.
2024-08-22Enable logf128 constant folding for hosts with 128bit long double (#104929)Matthew Devereau2-12/+24
This is a reland of (#96287). This patch attempts to reduce the reverted patch's clang compile time by removing #includes of float128.h and inlining convertToQuad functions instead.
2024-08-21[ctx_prof] API to get the instrumentation of a BB (#105468)Mircea Trofin1-0/+7
Analogous to PR #104491 Issue #89287
2024-08-21[ctx_prof] Profile flatterner (#104539)Mircea Trofin1-0/+40
Eventually we'll need to flatten the profile (at the end of all IPO) and lower to "vanilla" `MD_prof`. This is the first part of that. Issue #89287
2024-08-21[NFC][Support] Move ModRef/MemoryEffects printers to their own file (#105367)Rahul Joshi1-36/+0
- Move raw_ostream << operators for `ModRef` and `MemoryEffects` to a new ModRef.cpp file under llvm/Support (instead of AliasAnalysis.cpp) - This enables calling these operators from `Core` files like Instructions.cpp (for instance for debugging). Currently, they live in `LLVMAnalysis` which cannot be linked with `Core`.
2024-08-21[LAA] Collect loop guards only once in MemoryDepChecker (NFCI).Florian Hahn1-2/+6
This on its own gives small compile-time improvements in some configs and enables using loop guards at more places in the future while keeping compile-time impact low. https://llvm-compile-time-tracker.com/compare.php?from=c44202574ff9a8c0632aba30c2765b134557435f&to=55ffc3dd920fa9af439fd39f8f9cc13509531420&stat=instructions:u
2024-08-20[ctx_prof] Add analysis utility to fetch ID of a callsite (#104491)Mircea Trofin1-0/+7
This will be needed when maintaining the contextual profile for ICP or inlining - we'll need to first fetch the ID of a callsite, which is in an instrumentation instruction (intrinsic) preceding the callsite.
2024-08-20[DXIL][Analysis] Add validator version to info collected by Module Metadata ↵S. Bharadwaj Yadavalli1-0/+9
Analysis (#104828) Add Validator Version to information collected by Module Metadata Analysis pass. An earlier change (#104040) added a default hardcoded value for validator version to be associated with DXIL module created during HLSL source compilation. Add tests to verify validator version info collected - Updated existing tests - Added a test with validator version specified in DXIL metadata
2024-08-20Reapply "[CycleAnalysis] Methods to verify cycles and their nesting. (#102300)"Sameer Sahasrabuddhe1-0/+7
This reverts commit 4aacc60fe7e1f7b3f788bba8382ea1fa5189ef3b. The original implementation provided a simple method to check whether the forest of nested cycles is well-formed. This is now augmented with other methods to check well-formedness of every cycle, either individually, or as the entire forest. These will be used by future transforms that modify CycleInfo.
2024-08-20Revert "[CycleAnalysis] Methods to verify cycles and their nesting. (#102300)"Sameer Sahasrabuddhe1-9/+0
This reverts commit b432afc28406b670a58933c2fe56c73e6f85911e. Reverted due to linker failures in expensive-checks.
2024-08-20[BasicAA] Use nuw attribute of GEPs (#98608)Hari Limaye1-20/+49
Use the nuw attribute of GEPs to prove that pointers do not alias, in cases matching the following: + + + | BaseOffset | +<nuw> Indices | ---------------->|-------------------->| |-->V2Size | |-------> V1Size LHS RHS If the difference between pointers is Offset +<nuw> Indices then we know that the addition does not wrap the pointer index type (add nuw) and the constant Offset is a lower bound on the distance between the pointers. We can then prove NoAlias via Offset u>= V2Size.
2024-08-20[CycleAnalysis] Methods to verify cycles and their nesting. (#102300)Sameer Sahasrabuddhe1-0/+9
The original implementation provided a simple method to check whether the forest of nested cycles is well-formed. This is now augmented with other methods to check well-formedness of all cycles, either invdividually, or as the entire forest. These will be used by future transforms that modify CycleInfo.
2024-08-19[ValueTracking] Handle incompatible types instead of asserting in ↵Noah Goldstein1-2/+3
`isKnownNonEqual`; NFC Downstream hit this assert, since it doesn't really make any difference, just change code to return false.
2024-08-18[InstSimplify] Simplify `uadd.sat(X, Y) u>= X + Y` and `usub.sat(X, Y) u<= ↵Yingwei Zheng1-0/+16
X, Y` (#104698) These patterns are found in harfbuzz/typst. Alive2: https://alive2.llvm.org/ce/z/cxyjYV
2024-08-17[LSR] Split the -lsr-term-fold transformation into it's own pass (#104234)Philip Reames1-4/+0
This transformation doesn't actually use any of the internal state of LSR and recomputes all information from SCEV. Splitting it out makes it easier to test. Note that long term I would like to write a version of this transform which *is* integrated with LSR's solver, but if that happens, we'll just delete the extra pass. Integration wise, I switched from using TTI to using a pass configuration variable. This seems slightly more idiomatic, and means we don't run the extra logic on any target other than RISCV.
2024-08-17[NFC] Cleanup in ADT and Analysis headers. (#104484)Daniil Fukalov3-0/+3
Remove unused directly includes and forward declarations in ADT and Analysis headers.
2024-08-16Re-Apply "[DXIL][Analysis] Implement enough of DXILResourceAnalysis for ↵Justin Bogner1-3/+377
buffers" (#104517) Some build configs allow `llvm_unreachable` in a constexpr context, but not all, so these functions that map a fully covered enum to a string can't be constexpr. This version fixes that by dropping constexpr from those functions. This reverts commit fcc318ff7960d7de8cbac56eb4f32b44b5261677, reapplying 28d577ecefa1557f5dea5566bf33b885c563d14b. Original message follows: This implements the DXILResourceAnalysis pass for `dx.TypedBuffer` and `dx.RawBuffer` types. This should be sufficient to lower `dx.handle.fromBinding` for this set of types, but it leaves a number of TODOs around for other resource types. This also includes a straightforward `print` method in `ResourceInfo` to make the analysis testable. This is deliberately different than the printer in `lib/Target/DirectX/DXILResource.cpp`, which attempts to print bindings in a format compatible with the comments `dxc` prints. We will eventually want to make that functionality driven by this analysis pass, but it isn't sufficient for testing so we need both.
2024-08-16[LAA] Use computeConstantDifference() (#103725)Nikita Popov2-9/+7
Use computeConstantDifference() instead of casting getMinusSCEV() to SCEVConstant. This can be much faster in some cases, because computeConstantDifference() computes the result without creating new SCEV expressions. This improves LTO/ThinLTO compile-time for lencod by more than 10%. I've verified that computeConstantDifference() does not produce worse results than the previous code for anything in llvm-test-suite. This required raising the iteration cutoff to 6. I ended up increasing it to 8 just to be on the safe side (for code outside llvm-test-suite), and because this doesn't materially affect compile-time anyway (we'll almost always bail out earlier).
2024-08-15[Analysis] Use a range-based for loop (NFC) (#104445)Kazu Hirata1-2/+2
2024-08-15Revert "[DXIL][Analysis] Implement enough of DXILResourceAnalysis for ↵Mehdi Amini1-377/+3
buffers" (#104504) Reverts llvm/llvm-project#100699 This broke a few bots unfortunately.
2024-08-15[nfc][ctx_prof] Remove the need for `PassBuilder` to know about ↵Mircea Trofin1-0/+3
`UseCtxProfile` (#104492)
2024-08-15[ValueTracking] Fix f16 fptosi range for large integersNikita Popov1-1/+1
We were missing the signed flag on the negative value, so the range was incorrectly interpreted for integers larger than 64-bit. Split out from https://github.com/llvm/llvm-project/pull/80309.
2024-08-15[ctx_prof] Remove an unneeded include in CtxProfAnalysis.cppHaojian Wu1-1/+0
2024-08-14[ctx_prof] CtxProfAnalysis: populate module data (#102930)Mircea Trofin1-3/+90
Continuing from #102084, which introduced the analysis, we now populate it with info about functions contained in the module. When we will update the profile due to e.g. inlined callsites, we'll ingest the callee's counters and callsites to the caller. We'll move those to the caller's respective index space (counter and callers), so we need to know and maintain where those currently end. We also don't need to keep profiles not pertinent to this module. This patch also introduces an arguably much simpler way to track the GUID of a function from the frontend compilation, through ThinLTO, and into the post-thinlink compilation step, which doesn't rely on keeping names around. A separate RFC and patches will discuss extending this to the current PGO (instrumented and sampled) and other consumers as an infrastructural component.
2024-08-15[DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffersJustin Bogner1-3/+377
This implements the DXILResourceAnalysis pass for `dx.TypedBuffer` and `dx.RawBuffer` types. This should be sufficient to lower `dx.handle.fromBinding` for this set of types, but it leaves a number of TODOs around for other resource types. This also includes a straightforward `print` method in `ResourceInfo` to make the analysis testable. This is deliberately different than the printer in `lib/Target/DirectX/DXILResource.cpp`, which attempts to print bindings in a format compatible with the comments `dxc` prints. We will eventually want to make that functionality driven by this analysis pass, but it isn't sufficient for testing so we need both. Pull Request: https://github.com/llvm/llvm-project/pull/100699
2024-08-15[DXIL][Analysis] Boilerplate for DXILResourceAnalysis passJustin Bogner2-1/+79
Broke this out into its own commit to make the next one easier to review. Pull Request: https://github.com/llvm/llvm-project/pull/100700
2024-08-14[LLVM] Fix missing includes for function declarations that will be needed ↵Thomas Fransham2-0/+2
for explicit symbol visibility (#103900) In multiple source files function definitions never sees there declaration in a header because its never included causing linker errors when explicit symbol visibility macros\dllexport are added to the declarations. Most of these were originally found by @tstellar in https://github.com/llvm/llvm-project/pull/67502 TargetRegistry.h is needed in MCExternalSymbolizer.cpp for createMCSymbolizer Analysis/Passes.h is needed in LazyValueInfo.cpp and RegionInfo.cpp for createLazyValueInfoPassin and createRegionInfoPass Transforms/Scalar.h is needed in SpeculativeExecution.cpp for createSpeculativeExecutionPass
2024-08-14[Analysis] Use range-based for loops (NFC) (#103540)Kazu Hirata2-7/+6
2024-08-14BasicAA: Fix assert when indexing address spaces with different sizes (#103713)Matt Arsenault1-0/+3
Fixes #103500
2024-08-14[BasicAA] Remove unused variables (NFC)Nikita Popov1-3/+0
Split out from #98608.
2024-08-14Revert "Reland logf128 constant folding (#103217)"Nikita Popov2-2/+8
This reverts commit 3cab7c555ad6451f2b1b4dc918a4b4f4e4a3e45d. The modified test fails on ppc64le buildbots.
2024-08-14Reland logf128 constant folding (#103217)Matthew Devereau2-8/+2
This is a reland of #96287. This change makes tests in logf128.ll ignore the sign of NaNs for negative value tests and moves an #include <cmath> to be blocked behind #ifndef _GLIBCXX_MATH_H.
2024-08-14[SCEV] Look through multiply in computeConstantDifference() (#103051)Nikita Popov1-3/+25
Inside computeConstantDifference(), handle the case where both sides are of the form `C * %x`, in which case we can strip off the common multiplication (as long as we remember to multiply by it for the following difference calculation). There is an obvious alternative implementation here, which would be to directly decompose multiplies inside the "Multiplicity" accumulation. This does work, but I've found this to be both significantly slower (because everything has to work on APInt) and more complex in implementation (e.g. because we now need to match back the new More/Less with an arbitrary factor) without providing more power in practice. As such, I went for the simpler variant here. This is the last step to make computeConstantDifference() sufficiently powerful to replace existing uses of `cast<SCEVConstant>(getMinusSCEV())` with it.
2024-08-13Enhance TLI detection of __size_returning_new lib funcs. (#102391)Snehasish Kumar1-1/+50
Previously the return types of __size_returning_new variants were not validated based on their members. This patch checks the members manually, also generalizes the size_t checks to be based on the module instead of being hardcoded. As requested in followup comment on https://github.com/llvm/llvm-project/pull/101564.
2024-08-13[LLVM] Don't peek through bitcast on pointers and gep with zero indices. ↵Yingwei Zheng2-75/+23
NFC. (#102889) Since we are using opaque pointers now, we don't need to peek through bitcast on pointers and gep with zero indices.
2024-08-13[MemoryBuiltins] Use getAllOnesValue()Nikita Popov1-1/+2
Split out from https://github.com/llvm/llvm-project/pull/80309.
2024-08-13Reland "[Support] Assert that DomTree nodes share parent" (#102782)Vitaly Buka1-0/+2
A dominance query of a block that is in a different function is ill-defined, so assert that getNode() is only called for blocks that are in the same function. There are three cases, where this behavior did occur. LoopFuse didn't explicitly do this, but didn't invalidate the SCEV block dispositions, leaving dangling pointers to free'ed basic blocks behind, causing use-after-free. We do, however, want to be able to dereference basic blocks inside the dominator tree, so that we can refer to them by a number stored inside the basic block. Reverts #102780 Reland #101198 Fixes #102784 Co-authored-by: Alexis Engelke <engelke@in.tum.de>
2024-08-13[SCEV] Fix -Wrange-loop-construct (NFC)Jie Fu1-1/+1
/llvm-project/llvm/lib/Analysis/ScalarEvolution.cpp:12009:21: error: loop variable '[S, Mul]' creates a copy from type 'const value_type' (aka 'const llvm::detail::DenseMapPair<const llvm::SCEV *, int>') [-Werror,-Wrange-loop-construct] for (const auto [S, Mul] : Multiplicity) { ^ /llvm-project/llvm/lib/Analysis/ScalarEvolution.cpp:12009:10: note: use reference type 'const value_type &' (aka 'const llvm::detail::DenseMapPair<const llvm::SCEV *, int> &') to prevent copying for (const auto [S, Mul] : Multiplicity) { ^~~~~~~~~~~~~~~~~~~~~ &
2024-08-13[SCEV] Handle more add/addrec mixes in computeConstantDifference() (#101999)Nikita Popov1-48/+80
computeConstantDifference() can currently look through addrecs with identical steps, and then through adds with identical operands (apart from constants). However, it fails to handle minor variations, such as two nested add recs, or an outer add with an inner addrec (rather than the other way around). This patch supports these cases by adding a loop over the simplifications, limited to a small number of iterations. The motivation is the same as in #101339, to make computeConstantDifference() powerful enough to replace existing uses of `dyn_cast<SCEVConstant>(getMinusSCEV())` with it. Though as the IR test diff shows, other callers may also benefit.
2024-08-13[DataLayout] Remove constructor accepting a pointer to Module (#102841)Sergei Barannikov1-2/+1
The constructor initializes `*this` with `M->getDataLayout()`, which is effectively the same as calling the copy constructor. There does not seem to be a case where a copy would be necessary. Pull Request: https://github.com/llvm/llvm-project/pull/102841
2024-08-12[SCEV] Consolidate code for proving wrap flags of controlling finite IVs ↵Philip Reames1-47/+27
(#101404) The canAssumeNoSelfWrap routine in howManyLessThans was doing two subtly inter-related things. First, it was proving no-self-wrap. This exactly duplicates the existing logic in the caller. Second, it was establishing the precondition for the nw->nsw/nuw inference. Specifically, we need to know that *this* exit must be taken for the inference to be sound. Otherwise, another (possible abnormal) exit could be taken in the iteration where this IV would become poison. This change moves all of that logic into the caller, and caches the resulting nuw/nsw flags in the AddRec. This centralizes the logic in one place, and makes it clear that it all depends on controlling the sole exit. We do loose a couple cases with SCEV predication. Specifically, if SCEV predication was able to convert e.g. zext(addrec) into an addrec(zext) using predication, but didn't record the nuw fact on the new addrec, then the consuming code can no longer fix this up. I don't think this case particularly matters. --------- Co-authored-by: Nikita Popov <github@npopov.com>
2024-08-12[DXIL][Analysis] Add DXILMetadataAnalysis pass (#102079)S. Bharadwaj Yadavalli2-0/+97
DXIL Metadata Analysis passes (one for legacy PM and one for new PM) that collect following DXIL module metadata information in a structure are added. 1. Shader Model version 2. DXIL version 3. Shader Stage Information collected using the legacy pass is verified by adding additional test commands to existing metadata test sources.
2024-08-12[ConstantFolding] Use getSigned()Nikita Popov1-2/+3
Split out from https://github.com/llvm/llvm-project/pull/80309.
2024-08-12[SCEV] Fix incorrect extension in computeConstantDifference()Nikita Popov1-3/+8
The Mul factor was zero-extended here, resulting in incorrect results for integers larger than 64-bit. As we currently only multiply by 1 or -1, just split this into two cases -- there's no need for a full multiplication here. Fixes https://github.com/llvm/llvm-project/issues/102597.
2024-08-12[KnownBits] Add KnownBits::add and KnownBits::sub helper wrappers. (#99468)Simon Pilgrim1-12/+5
2024-08-10Revert "[Support] Assert that DomTree nodes share parent" (#102780)Vitaly Buka1-2/+0
Reverts llvm/llvm-project#101198 Breaks multiple bots: https://lab.llvm.org/buildbot/#/builders/72/builds/2103 https://lab.llvm.org/buildbot/#/builders/164/builds/1909 https://lab.llvm.org/buildbot/#/builders/66/builds/2706
2024-08-10[Analysis] Use llvm::set_is_subset (NFC) (#102766)Kazu Hirata1-3/+1
2024-08-10[Support] Assert that DomTree nodes share parent (#101198)Alexis Engelke1-0/+2
A dominance query of a block that is in a different function is ill-defined, so assert that getNode() is only called for blocks that are in the same function. There are two cases, where this behavior did occur. LoopFuse didn't explicitly do this, but didn't invalidate the SCEV block dispositions, leaving dangling pointers to free'ed basic blocks behind, causing use-after-free. We do, however, want to be able to dereference basic blocks inside the dominator tree, so that we can refer to them by a number stored inside the basic block.
2024-08-09[llvm] Construct SmallVector with ArrayRef (NFC) (#102712)Kazu Hirata1-2/+1
Without this patch, the constructor arguments come from SmallVectorImpl, not ArrayRef. This patch switches them to ArrayRef so that we can construct SmallVector with a single argument. Note that LLVM Programmer’s Manual prefers ArrayRef to SmallVectorImpl for flexibility.
2024-08-09[MemoryBuiltins] Simplify getCalledFunction() helper (NFC)Nikita Popov1-24/+12
If nobuiltin is set, directly return nullptr instead of using a separate out parameter and having all callers check this.