aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Value.cpp
AgeCommit message (Collapse)AuthorFilesLines
2021-09-21[InstCombine] Improve TryToSinkInstruction with multiple usesAnna Thomas1-0/+12
This patch allows sinking an instruction which can have multiple uses in a single user. We were previously over-restrictive by looking for exactly one use, rather than one user. Also added an API for retrieving a unique undroppable user. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D109700
2021-09-19[llvm] Use pop_back_val (NFC)Kazu Hirata1-2/+1
2021-09-15Revert "[InstCombine] Improve TryToSinkInstruction with multiple uses"Anna Thomas1-12/+0
This reverts commit 4ac4e52189aa6d80c3d59dc2c8f7dcc0cb7f9d58. There are couple of test failures, which needs update of the test cases. Doing a clean revert and will recommit the change along with fixed testcases.
2021-09-15Re-add getSingleUndroppableUse APIAnna Thomas1-0/+12
The API was removed in 4ac4e52189aa in favor of getUniqueUndroppableUser. However, this caused a buildbot failure in AbstractCallSiteTest.cpp, which uses the API and the AbstractCallSite class requires a "use" rather than a user. Retain the API so that the unittest compiles and passes.
2021-09-15[InstCombine] Improve TryToSinkInstruction with multiple usesAnna Thomas1-6/+6
This patch allows sinking an instruction which can have multiple uses in a single user. We were previously over-restrictive by looking for exactly one use, rather than one user. Also, the API for retrieving undroppable user has been updated accordingly since in both usecases (Attributor and InstCombine), we seem to care about the user, rather than the use. Reviewed-By: nikic Differential Revision: https://reviews.llvm.org/D109700
2021-08-19[NFC] Replace some attribute methods that use confusing indexesArthur Eubanks1-3/+2
2021-07-14Global variables with strong definitions cannot be freedPhilip Reames1-0/+1
With the current deref semantics, this is redundant - since we assume that anything which is dereferenceable (ever) can't be freed - but it becomes neccessary for the deref-at-point semantics. Testing wise, this is covered by test/CodeGen/X86/hoist-invariant-load.ll when -use-dereferenceable-at-point-semantics is active. I didn't bother duplicating the command line since a) it's an in-development mode, and b) the change is pretty obvious.
2021-06-28[IR] Fix replaceUsesWithIf ponetial issue with constantsStanislav Mekhanoshin1-1/+11
There can be a use after free in the Value::replaceUsesWithIf() if two uses point to the same constant. Patch defers handling of the constants past the iterator scan. Another potential issue is that handleOperandChange updates all the uses in a given Constant, not just the one passed to ShouldReplace. Added a FIXME comment. Both issues are not currently exploitable as the only use of this call with constants avoids it. Differential Revision: https://reviews.llvm.org/D105061
2021-06-10[IR] Value: Fix OpCode checksSami Tolvanen1-3/+6
Value::SubclassID cannot be directly compared to Instruction enums, such as Instruction::{Call,Invoke,CallBr}. We have to first subtract InstructionVal from the SubclassID to get the OpCode, similar to Instruction::getOpCode(). Reviewed By: nickdesaulniers Differential Revision: https://reviews.llvm.org/D104043
2021-05-27Fix non-global-value-max-name-size not considered by LLParserHasyimi Bahrudin1-10/+0
`non-global-value-max-name-size` is used by `Value` to cap the length of local value name. However, this flag is not considered by `LLParser`, which leads to unexpected `use of undefined value error`. The fix is to move the responsibility of capping the length to `ValueSymbolTable`. The test is the one provided by [[ https://bugs.llvm.org/show_bug.cgi?id=45899 | Mikael in the bug report ]]. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D102707
2021-05-25[IR] Allow Value::replaceUsesWithIf() to process constantsStanislav Mekhanoshin1-0/+23
The change is currently NFC, but exploited by the depending D102954. Code to handle constants is borrowed from the general implementation of Value::doRAUW(). Differential Revision: https://reviews.llvm.org/D103051
2021-04-29[CodeGen] don't emit addrsig symbol if it's used only by metadataZequan Wu1-0/+21
Value only used by metadata can be removed from .addrsig table. This solves the undefined symbol error when enabling addrsig table on COFF LTO. Differential Revision: https://reviews.llvm.org/D101512
2021-04-20[NFC] Restructure code to make it possible to insert other GCsMax Kazantsev1-18/+17
2021-04-19[DebugInfo] Replace debug uses in replaceUsesOutsideBlockOCHyams1-0/+13
Value::replaceUsesOutsideBlock doesn't replace debug uses which leads to an unnecessary reduction in variable location coverage. Fix this, add a unittest for it, and add a regression test demonstrating the change through instcombine's replacedSelectWithOperand. Reviewed By: djtodoro Differential Revision: https://reviews.llvm.org/D99169
2021-04-16[nofree] Restrict semantics to memory visible to callerPhilip Reames1-7/+10
This patch clarifies the semantics of the nofree function attribute to make clear that it provides an "as if" semantic. That is, a nofree function is guaranteed not to free memory which existed before the call, but might allocate and then deallocate that same memory within the lifetime of the callee. This is the result of the discussion on llvm-dev under the thread "Ambiguity in the nofree function attribute". The most important part of this change is the LangRef wording. The rest is minor comment changes to emphasize the new semantics where code was accidentally consistent, and fix one place which wasn't consistent. That one place is currently narrowly used as it is primarily part of the ongoing (and not yet enabled) deref-at-point semantics work. Differential Revision: https://reviews.llvm.org/D100141
2021-04-15Revert "[DebugInfo] Replace debug uses in replaceUsesOutsideBlock"OCHyams1-13/+0
This reverts commit 96a1e6b7cf72d9bd625903ea4b441404200383cf. Failing build bots e.g. https://lab.llvm.org/buildbot/#/builders/161/builds/163
2021-04-15[DebugInfo] Replace debug uses in replaceUsesOutsideBlockOCHyams1-0/+13
Value::replaceUsesOutsideBlock doesn't replace debug uses which leads to an unnecessary reduction in variable location coverage. Fix this, add a unittest for it, and add a regression test demonstrating the change through instcombine's replacedSelectWithOperand. Reviewed By: djtodoro Differential Revision: https://reviews.llvm.org/D99169
2021-04-06Use AssumeInst in a few more places [nfc]Philip Reames1-2/+1
Follow up to a6d2a8d6f5. These were found by simply grepping for "::assume", and are the subset of that result which looked cleaner to me using the isa/dyn_cast patterns.
2021-04-06Move GCRelocateInst and GCResultInst to IntrinsicInst.h [nfc]Philip Reames1-1/+0
These two are part of the IntrinsicInst class hierarchy and it helps to cut down on some redundant includes.
2021-04-01[deref-at-point] restrict inference of dereferenceability based on allocsize ↵Philip Reames1-12/+8
attribute Support deriving dereferenceability facts from allocation sites with known object sizes while correctly accounting for any possibly frees between allocation and use site. (At the moment, we're conservative and only allowing it in functions where we know we can't free.) This is part of the work on deref-at-point semantics. I'm making the change unconditional as the miscompile in this case is way too easy to trip by accident, and the optimization was only recently added (by me). There will be a follow up patch wiring through TLI since that should now be doable without introducing widespread miscompiles. Differential Revision: https://reviews.llvm.org/D95815
2021-03-25[deref] Handle byval/byref/sret/inalloc/preallocated arguments for ↵Philip Reames1-0/+6
deref-at-point semantics All of these are scoped allocations which remain dereferenceable during the lifetime of the callee. Differential Revision: https://reviews.llvm.org/D99310
2021-03-24[deref] Implement initial set of inference rules for deref-at-pointPhilip Reames1-2/+59
This implements a subset of the initial set of inference rules proposed in the llvm-dev thread "RFC: Decomposing deref(N) into deref(N) + nofree". The nolias one got moved to a separate review as there was some concerns raised which require further discussion. Differential Revision: https://reviews.llvm.org/D99135
2021-03-19Update basic deref API to account for possiblity of free [NFC]Philip Reames1-1/+10
This patch is plumbing to support work towards the goal outlined in the recent llvm-dev post "[llvm-dev] RFC: Decomposing deref(N) into deref(N) + nofree". The point of this change is purely to simplify iteration on other pieces on way to making the switch. Rebuilding with a change to Value.h is slow and painful, so I want to get the API change landed. Once that's done, I plan to more closely audit each caller, add the inference rules in their own patch, then post a patch with the langref changes and test diffs. The value of the command line flag is that we can exercise the inference logic in standalone patches without needing the whole switch ready to go just yet. Differential Revision: https://reviews.llvm.org/D98908
2021-02-18[BasicAA] Always strip single-argument phi nodesNikita Popov1-5/+8
We can always look through single-argument (LCSSA) phi nodes when performing alias analysis. getUnderlyingObject() already does this, but stripPointerCastsAndInvariantGroups() does not. We still look through these phi nodes with the usual aliasPhi() logic, but sometimes get sub-optimal results due to the restrictions on value equivalence when looking through arbitrary phi nodes. I think it's generally beneficial to keep the underlying object logic and the pointer cast stripping logic in sync, insofar as it is possible. With this patch we get marginally better results: aa.NumMayAlias | 5010069 | 5009861 aa.NumMustAlias | 347518 | 347674 aa.NumNoAlias | 27201336 | 27201528 ... licm.NumPromoted | 1293 | 1296 I've renamed the relevant strip method to stripPointerCastsForAliasAnalysis(), as we're past the point where we can explicitly spell out everything that's getting stripped. Differential Revision: https://reviews.llvm.org/D96668
2021-01-11[NFC][LICM] Minor improvements to debug outputQuentin Colombet1-0/+12
Added a utility function in Value class to print block name and use block labels for unnamed blocks. Changed LICM to call this function in its debug output. Patch by Xiaoqing Wu <xiaoqing_wu@apple.com> Differential Revision: https://reviews.llvm.org/D93577
2020-10-23[IR] Merge metadata manipulation code into ValueSerge Pavlov1-3/+7
Now there are two main classes in Value hierarchy, which support metadata, these are Instruction and GlobalObject. They implement different APIs for metadata manipulation, which however overlap. This change moves metadata manipulation code into Value, so descendant classes can use this code for their operations on metadata. No functional changes intended. Differential Revision: https://reviews.llvm.org/D67626
2020-09-24IR: Have byref imply dereferenceableMatt Arsenault1-4/+9
The langref already states it does, but this wasn't implemented. Also covers inalloca and preallocated. Also helps fix a dependence on pointer element types.
2020-09-24OpaquePtr: Add helpers for sret to mirror byvalMatt Arsenault1-1/+1
Sret should really have a type parameter like byval does.
2020-08-28[SROA] Improve handleling of assumes bundles by SROATyker1-1/+1
This patch fixes this crash https://gcc.godbolt.org/z/Ps8d1e And gives SROA the ability to remove assumes if it allows promoting an alloca to register Without removing assumes when it can't promote to register. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D86570
2020-08-26[Value][InstCombine] Fix one-use checks in PHI-of-op -> Op-of-PHI[s] ↵Roman Lebedev1-0/+8
transforms to be one-user checks As FIXME said, they really should be checking for a single user, not use, so let's do that. It is not *that* unusual to have the same value as incoming value in a PHI node, not unlike how a PHI may have the same incoming basic block more than once. There isn't a nice way to do that, Value::users() isn't uniqified, and Value only tracks it's uses, not Users, so the check is potentially costly since it does indeed potentially involes traversing the entire use list of a value.
2020-07-28[SROA][Mem2Reg] Use efficient droppable use API (after D83976)Johannes Doerfert1-16/+25
Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D84804
2020-07-24[Mem2Reg] Teach promote to register about droppable instructionsJohannes Doerfert1-0/+4
This is the first of two patches to address PR46753. We basically allow mem2reg to promote allocas that are used in doppable instructions, for now that means `llvm.assume`. The uses of the alloca (or a bitcast or zero offset GEP from there) are replaced by `undef` in the droppable instructions. Reviewed By: Tyker Differential Revision: https://reviews.llvm.org/D83976
2020-06-30[IR] Delete llvm::Constants using the correct type.Eli Friedman1-0/+4
In most cases, this doesn't have much impact: the destructors just call the base class destructor anyway. A few subclasses of ConstantExpr actually store non-trivial data, though. Make sure we clean up appropriately. This is sort of ugly, but I don't see a good alternative given the constraints. Issue found by asan buildbots running the testcase for D80330. Differential Revision: https://reviews.llvm.org/D82509
2020-06-29[Alignment][NFC] migrate DataLayout::getPreferredAlignmentGuillaume Chatelet1-1/+1
This patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Differential Revision: https://reviews.llvm.org/D82752
2020-06-25[IR] GetUnderlyingObject(), stripPointerCastsAndOffsets(): don't crash on ↵Roman Lebedev1-0/+2
`bitcast <1 x i8*> to i8*` I'm not sure how to write standalone tests for each of two changes here. If either one of these two fixes is missing, the test fill crash.
2020-06-19try to fix build bot after b7338fb1a6a464472850211165391983d2c8fdf3Tyker1-1/+3
2020-06-19[AssumeBundles] add cannonicalisation to the assume builderTyker1-3/+7
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"Tyker1-7/+3
This reverts commit 90c50cad1983c5e29107a78382dead0fe2a9562c.
2020-06-16[AssumeBundles] add cannonicalisation to the assume builderTyker1-3/+7
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-20Make Value::getPointerAlignment() return an Align, not a MaybeAlign.Eli Friedman1-19/+12
If we don't know anything about the alignment of a pointer, Align(1) is still correct: all pointers are at least 1-byte aligned. Included in this patch is a bugfix for an issue discovered during this cleanup: pointers with "dereferenceable" attributes/metadata were assumed to be aligned according to the type of the pointer. This wasn't intentional, as far as I can tell, so Loads.cpp was fixed to stop making this assumption. Frontends may need to be updated. I updated clang's handling of C++ references, and added a release note for this. Differential Revision: https://reviews.llvm.org/D80072
2020-05-15[IR] Trivial cleanups in Use. NFC.Jay Foad1-2/+2
Remove Use::setPrev. It provided no value because it had the same accessibility as the underlying field Prev, and there was no corresponding setNext anyway. Simplify Use::removeFromList.
2020-05-13[Attributor] Use AAValueConstantRange to infer dereferencability.Kuter Dinel1-5/+18
Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D76208
2020-04-12NFC: Clean up the implementation of StringPool a bit, and remove dependence ↵Chris Lattner1-3/+6
on some "implicitly MallocAllocator" based methods on StringMapEntry. This allows reducing the #includes in StringMapEntry.h. Summary: StringPool has many caveats and isn't used in the monorepo. I will propose removing it as a patch separate from this refactoring patch. Reviewers: rriddle Subscribers: hiraditya, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77976
2020-04-03[Alignment][NFC] Deprecate InstrTypes getRetAlignment/getParamAlignmentGuillaume Chatelet1-5/+5
Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77312
2020-03-18[AliasAnalysis] Misc fixes for checking aliasing with scalable types.Eli Friedman1-3/+4
This is fixing up various places that use the implicit TypeSize->uint64_t conversion. The new overloads in MemoryLocation.h are already used in various places that construct a MemoryLocation from a TypeSize, including MemorySSA. (They were using the implicit conversion before.) Differential Revision: https://reviews.llvm.org/D76249
2020-03-12Basis of dropping uses in llvm.assume.Tyker1-0/+45
Summary: This patch adds the basic utilities to deal with dropable uses. dropable uses are uses that we rather drop than prevent transformations, for now they are limited to uses in llvm.assume. Reviewers: jdoerfert, sstefan1 Reviewed By: jdoerfert Subscribers: uenoku, lebedev.ri, mgorny, hiraditya, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D73404
2020-02-06Fix MSAN failure on Function destructionEvgenii Stepanov1-2/+6
Summary: When Function is destroyed, GlobalValue base class is destroyed, then Value destructor would call use_empty, which ultimately attempts to downcast 'this' to GlobalValue. This is UB, and is caught my MSAN as accessing uninitialized memory. Call materialized_use_empty, which doesn't call assertModuleIsMaterializedImpl(). Reviewers: eugenis Reviewed By: eugenis Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D74161 Patch by Antonio Maiorano.
2020-01-22[IR] Value::getPointerAlignment(): handle pointer constantsRoman Lebedev1-0/+11
Summary: New `@test13` in `Attributor/align.ll` is the main motivation - `null` pointer really does not limit our alignment knowledge, in fact it is fully aligned since it has no bits set. Here we don't special-case `null` pointer because it is somewhat controversial to add one more place where we enforce that `null` pointer is zero, but instead we do the more general thing of trying to perform constant-fold of pointer constant to an integer, and perform alignment inferrment on that. Reviewers: jdoerfert, gchatelet, courbet, sstefan1 Reviewed By: jdoerfert Subscribers: hiraditya, arphaman, jfb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D73131
2019-11-14Add missing includes needed to prune LLVMContext.h include, NFCReid Kleckner1-1/+2
These are a pre-requisite to removing #include "llvm/Support/Options.h" from LLVMContext.h: https://reviews.llvm.org/D70280
2019-10-15[Alignment][NFC] Value::getPointerAlignment returns MaybeAlignGuillaume Chatelet1-23/+23
Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet, jdoerfert Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68398 llvm-svn: 374889