aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Instructions.cpp
AgeCommit message (Collapse)AuthorFilesLines
2021-09-21[IR] Look through bitcast in hasFnAttribute()Antonio Frighetto1-2/+14
A logic incompleteness may lead MemorySSA to be too conservative in its results. Specifically, when dealing with a call of kind `call i32 bitcast (i1 (i1)* @test to i32 (i32)*)(i32 %1)`, where the function `test` is declared with readonly attribute, the bitcast is not looked through, obscuring function attributes. Hence, some methods of CallBase (e.g., doesNotReadMemory) could provide suboptimal results. Differential Revision: https://reviews.llvm.org/D109888
2021-09-21[IR] Add the constructor of ShuffleVector for one-input-vector.hyeongyu kim1-0/+26
One of the two inputs of the Shufflevector is often a placeholder. Previously, there were cases where the placeholder was undef, and there were cases where it was poison. I added these constructors to create a placeholder consistently. Changing to use the newly added constructor will be written in a separate patch. Reviewed By: spatel Differential Revision: https://reviews.llvm.org/D110146
2021-09-09[APInt] Normalize naming on keep constructors / predicate methods.Chris Lattner1-3/+3
This renames the primary methods for creating a zero value to `getZero` instead of `getNullValue` and renames predicates like `isAllOnesValue` to simply `isAllOnes`. This achieves two things: 1) This starts standardizing predicates across the LLVM codebase, following (in this case) ConstantInt. The word "Value" doesn't convey anything of merit, and is missing in some of the other things. 2) Calling an integer "null" doesn't make any sense. The original sin here is mine and I've regretted it for years. This moves us to calling it "zero" instead, which is correct! APInt is widely used and I don't think anyone is keen to take massive source breakage on anything so core, at least not all in one go. As such, this doesn't actually delete any entrypoints, it "soft deprecates" them with a comment. Included in this patch are changes to a bunch of the codebase, but there are more. We should normalize SelectionDAG and other APIs as well, which would make the API change more mechanical. Differential Revision: https://reviews.llvm.org/D109483
2021-09-07Don't check if the result of hasAttrSomewhere is non-zero in ↵Arthur Eubanks1-3/+2
CallBase::getReturnedArgOperand() Index is 0 when the return value has the returned attribute. But the return value cannot have the returned attribute, so the check is pointless. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D109334
2021-08-19[NFC] Replace some attribute methods that use confusing indexesArthur Eubanks1-3/+2
2021-08-13[NFC] Rename AttributeList::hasFnAttribute() -> hasFnAttr()Arthur Eubanks1-2/+2
This is more consistent with similar methods.
2021-08-13[NFC] Remove AttributeList::hasParamAttribute()Arthur Eubanks1-2/+2
It's the same as AttributeList::hasParamAttr().
2021-08-02[TTI] Add basic SK_InsertSubvector shuffle mask recognitionSimon Pilgrim1-0/+74
This patch adds an initial ShuffleVectorInst::isInsertSubvectorMask helper to recognize 2-op shuffles where the lowest elements of one of the sources are being inserted into the "in-place" other operand, this includes "concat_vectors" patterns as can be seen in the Arm shuffle cost changes. This also helped fix a x86 issue with irregular/length-changing SK_InsertSubvector costs - I'm hoping this will help with D107188 This doesn't currently attempt to work with 1-op shuffles that could either be a "widening" shuffle or a self-insertion. The self-insertion case is tricky, but we currently always match this with the existing SK_PermuteSingleSrc logic. The widening case will be addressed in a follow up patch that treats the cost as 0. Masks with a high number of undef elts will still struggle to match optimal subvector widths - its currently bounded by minimum-width possible insertion, whilst some cases would benefit from wider (pow2?) subvectors. Differential Revision: https://reviews.llvm.org/D107228
2021-07-13[InstCombine] Precommit tests for D105088 (NFC)Krishna Kariya1-0/+8
Add tests for D105088, as well as an option to disable the (generally) unsound inttoptr of ptrtoint optimization. Differential Revision: https://reviews.llvm.org/D105771
2021-07-04[NFC] Fix a few whitespace issues and typos.Paul Walker1-0/+1
2021-06-28IR: Fix use-list-order round-tripping for brDuncan P. N. Exon Smith1-5/+8
Fix the use-list-order for br instructions by setting the operands in order of their index to match the use-list-order prediction. The case where this matters is when there is a condition but the if-true and if-false branches are identical. Bug was found when reviewing failures pointed at by https://reviews.llvm.org/D104950. Fix is similar to 3cf415c6c367ced43175ebd1dc4bd9582c7f5376. Differential Revision: https://reviews.llvm.org/D104959
2021-06-24Partial Reapply "[DebugInfo] Use variadic debug values to salvage BinOps and ↵Stephen Tozer1-0/+9
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-23IR: Fix use-list-order round-tripping for call and invokeDuncan P. N. Exon Smith1-9/+15
Fix the use-list-order for call and invoke instructions by setting the operands in order of their index. This matches the use-list-order prediction. Note that the verifier precludes sharing operands in callbr (so there was no bug to fix), but that code was updated for consistency. Bug was found during review of https://reviews.llvm.org/D104740. Differential Revision: https://reviews.llvm.org/D104805
2021-06-22[OpaquePtr] Handle addrspacecasts in InstCombineNikita Popov1-3/+5
This adds support for addrspace casts involving opaque pointers to InstCombine, as well as the isEliminableCastPair() helper (otherwise the assertion failure would just move there). Add PointerType::hasSameElementTypeAs() to hide the element type details. Differential Revision: https://reviews.llvm.org/D104668
2021-06-08Revert "3rd Reapply "[DebugInfo] Use variadic debug values to salvage BinOps ↵Hans Wennborg1-9/+0
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-25[OpaquePtr] Make atomicrmw work with opaque pointersArthur Eubanks1-3/+3
FullTy is only necessary when we need to figure out what type an instruction works with given a pointer's pointee type. However, we just end up using the value operand's type, so FullTy isn't necessary. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D102788
2021-05-25Revert "[OpaquePtr] Make atomicrmw work with opaque pointers"Arthur Eubanks1-3/+3
This reverts commit 0bebda17bea38785c90a6fec3ca01cf74eb78b7c. Causing "Invalid record" errors.
2021-05-21[Verifier] Move some atomicrmw/cmpxchg checks to instruction creationArthur Eubanks1-7/+0
These checks already exist as asserts when creating the corresponding instruction. Anybody creating these instructions already need to take care to not break these checks. Move the checks for success/failure ordering in cmpxchg from the verifier to the LLParser and BitcodeReader plus an assert. Add some tests for cmpxchg ordering. The .bc files are created from the .ll files with an llvm-as with these checks disabled. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D102803
2021-05-213rd Reapply "[DebugInfo] Use variadic debug values to salvage BinOps and GEP ↵Stephen Tozer1-0/+9
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-05-19[OpaquePtr] Make atomicrmw work with opaque pointersArthur Eubanks1-3/+3
FullTy is only necessary when we need to figure out what type an instruction works with given a pointer's pointee type. However, we just end up using the value operand's type, so FullTy isn't necessary. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D102788
2021-05-19[OpaquePtr] Make cmpxchg work with opaque pointersArthur Eubanks1-6/+8
Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D102745
2021-05-18[OpaquePtr] Make loads and stores work with opaque pointersArthur Eubanks1-5/+5
Don't check that types match when the pointer operand is an opaque pointer. I would separate the Assembler and Verifier changes, but verify-uselistorder in the Assembler test ends up running the verifier. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D102450
2021-05-06[CGAtomic] Lift strong requirement for remaining compare_exchange combinationsBruno Cardoso Lopes1-3/+0
Follow up on 431e3138a and complete the other possible combinations. Besides enforcing the new behavior, it also mitigates TSAN false positives when combining orders that used to be stronger.
2021-04-30Revert "Re-reapply "[DebugInfo] Use variadic debug values to salvage BinOps ↵Nathan Chancellor1-9/+0
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 Tozer1-0/+9
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 Huang1-9/+0
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 Tozer1-0/+9
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-29[SampleFDO] Do not scale the magic number NOMORE_ICP_MAGICNUM in value profileWei Mi1-4/+10
during profile update. When we inline a function and update the profile, the value profiles of the indirect call in the inliner and inlinee will be scaled. In https://reviews.llvm.org/D96806 and https://reviews.llvm.org/D97350, we start using the magic number NOMORE_ICP_MAGICNUM (-1) to mark targets which have been promoted. The magic number shouldn't be scaled during the profile update. Although the problem has been suppressed by https://reviews.llvm.org/D98187 for SampleFDO, which stops profile update for inlining in sampleFDO, the patch is still wanted since it will be more consistent to handle the magic number properly in profile update. Differential Revision: https://reviews.llvm.org/D99394
2021-03-25[IR] Lift attribute handling for assume bundles into CallBaseNikita Popov1-0/+7
Rather than special-casing assume in BasicAA getModRefBehavior(), do this one level higher, in the attribute handling of CallBase. For assumes with operand bundles, the inaccessiblememonly attribute applies regardless of operand bundles.
2021-03-11Revert "[DebugInfo] Use variadic debug values to salvage BinOps and GEP ↵Stephen Tozer1-9/+0
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 ↵gbtozers1-0/+9
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-03-04[ObjC][ARC] Use operand bundle 'clang.arc.attachedcall' instead ofAkira Hatanaka1-0/+29
explicitly emitting retainRV or claimRV calls in the IR This reapplies ed4718eccb12bd42214ca4fb17d196d49561c0c7, which was reverted because it was causing a miscompile. The bug that was causing the miscompile has been fixed in 75805dce5ff874676f3559c069fcd6737838f5c0. Original commit message: Background: This fixes a longstanding problem where llvm breaks ARC's autorelease optimization (see the link below) by separating calls from the marker instructions or retainRV/claimRV calls. The backend changes are in https://reviews.llvm.org/D92569. https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autoreleasereturnvalue What this patch does to fix the problem: - The front-end adds operand bundle "clang.arc.attachedcall" to calls, which indicates the call is implicitly followed by a marker instruction and an implicit retainRV/claimRV call that consumes the call result. In addition, it emits a call to @llvm.objc.clang.arc.noop.use, which consumes the call result, to prevent the middle-end passes from changing the return type of the called function. This is currently done only when the target is arm64 and the optimization level is higher than -O0. - ARC optimizer temporarily emits retainRV/claimRV calls after the calls with the operand bundle in the IR and removes the inserted calls after processing the function. - ARC contract pass emits retainRV/claimRV calls after the call with the operand bundle. It doesn't remove the operand bundle on the call since the backend needs it to emit the marker instruction. The retainRV and claimRV calls are emitted late in the pipeline to prevent optimization passes from transforming the IR in a way that makes it harder for the ARC middle-end passes to figure out the def-use relationship between the call and the retainRV/claimRV calls (which is the cause of PR31925). - The function inliner removes an autoreleaseRV call in the callee if nothing in the callee prevents it from being paired up with the retainRV/claimRV call in the caller. It then inserts a release call if claimRV is attached to the call since autoreleaseRV+claimRV is equivalent to a release. If it cannot find an autoreleaseRV call, it tries to transfer the operand bundle to a function call in the callee. This is important since the ARC optimizer can remove the autoreleaseRV returning the callee result, which makes it impossible to pair it up with the retainRV/claimRV call in the caller. If that fails, it simply emits a retain call in the IR if retainRV is attached to the call and does nothing if claimRV is attached to it. - SCCP refrains from replacing the return value of a call with a constant value if the call has the operand bundle. This ensures the call always has at least one user (the call to @llvm.objc.clang.arc.noop.use). - This patch also fixes a bug in replaceUsesOfNonProtoConstant where multiple operand bundles of the same kind were being added to a call. Future work: - Use the operand bundle on x86-64. - Fix the auto upgrader to convert call+retainRV/claimRV pairs into calls with the operand bundles. rdar://71443534 Differential Revision: https://reviews.llvm.org/D92808
2021-03-03Sink routine for replacing a operand bundle to CallBase [NFC]Philip Reames1-25/+13
We had equivalent code for both CallInst and InvokeInst, but never cared about the result type.
2021-03-03Revert "[ObjC][ARC] Use operand bundle 'clang.arc.attachedcall' instead of ↵Hans Wennborg1-29/+0
explicitly emitting retainRV or claimRV calls in the IR" This caused miscompiles of Chromium tests for iOS due clobbering of live registers. See discussion on the code review for details. > Background: > > This fixes a longstanding problem where llvm breaks ARC's autorelease > optimization (see the link below) by separating calls from the marker > instructions or retainRV/claimRV calls. The backend changes are in > https://reviews.llvm.org/D92569. > > https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autoreleasereturnvalue > > What this patch does to fix the problem: > > - The front-end adds operand bundle "clang.arc.attachedcall" to calls, > which indicates the call is implicitly followed by a marker > instruction and an implicit retainRV/claimRV call that consumes the > call result. In addition, it emits a call to > @llvm.objc.clang.arc.noop.use, which consumes the call result, to > prevent the middle-end passes from changing the return type of the > called function. This is currently done only when the target is arm64 > and the optimization level is higher than -O0. > > - ARC optimizer temporarily emits retainRV/claimRV calls after the calls > with the operand bundle in the IR and removes the inserted calls after > processing the function. > > - ARC contract pass emits retainRV/claimRV calls after the call with the > operand bundle. It doesn't remove the operand bundle on the call since > the backend needs it to emit the marker instruction. The retainRV and > claimRV calls are emitted late in the pipeline to prevent optimization > passes from transforming the IR in a way that makes it harder for the > ARC middle-end passes to figure out the def-use relationship between > the call and the retainRV/claimRV calls (which is the cause of > PR31925). > > - The function inliner removes an autoreleaseRV call in the callee if > nothing in the callee prevents it from being paired up with the > retainRV/claimRV call in the caller. It then inserts a release call if > claimRV is attached to the call since autoreleaseRV+claimRV is > equivalent to a release. If it cannot find an autoreleaseRV call, it > tries to transfer the operand bundle to a function call in the callee. > This is important since the ARC optimizer can remove the autoreleaseRV > returning the callee result, which makes it impossible to pair it up > with the retainRV/claimRV call in the caller. If that fails, it simply > emits a retain call in the IR if retainRV is attached to the call and > does nothing if claimRV is attached to it. > > - SCCP refrains from replacing the return value of a call with a > constant value if the call has the operand bundle. This ensures the > call always has at least one user (the call to > @llvm.objc.clang.arc.noop.use). > > - This patch also fixes a bug in replaceUsesOfNonProtoConstant where > multiple operand bundles of the same kind were being added to a call. > > Future work: > > - Use the operand bundle on x86-64. > > - Fix the auto upgrader to convert call+retainRV/claimRV pairs into > calls with the operand bundles. > > rdar://71443534 > > Differential Revision: https://reviews.llvm.org/D92808 This reverts commit ed4718eccb12bd42214ca4fb17d196d49561c0c7.
2021-02-27[IR] Use range-based for loops (NFC)Kazu Hirata1-5/+5
2021-02-12[ObjC][ARC] Use operand bundle 'clang.arc.attachedcall' instead ofAkira Hatanaka1-0/+29
explicitly emitting retainRV or claimRV calls in the IR Background: This fixes a longstanding problem where llvm breaks ARC's autorelease optimization (see the link below) by separating calls from the marker instructions or retainRV/claimRV calls. The backend changes are in https://reviews.llvm.org/D92569. https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autoreleasereturnvalue What this patch does to fix the problem: - The front-end adds operand bundle "clang.arc.attachedcall" to calls, which indicates the call is implicitly followed by a marker instruction and an implicit retainRV/claimRV call that consumes the call result. In addition, it emits a call to @llvm.objc.clang.arc.noop.use, which consumes the call result, to prevent the middle-end passes from changing the return type of the called function. This is currently done only when the target is arm64 and the optimization level is higher than -O0. - ARC optimizer temporarily emits retainRV/claimRV calls after the calls with the operand bundle in the IR and removes the inserted calls after processing the function. - ARC contract pass emits retainRV/claimRV calls after the call with the operand bundle. It doesn't remove the operand bundle on the call since the backend needs it to emit the marker instruction. The retainRV and claimRV calls are emitted late in the pipeline to prevent optimization passes from transforming the IR in a way that makes it harder for the ARC middle-end passes to figure out the def-use relationship between the call and the retainRV/claimRV calls (which is the cause of PR31925). - The function inliner removes an autoreleaseRV call in the callee if nothing in the callee prevents it from being paired up with the retainRV/claimRV call in the caller. It then inserts a release call if claimRV is attached to the call since autoreleaseRV+claimRV is equivalent to a release. If it cannot find an autoreleaseRV call, it tries to transfer the operand bundle to a function call in the callee. This is important since the ARC optimizer can remove the autoreleaseRV returning the callee result, which makes it impossible to pair it up with the retainRV/claimRV call in the caller. If that fails, it simply emits a retain call in the IR if retainRV is attached to the call and does nothing if claimRV is attached to it. - SCCP refrains from replacing the return value of a call with a constant value if the call has the operand bundle. This ensures the call always has at least one user (the call to @llvm.objc.clang.arc.noop.use). - This patch also fixes a bug in replaceUsesOfNonProtoConstant where multiple operand bundles of the same kind were being added to a call. Future work: - Use the operand bundle on x86-64. - Fix the auto upgrader to convert call+retainRV/claimRV pairs into calls with the operand bundles. rdar://71443534 Differential Revision: https://reviews.llvm.org/D92808
2021-02-09Revert "[ObjC][ARC] Use operand bundle 'clang.arc.rv' instead of explicitly"Nico Weber1-29/+0
This reverts commit 4a64d8fe392449b205e59031aad5424968cf7446. Makes clang crash when buildling trivial iOS programs, see comment after https://reviews.llvm.org/D92808#2551401
2021-02-05[ObjC][ARC] Use operand bundle 'clang.arc.rv' instead of explicitlyAkira Hatanaka1-0/+29
emitting retainRV or claimRV calls in the IR This reapplies 3fe3946d9a958b7af6130241996d9cfcecf559d4 without the changes made to lib/IR/AutoUpgrade.cpp, which was violating layering. Original commit message: Background: This patch makes changes to the front-end and middle-end that are needed to fix a longstanding problem where llvm breaks ARC's autorelease optimization (see the link below) by separating calls from the marker instructions or retainRV/claimRV calls. The backend changes are in https://reviews.llvm.org/D92569. https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autoreleasereturnvalue What this patch does to fix the problem: - The front-end adds operand bundle "clang.arc.rv" to calls, which indicates the call is implicitly followed by a marker instruction and an implicit retainRV/claimRV call that consumes the call result. In addition, it emits a call to @llvm.objc.clang.arc.noop.use, which consumes the call result, to prevent the middle-end passes from changing the return type of the called function. This is currently done only when the target is arm64 and the optimization level is higher than -O0. - ARC optimizer temporarily emits retainRV/claimRV calls after the calls with the operand bundle in the IR and removes the inserted calls after processing the function. - ARC contract pass emits retainRV/claimRV calls after the call with the operand bundle. It doesn't remove the operand bundle on the call since the backend needs it to emit the marker instruction. The retainRV and claimRV calls are emitted late in the pipeline to prevent optimization passes from transforming the IR in a way that makes it harder for the ARC middle-end passes to figure out the def-use relationship between the call and the retainRV/claimRV calls (which is the cause of PR31925). - The function inliner removes an autoreleaseRV call in the callee if nothing in the callee prevents it from being paired up with the retainRV/claimRV call in the caller. It then inserts a release call if the call is annotated with claimRV since autoreleaseRV+claimRV is equivalent to a release. If it cannot find an autoreleaseRV call, it tries to transfer the operand bundle to a function call in the callee. This is important since ARC optimizer can remove the autoreleaseRV returning the callee result, which makes it impossible to pair it up with the retainRV/claimRV call in the caller. If that fails, it simply emits a retain call in the IR if the implicit call is a call to retainRV and does nothing if it's a call to claimRV. Future work: - Use the operand bundle on x86-64. - Fix the auto upgrader to convert call+retainRV/claimRV pairs into calls annotated with the operand bundles. rdar://71443534 Differential Revision: https://reviews.llvm.org/D92808
2021-02-05Revert "[ObjC][ARC] Use operand bundle 'clang.arc.rv' instead of explicitly"Akira Hatanaka1-29/+0
This reverts commit 3fe3946d9a958b7af6130241996d9cfcecf559d4. The commit violates layering by including a header from Analysis in lib/IR/AutoUpgrade.cpp.
2021-02-05[ObjC][ARC] Use operand bundle 'clang.arc.rv' instead of explicitlyAkira Hatanaka1-0/+29
emitting retainRV or claimRV calls in the IR Background: This patch makes changes to the front-end and middle-end that are needed to fix a longstanding problem where llvm breaks ARC's autorelease optimization (see the link below) by separating calls from the marker instructions or retainRV/claimRV calls. The backend changes are in https://reviews.llvm.org/D92569. https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autoreleasereturnvalue What this patch does to fix the problem: - The front-end adds operand bundle "clang.arc.rv" to calls, which indicates the call is implicitly followed by a marker instruction and an implicit retainRV/claimRV call that consumes the call result. In addition, it emits a call to @llvm.objc.clang.arc.noop.use, which consumes the call result, to prevent the middle-end passes from changing the return type of the called function. This is currently done only when the target is arm64 and the optimization level is higher than -O0. - ARC optimizer temporarily emits retainRV/claimRV calls after the calls with the operand bundle in the IR and removes the inserted calls after processing the function. - ARC contract pass emits retainRV/claimRV calls after the call with the operand bundle. It doesn't remove the operand bundle on the call since the backend needs it to emit the marker instruction. The retainRV and claimRV calls are emitted late in the pipeline to prevent optimization passes from transforming the IR in a way that makes it harder for the ARC middle-end passes to figure out the def-use relationship between the call and the retainRV/claimRV calls (which is the cause of PR31925). - The function inliner removes an autoreleaseRV call in the callee if nothing in the callee prevents it from being paired up with the retainRV/claimRV call in the caller. It then inserts a release call if the call is annotated with claimRV since autoreleaseRV+claimRV is equivalent to a release. If it cannot find an autoreleaseRV call, it tries to transfer the operand bundle to a function call in the callee. This is important since ARC optimizer can remove the autoreleaseRV returning the callee result, which makes it impossible to pair it up with the retainRV/claimRV call in the caller. If that fails, it simply emits a retain call in the IR if the implicit call is a call to retainRV and does nothing if it's a call to claimRV. Future work: - Use the operand bundle on x86-64. - Fix the auto upgrader to convert call+retainRV/claimRV pairs into calls annotated with the operand bundles. rdar://71443534 Differential Revision: https://reviews.llvm.org/D92808
2021-01-04[IR] CallBase::getBundleOpInfoForOperand - ensure Current iterator is ↵Simon Pilgrim1-1/+1
defined. NFCI. Fix clang static analyzer undefined pointer warning in the case Begin == End.
2020-12-10[CallBase] Add hasRetAttr version that takes StringRef.Florian Hahn1-10/+0
This makes it slightly easier to deal with custom attributes and CallBase already provides hasFnAttr versions that support both AttrKind and StringRef arguments in a similar fashion. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D92567
2020-12-09[IR] Support scalable vectors in CastInst::CreatePointerCastCullen Rhodes1-4/+4
Reviewed By: sdesmalen Differential Revision: https://reviews.llvm.org/D92482
2020-12-09[NFC][Instructions] Refactor CmpInst::getFlippedStrictnessPredicate() in ↵Roman Lebedev1-32/+84
terms of is{,Non}StrictPredicate()/get{Non,}StrictPredicate() In particular, this creates getStrictPredicate() method, to be symmetrical with already-existing getNonStrictPredicate().
2020-12-08[IR] Remove CastInst::isCastable since it is not usedCullen Rhodes1-59/+0
It was removed back in 2013 (f63dfbb) by Matt Arsenault but then reverted since DragonEgg used it, but that project is no longer maintained. Reviewed By: ldionne, dexonsmith Differential Revision: https://reviews.llvm.org/D92571
2020-12-07[IR] Bail out for scalable vectors in ShuffleVectorInst::isConcatCullen Rhodes1-0/+5
Shuffle mask for concat can't be expressed for scalable vectors, so we should bail out. A test has been added that previously crashed, also tested isIdentityWithPadding and isIdentityWithExtract where we already bail out. Reviewed By: sdesmalen Differential Revision: https://reviews.llvm.org/D92475
2020-11-27[AllocaInst] Update `getAllocationSizeInBits` to return `TypeSize`.Francesco Petrogalli1-2/+3
Reviewed By: peterwaller-arm, sdesmalen Differential Revision: https://reviews.llvm.org/D92020
2020-11-24Make CallInst::updateProfWeight emit i32 weights instead of i64Arthur Eubanks1-2/+3
Typically branch_weights are i32, not i64. This fixes entry_counts_cold.ll under NPM. Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D90539
2020-11-17[IR] ShuffleVectorInst::isIdentityWithPadding - bail on non-fixed-type ↵Simon Pilgrim1-1/+7
vector shuffles. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=27416
2020-11-06[IR] CmpInst: Add getFlippedSignednessPredicate()Roman Lebedev1-0/+12
And refactor a few places to use it