summaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Operator.cpp
AgeCommit message (Collapse)Author
2025-11-05[NFC][LLVM][IR] Cleanup namespace usage in LLVM IR cpp files (#166477)Rahul Joshi
2024-12-04[IR] Fix accumulateConstantOffset() on zero-index GEPNikita Popov
These are degenerate but not malformed, so make sure we don't crash.
2024-12-04[LLVM][IR] When evaluating GEP offsets don't assume ConstantInt is a scalar. ↵Paul Walker
(#117162)
2024-11-21[Operator] Truncate large type sizes in GEP calculationsNikita Popov
If the size is larger than the index width, truncate it instead of asserting. Longer-term we should consider rejecting types larger than the index size in the verifier, though this is probably tricky in practice (it's address space dependent, and types are owned by the context, not the module). Fixes https://github.com/llvm/llvm-project/issues/116960.
2024-10-15[IR] Add support for `samesign` in `Operator::hasPoisonGeneratingFlags` ↵Yingwei Zheng
(#112358) Fix https://github.com/llvm/llvm-project/issues/112356.
2024-09-30[NFC] Use initial-stack-allocations for more data structures (#110544)Jeremy Morse
This replaces some of the most frequent offenders of using a DenseMap that cause a malloc, where the typical element-count is small enough to fit in an initial stack allocation. Most of these are fairly obvious, one to highlight is the collectOffset method of GEP instructions: if there's a GEP, of course it's going to have at least one offset, but every time we've called collectOffset we end up calling malloc as well for the DenseMap in the MapVector.
2024-05-27[IR] Add getelementptr nusw and nuw flags (#90824)Nikita Popov
This implements the `nusw` and `nuw` flags for `getelementptr` as proposed at https://discourse.llvm.org/t/rfc-add-nusw-and-nuw-flags-for-getelementptr/78672. The three possible flags are encapsulated in the new `GEPNoWrapFlags` class. Currently this class has a ctor from bool, interpreted as the InBounds flag. This ctor should be removed in the future, as code gets migrated to handle all flags. There are a few places annotated with `TODO(gep_nowrap)`, where I've had to touch code but opted to not infer or precisely preserve the new flags, so as to keep this as NFC as possible and make sure any changes of that kind get test coverage when they are made.
2024-04-18[IR] Drop poison-generating return attributes when necessary (#89138)Andreas Jonson
Rename has/dropPoisonGeneratingFlagsOrMetadata to has/dropPoisonGeneratingAnnotations and make it also handle nonnull, align and range return attributes on calls, similar to the existing handling for !nonnull, !align and !range metadata.
2024-04-09Add support for `nneg` flag with `uitofp`Noah Goldstein
As noted when #82404 was pushed (canonicalizing `sitofp` -> `uitofp`), different signedness on fp casts can have dramatic performance implications on different backends. So, it makes to create a reliable means for the backend to pick its cast signedness if either are correct. Further, this allows us to start canonicalizing `sitofp`- > `uitofp` which may easy middle end analysis. Closes #86141
2024-04-02[IR] Fix crashes caused by #85592 (#87169)elhewaty
This patch fixes the crash caused by the pull request: https://github.com/llvm/llvm-project/pull/85592
2024-03-29[IR] Add nowrap flags for trunc instruction (#85592)elhewaty
This patch adds the nuw (no unsigned wrap) and nsw (no signed wrap) poison-generating flags to the trunc instruction. Discourse thread: https://discourse.llvm.org/t/rfc-add-nowrap-flags-to-trunc/77453
2024-03-20[IR] Change representation of getelementptr inrange (#84341)Nikita Popov
As part of the migration to ptradd (https://discourse.llvm.org/t/rfc-replacing-getelementptr-with-ptradd/68699), we need to change the representation of the `inrange` attribute, which is used for vtable splitting. Currently, inrange is specified as follows: ``` getelementptr inbounds ({ [4 x ptr], [4 x ptr] }, ptr @vt, i64 0, inrange i32 1, i64 2) ``` The `inrange` is placed on a GEP index, and all accesses must be "in range" of that index. The new representation is as follows: ``` getelementptr inbounds inrange(-16, 16) ({ [4 x ptr], [4 x ptr] }, ptr @vt, i64 0, i32 1, i64 2) ``` This specifies which offsets are "in range" of the GEP result. The new representation will continue working when canonicalizing to ptradd representation: ``` getelementptr inbounds inrange(-16, 16) (i8, ptr @vt, i64 48) ``` The inrange offsets are relative to the return value of the GEP. An alternative design could make them relative to the source pointer instead. The result-relative format was chosen on the off-chance that we want to extend support to non-constant GEPs in the future, in which case this variant is more expressive. This implementation "upgrades" the old inrange representation in bitcode by simply dropping it. This is a very niche feature, and I don't think trying to upgrade it is worthwhile. Let me know if you disagree.
2024-02-12[IR] Add ptradd fast path in accumulateConstantOffset() (NFC)Nikita Popov
For getelementptr i8 (aka ptradd) we can skip the whole logic and directly use the offset. As we're now canonicalizing to this form, it's pretty common and worth having a fast-path for.
2024-01-04[IR] Fix GEP offset computations for vector GEPs (#75448)Jannik Silvanus
Vectors are always bit-packed and don't respect the elements' alignment requirements. This is different from arrays. This means offsets of vector GEPs need to be computed differently than offsets of array GEPs. This PR fixes many places that rely on an incorrect pattern that always relies on `DL.getTypeAllocSize(GTI.getIndexedType())`. We replace these by usages of `GTI.getSequentialElementStride(DL)`, which is a new helper function added in this PR. This changes behavior for GEPs into vectors with element types for which the (bit) size and alloc size is different. This includes two cases: * Types with a bit size that is not a multiple of a byte, e.g. i1. GEPs into such vectors are questionable to begin with, as some elements are not even addressable. * Overaligned types, e.g. i16 with 32-bit alignment. Existing tests are unaffected, but a miscompilation of a new test is fixed. --------- Co-authored-by: Nikita Popov <github@npopov.com>
2023-12-14[IR] Avoid redundant map lookup [NFC]Jannik Silvanus
Use the iterator returned by MapVector::insert to update the value in the map, instead of a second redundant map lookup.
2023-11-30[IR] Support or disjoint in hasPoisonGeneratingFlags()Nikita Popov
This fixed incorrect removal of freeze instructions.
2023-10-30[IR] Add zext nneg flag (#67982)Nikita Popov
Add an nneg flag to the zext instruction, which specifies that the argument is non-negative. Otherwise, the result is a poison value. The primary use-case for the flag is to preserve information when sext gets replaced with zext due to range-based canonicalization. The nneg flag allows us to convert the zext back into an sext later. This is useful for some optimizations (e.g. a signed icmp can fold with sext but not zext), as well as some targets (e.g. RISCV prefers sext over zext). Discourse thread: https://discourse.llvm.org/t/rfc-add-zext-nneg-flag/73914 This patch is based on https://reviews.llvm.org/D156444 by @Panagiotis156, with some implementation simplifications and additional tests. --------- Co-authored-by: Panagiotis K <karouzakispan@gmail.com>
2023-09-14[IR] Enable load/store/alloca for arrays of scalable vectors.Paul Walker
Differential Revision: https://reviews.llvm.org/D158517
2023-01-20[ValueTracking] Take poison-generating metadata into account (PR59888)Nikita Popov
In canCreateUndefOrPoison(), take not only poison-generating flags, but also poison-generating metadata into account. The helpers are written generically, but I believe the only case that can actually matter is !range on calls -- !nonnull and !align are only valid on loads, and those can create undef/poison anyway. Unfortunately, this negatively impacts logical to bitwise and/or conversion: For ctpop/ctlz/cttz we always attach !range metadata, which will now block the transform, because it might introduce poison. It would be possible to recover this regression by supporting a ConsiderFlagsAndMetadata=false mode in impliesPoison() and clearing flags/metadata on visited instructions. Fixes https://github.com/llvm/llvm-project/issues/59888. Differential Revision: https://reviews.llvm.org/D142115
2022-12-30[NFC][IR] Remove unused assignment to OffsetAlfonso Gregory
This value is overwritten anyway, so let's remove it
2022-12-02[IR] Use std::nullopt instead of None (NFC)Kazu Hirata
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-02-02Cleanup header dependencies in LLVMCoreserge-sans-paille
Based on the output of include-what-you-use. This is a big chunk of changes. It is very likely to break downstream code unless they took a lot of care in avoiding hidden ehader dependencies, something the LLVM codebase doesn't do that well :-/ I've tried to summarize the biggest change below: - llvm/include/llvm-c/Core.h: no longer includes llvm-c/ErrorHandling.h - llvm/IR/DIBuilder.h no longer includes llvm/IR/DebugInfo.h - llvm/IR/IRBuilder.h no longer includes llvm/IR/IntrinsicInst.h - llvm/IR/LLVMRemarkStreamer.h no longer includes llvm/Support/ToolOutputFile.h - llvm/IR/LegacyPassManager.h no longer include llvm/Pass.h - llvm/IR/Type.h no longer includes llvm/ADT/SmallPtrSet.h - llvm/IR/PassManager.h no longer includes llvm/Pass.h nor llvm/Support/Debug.h And the usual count of preprocessed lines: $ clang++ -E -Iinclude -I../llvm/include ../llvm/lib/IR/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l before: 6400831 after: 6189948 200k lines less to process is no that bad ;-) Discourse thread on the topic: https://llvm.discourse.group/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D118652
2021-12-20[llvm] Construct SmallVector with iterator ranges (NFC)Kazu Hirata
2021-12-14Add FMF to hasPoisonGeneratingFlags/dropPoisonGeneratingFlagsPhilip Reames
These flags are documented as generating poison values for particular input values. As such, we should really be consistent about their handling with how we handle nsw/nuw/exact/inbounds. Differential Revision: https://reviews.llvm.org/D115460
2021-11-24[LoopVectorize] Propagate fast-math flags for VPInstructionRosie Sumpter
In-loop vector reductions which use the llvm.fmuladd intrinsic involve the creation of two recipes; a VPReductionRecipe for the fadd and a VPInstruction for the fmul. If the call to llvm.fmuladd has fast-math flags these should be propagated through to the fmul instruction, so an interface setFastMathFlags has been added to the VPInstruction class to enable this. Differential Revision: https://reviews.llvm.org/D113125
2021-10-27[Operator] Add hasPoisonGeneratingFlags [mostly NFC]Philip Reames
This method parallels the dropPoisonGeneratingFlags on Instruction, but is hoisted to operator to handle constant expressions as well. This is mostly code movement, but I did go ahead and add the inrange constexpr gep case. This had been discussed previously, but apparently never followed up o.
2021-10-18[DebugInfo] Correctly handle arrays with 0-width elements in GEP salvagingStephen Tozer
Fixes an issue where GEP salvaging did not properly account for GEP instructions which stepped over array elements of width 0 (effectively a no-op). This unnecessarily produced long expressions by appending `... + (x * 0)` and potentially extended the number of SSA values used in the dbg.value. This also erroneously triggered an assert in the salvage function that the element width would be strictly positive. These issues are resolved by simply ignoring these useless operands. Reviewed By: aprantl Differential Revision: https://reviews.llvm.org/D111809
2021-06-24Partial Reapply "[DebugInfo] Use variadic debug values to salvage BinOps and ↵Stephen Tozer
GEP instrs with non-const operands" This is a partial reapply of the original commit and the followup commit that were previously reverted; this reapply also includes a small fix for a potential source of non-determinism, but also has a small change to turn off variadic debug value salvaging, to ensure that any future revert/reapply steps to disable and renable this feature do not risk causing conflicts. Differential Revision: https://reviews.llvm.org/D91722 This reverts commit 386b66b2fc297cda121a3cc8a36887a6ecbcfc68.
2021-06-08Revert "3rd Reapply "[DebugInfo] Use variadic debug values to salvage BinOps ↵Hans Wennborg
and GEP instrs with non-const operands"" > This reapplies c0f3dfb9, which was reverted following the discovery of > crashes on linux kernel and chromium builds - these issues have since > been fixed, allowing this patch to re-land. This reverts commit 36ec97f76ac0d8be76fb16ac521f55126766267d. The change caused non-determinism in the compiler, see comments on the code review at https://reviews.llvm.org/D91722. Reverting to unbreak people's builds until that can be addressed. This also reverts the follow-up "[DebugInfo] Limit the number of values that may be referenced by a dbg.value" in a0bd6105d80698c53ceaa64bbe6e3b7e7bbf99ee.
2021-05-213rd Reapply "[DebugInfo] Use variadic debug values to salvage BinOps and GEP ↵Stephen Tozer
instrs with non-const operands" This reapplies c0f3dfb9, which was reverted following the discovery of crashes on linux kernel and chromium builds - these issues have since been fixed, allowing this patch to re-land. This reverts commit 4397b7095d640f9b9426c4d0135e999c5a1de1c5.
2021-04-30Revert "Re-reapply "[DebugInfo] Use variadic debug values to salvage BinOps ↵Nathan Chancellor
and GEP instrs with non-const operands"" This reverts commit 791930d74087b8ae8901172861a0fd21a211e436, as per https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy. I observed breakage with the Linux kernel, as reported at https://reviews.llvm.org/D91722#2724321 Fixes exist at https://reviews.llvm.org/D101523 https://reviews.llvm.org/D101540 but they have not landed so to unbreak the tree for the weekend, revert this commit. Commit b11e4c990771 ("Revert "[DebugInfo] Drop DBG_VALUE_LISTs with an excessive number of debug operands"") only reverted one follow-up fix, not the original patch that broke the kernel. e
2021-04-23Re-reapply "[DebugInfo] Use variadic debug values to salvage BinOps and GEP ↵Stephen Tozer
instrs with non-const operands" Previous build failures were caused by an error in bitcode reading and writing for DIArgList metadata, which has been fixed in e5d844b587. There were also some unnecessary asserts that were being triggered on certain builds, which have been removed. This reverts commit dad5caa59e6b2bde8d6cf5b64a972c393c526c82.
2021-04-12Revert "Reapply "[DebugInfo] Use variadic debug values to salvage BinOps and ↵Amy Huang
GEP instrs with non-const operands"" This change causes an assert / segmentation fault in LTO builds. This reverts commit f2e4f3eff3c9135d92840016f8ed4540cdd1313b.
2021-04-12Reapply "[DebugInfo] Use variadic debug values to salvage BinOps and GEP ↵Stephen Tozer
instrs with non-const operands" The causes of the previous build errors have been fixed in revisions aa3e78a59fdf3b211be72f1b3221af831665e67d, and 140757bfaaa00110a92d2247a910c847e6e3bcc8 This reverts commit f40976bd01032f4905dde361e709166704581077.
2021-03-11Revert "[DebugInfo] Use variadic debug values to salvage BinOps and GEP ↵Stephen Tozer
instrs with non-const operands" This reverts commit c0f3dfb9f119bb5f22dd8846f5502b6abaf026d3. Reverted due to an error on the clang-x64-windows-msvc buildbot.
2021-03-11[DebugInfo] Use variadic debug values to salvage BinOps and GEP instrs with ↵gbtozers
non-const operands This patch improves salvageDebugInfoImpl by allowing it to salvage arithmetic operations with two or more non-const operands; this includes the GetElementPtr instruction, and most Binary Operator instructions. These salvages produce DIArgList locations and are only valid for dbg.values, as currently variadic DIExpressions must use DW_OP_stack_value. This functionality is also only added for salvageDebugInfoForDbgValues; other functions that directly call salvageDebugInfoImpl (such as in ISel or Coroutine frame building) can be updated in a later patch. Differential Revision: https://reviews.llvm.org/D91722
2021-02-17[SROA] Propagate correct TBAA/TBAA Struct offsetsWilliam S. Moses
SROA does not correctly account for offsets in TBAA/TBAA struct metadata. This patch creates functionality for generating new MD with the corresponding offset and updates SROA to use this functionality. Differential Revision: https://reviews.llvm.org/D95826
2020-06-26Fix some clang-tidy namespace closing comments warnings. NFC.Simon Pilgrim
2020-06-19[AssumeBundles] add cannonicalisation to the assume builderTyker
Summary: this reduces significantly the number of assumes generated without aftecting too much the information that is preserved. this improves the compile-time cost of enable-knowledge-retention significantly. Reviewers: jdoerfert, sstefan1 Reviewed By: jdoerfert Subscribers: hiraditya, asbirlea, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D79650
2020-06-16Revert "[AssumeBundles] add cannonicalisation to the assume builder"Tyker
This reverts commit 90c50cad1983c5e29107a78382dead0fe2a9562c.
2020-06-16[AssumeBundles] add cannonicalisation to the assume builderTyker
Summary: this reduces significantly the number of assumes generated without aftecting too much the information that is preserved. this improves the compile-time cost of enable-knowledge-retention significantly. Reviewers: jdoerfert, sstefan1 Reviewed By: jdoerfert Subscribers: hiraditya, asbirlea, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D79650
2020-05-13[Attributor] Use AAValueConstantRange to infer dereferencability.Kuter Dinel
Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D76208
2020-04-23[SVE] Remove calls to isScalable from IRChristopher Tetreault
Reviewers: efriedma, sdesmalen, dexonsmith, dblaikie Reviewed By: sdesmalen Subscribers: tschuett, hiraditya, rkruppe, psnobl, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77691
2020-03-18[InstCombine] GEPOperator::accumulateConstantOffset does not support ↵Sander de Smalen
scalable vectors Avoid transforming: %0 = bitcast i8* %base to <vscale x 16 x i8>* %1 = getelementptr <vscale x 16 x i8>, <vscale x 16 x i8>* %0, i64 1 into: %0 = getelementptr i8, i8* %base, i64 16 %1 = bitcast i8* %0 to <vscale x 16 x i8>* Reviewers: efriedma, ctetreau Reviewed By: efriedma Tags: #llvm Differential Revision: https://reviews.llvm.org/D76236
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
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
2018-02-14Adding a width of the GEP index to the Data Layout.Elena Demikhovsky
Making a width of GEP Index, which is used for address calculation, to be one of the pointer properties in the Data Layout. p[address space]:size:memory_size:alignment:pref_alignment:index_size_in_bits. The index size parameter is optional, if not specified, it is equal to the pointer size. Till now, the InstCombiner normalized GEPs and extended the Index operand to the pointer width. It works fine if you can convert pointer to integer for address calculation and all registered targets do this. But some ISAs have very restricted instruction set for the pointer calculation. During discussions were desided to retrieve information for GEP index from the Data Layout. http://lists.llvm.org/pipermail/llvm-dev/2018-January/120416.html I added an interface to the Data Layout and I changed the InstCombiner and some other passes to take the Index width into account. This change does not affect any in-tree target. I added tests to cover data layouts with explicitly specified index size. Differential Revision: https://reviews.llvm.org/D42123 llvm-svn: 325102
2017-03-20[IR] Remove some unneeded includes from Operator.h and fix cpp files that ↵Craig Topper
were transitively depending on it. NFC llvm-svn: 298235
2017-03-20[IR] Add missing copyright header.Craig Topper
llvm-svn: 298234
2016-12-02IR: Change the gep_type_iterator API to avoid always exposing the "current" ↵Peter Collingbourne
type. Instead, expose whether the current type is an array or a struct, if an array what the upper bound is, and if a struct the struct type itself. This is in preparation for a later change which will make PointerType derive from Type rather than SequentialType. Differential Revision: https://reviews.llvm.org/D26594 llvm-svn: 288458
2016-01-19[opaque pointer types] [NFC] GEP: replace get(Pointer)ElementType uses with ↵Eduard Burtescu
get{Source,Result}ElementType. Summary: GEPOperator: provide getResultElementType alongside getSourceElementType. This is made possible by adding a result element type field to GetElementPtrConstantExpr, which GetElementPtrInst already has. GEP: replace get(Pointer)ElementType uses with get{Source,Result}ElementType. Reviewers: mjacob, dblaikie Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D16275 llvm-svn: 258145