552 Commits

Author SHA1 Message Date
Matt Arsenault
733640d29e
Attributor: Handle inferring align from use by atomics (#85762) 2024-03-21 10:54:03 +05:30
lcvon007
676c495195
[Attributor][FIX] Register right new created BB. (#84929)
CBBB will keep same after the first iteration so
registerManifestAddedBasicBlock would always register the same basic
block later.

Co-authored-by: laichunfeng <laichunfeng@tencent.com>
2024-03-13 16:38:48 +08:00
Jeremy Morse
2fe81edef6 [NFC][RemoveDIs] Insert instruction using iterators in Transforms/
As part of the RemoveDIs project we need LLVM to insert instructions using
iterators wherever possible, so that the iterators can carry a bit of
debug-info. This commit implements some of that by updating the contents of
llvm/lib/Transforms/Utils to always use iterator-versions of instruction
constructors.

There are two general flavours of update:
 * Almost all call-sites just call getIterator on an instruction
 * Several make use of an existing iterator (scenarios where the code is
   actually significant for debug-info)
The underlying logic is that any call to getFirstInsertionPt or similar
APIs that identify the start of a block need to have that iterator passed
directly to the insertion function, without being converted to a bare
Instruction pointer along the way.

Noteworthy changes:
 * FindInsertedValue now takes an optional iterator rather than an
   instruction pointer, as we need to always insert with iterators,
 * I've added a few iterator-taking versions of some value-tracking and
   DomTree methods -- they just unwrap the iterator. These are purely
   convenience methods to avoid extra syntax in some passes.
 * A few calls to getNextNode become std::next instead (to keep in the
   theme of using iterators for positions),
 * SeparateConstOffsetFromGEP has it's insertion-position field changed.
   Noteworthy because it's not a purely localised spelling change.

All this should be NFC.
2024-03-05 15:12:22 +00:00
Nikita Popov
6c2fbc3a68
[IRBuilder] Add CreatePtrAdd() method (NFC) (#77582)
This abstracts over the common pattern of creating a gep with i8 element
type.
2024-01-12 14:21:21 +01:00
Bill Wendling
fc6b5666db
[NFC][ObjectSizeOffset] Use classes instead of std::pair (#76882)
The use of std::pair makes the values it holds opaque. Using classes
improves this while keeping the POD aspect of a std::pair. As a nice
addition, the "known" functions held inappropriately in the Visitor
classes can now properly reside in the value classes. :-)
2024-01-05 18:08:53 -08:00
Nikita Popov
658b260dbf [Attributor] Don't construct pretty GEPs
Bring this in line with other transforms like ArgPromotion/SROA/
SCEVExpander and always produce canonical i8 GEPs.
2023-12-22 16:48:13 +01:00
Nikita Popov
696cc20d4e [LVI] Make UndefAllowed argument of getConstantRange() required
For the two remaining uses that did not explicitly specify it,
set UndefAllowed=false. In both cases, I believe that treating
undef as a full range is the correct behavior.
2023-12-12 11:43:52 +01:00
Youngsuk Kim
9071a15d4b
[llvm][Attributor] Strip AddressSpaceCast from 'constructPointer' (#74742)
* Remove pointer AddressSpaceCast in function `constructPointer`
* Remove 1st parameter (`ResTy`) of function `constructPointer`

1st input argument to function `constructPointer` in all 4 call-sites is
`ptr addrspace(0)`. Function `constructPointer` performs a pointer
AddressSpaceCast to `ResTy`, making the returned pointer have type `ptr
addrspace(0)` in all 4 call-sites.

Unless there's a clear reason to discard the addrspace info of input
parameter `Ptr`, I think we should keep and forward that info to the
returned pointer of `constructPointer`.

Opaque ptr cleanup effort.
2023-12-11 09:29:01 -05:00
Vidhush Singhal
754b93e466
[Attributor] New attribute to identify what byte ranges are alive for an allocation (#66148)
Changes the size of allocations automatically.
For now, implements the case when a single range from start of the
allocation is alive and the allocation can be reduced.
2023-11-10 16:26:37 -08:00
Johannes Doerfert
a8152086ff [Attributor][FIX] Ensure new BBs are registered 2023-11-01 12:12:14 -07:00
Nikita Popov
6b8ed78719 [IR] Add writable attribute
This adds a writable attribute, which in conjunction with
dereferenceable(N) states that a spurious store of N bytes is
introduced on function entry. This implies that this many bytes
are writable without trapping or introducing data races. See
https://llvm.org/docs/Atomics.html#optimization-outside-atomic for
why the second point is important.

This attribute can be added to sret arguments. I believe Rust will
also be able to use it for by-value (moved) arguments. Rust likely
won't be able to use it for &mut arguments (tree borrows does not
appear to allow spurious stores).

In this patch the new attribute is only used by LICM scalar promotion.
However, the actual motivation for this is to fix a correctness issue
in call slot optimization, which needs this attribute to avoid
optimization regressions.

Followup to the discussion on D157499.

Differential Revision: https://reviews.llvm.org/D158081
2023-11-01 10:46:31 +01:00
Harvin Iriawan
211dc4ad40
[Analysis] Add Scalable field in MemoryLocation.h (#69716)
This is the first of a series of patch to improve Alias Analysis on
  Scalable quantities.
  Keep Scalable information from TypeSize which
  will be used in Alias Analysis.
2023-10-24 18:18:51 +01:00
Johannes Doerfert
ba87fba806 [Attributor] Ignore different kernels for kernel lifetime objects
If a potential interfering access is in a different kernel and the
underlying object has kernel lifetime we can straight out ignore the
interfering access.
TODO: This should be made much stronger via "reaching kernels", which we
already track in AAKernelInfo.
2023-10-21 12:31:06 -07:00
Matt Arsenault
bad5893c30 Attributor: Fix not propagating nofpclass arguments through transitive callers
Fixes #64867
2023-10-05 06:03:40 -07:00
Mikael Holmen
e4114f9c0d [AttributorAttributes] Remove unused variable [NFC]
gcc warned about it:
 [232/4788] Building CXX object lib/Transforms/IPO/CMakeFiles/LLVMipo.dir/AttributorAttributes.cpp.o
 ../lib/Transforms/IPO/AttributorAttributes.cpp: In lambda function:
 ../lib/Transforms/IPO/AttributorAttributes.cpp:12555:17: warning: unused variable 'SI' [-Wunused-variable]
 12555 |       if (auto *SI = dyn_cast<StoreInst>(Inst)) {
       |                 ^~

Fix the warning by removing the variable and turn dyn_cast into isa.
2023-09-29 10:50:53 +02:00
Shilei Tian
a501d06fcb
[Attributor] Only manifest pointer operand for StoreInst in AAAddressSpace (#65708)
`AAAddressSpace` currently only works for `LoadInst` and `StoreInst`
currently. For `StoreInst`, the corresponding use can be the pointer
operand, or value operand, or both. When it is used as value operand, it
can prevent `AMDGPUPromoteAlloca` from optimization in certain cases.
This patch changes the manifest method such that only pointer operand
will be rewritten.
2023-09-08 15:24:25 -04:00
Johannes Doerfert
73a836a464
[Attributor] Look through indirect calls (#65197)
Through the new `Attributor::checkForAllCallees` we can look through
indirect calls and visit all potential callees if they are known. Most
AAs will do that implicitly now via `AACalleeToCallSite`, thus, most AAs
are able to deal with missing callees for call site IR positions.

Differential Revision: https://reviews.llvm.org/D112290
2023-09-08 12:14:38 -07:00
Johannes Doerfert
9207a90be5 [Attributor] Do not expand dead indirect call sites 2023-09-01 22:14:38 -07:00
Johannes Doerfert
a8ac969b10 [Attributor][NFC] Use common helper to avoid duplication
Many AAs translated callee information to the call site explicitly but
they now all use the helper we already had for callee return to call
site return propagation. In a follow up the helper is going to be
extended to handle multiple callees.
2023-09-01 21:04:03 -07:00
Johannes Doerfert
ac0d3869c5 [Attributor][NFC] Simplify the helper APIs
We have various helpers to propagate information. This patch cleans up
the API to allow less template parameters and more uniform handling.
2023-09-01 21:04:02 -07:00
Johannes Doerfert
6b95126b9b [Attributor][NFC] Rename AACallSiteReturnedFromReturned
In a follow up we'll use it for more than "callee return" -> "call site
return" deduction, effectively allowing "callee" -> "call site".
2023-09-01 21:04:02 -07:00
Johannes Doerfert
37642714ed [Attributor][FIX] Support non-0 AS for function pointers 2023-09-01 17:17:51 -07:00
Johannes Doerfert
8dd3b4581c [Attributor][NFC] Clean include order 2023-08-31 19:32:52 -07:00
Matt Arsenault
850ec7bbb1 Attributor: Try to propagate concrete denormal-fp-math{-f32}
Allow specialization of functions with "dynamic" denormal modes to a
known IEEE or DAZ mode based on callers. This should make it possible
to implement a is-denormal-flushing-enabled test using
llvm.canonicalize and have it be free after LTO.

https://reviews.llvm.org/D156129
2023-08-31 08:26:32 -04:00
Johannes Doerfert
6f0ca01c57 [Attributor] Introduce AAGlobalValueInfo to track global value uses
GlobalValues are often interesting, especially if they have local
linkage. We now track all uses of those and refine potential callees
with it. Effectively, if an internal function cannot reach an indirect
call site, it cannot be a potential callee, even if it has its address
taken.
2023-08-29 22:41:54 -07:00
Johannes Doerfert
498887ae8a [Attributor] Introduce the closed world flag
The Attributor user can now set the closed world flag
(`AttributorConfig.IsClosedWorldModule` or
`-attributor-assume-closed-world`) in order to specialize call edges
based only on available callees. That means, we assume all functions are
known and hence all potential callees must be declared/defined in the
module. We will use this for GPUs and LTO cases, but for now the user
has to set it via a flag.
2023-08-29 22:35:17 -07:00
Johannes Doerfert
936661084c [Attributor][NFC] Add querying AA to shouldSpecializeCallSiteForCallee
The callback might require an AA, e.g., to ask other AAs for information
in a way that will enfore dependences.
2023-08-29 22:35:16 -07:00
Matt Arsenault
d2a06ef05a Attributor: Allow refining of callsite attributes that already have nofpclass
https://reviews.llvm.org/D158419
2023-08-28 13:54:49 -04:00
Johannes Doerfert
e5313ef55f [Attributor] Filter potential callees based on noundef arguments
If a potential callee has more arguments than the call site, the values
passed will be `poison`. If the potential callee would exhibit UB for
such `undef` argument, e.g., they are marked `noundef`, we can rule the
potential callee out.
2023-08-25 14:36:43 -07:00
Johannes Doerfert
d0b5523632 [Attributor] Introduce limit for indirect call specialization
The user can now limit the number of indirect calls specialized for a
given call site with `-attributor-max-specializations-per-call-base=N`
or the AttributorConfig callback. We further attach the `!callee`
metadata if all remaining callees are known.
2023-08-25 14:36:42 -07:00
Johannes Doerfert
f118e3bcca [Attributor][NFC] Fix typo 2023-08-25 14:36:42 -07:00
Johannes Doerfert
d2c37fc4f7 [Attributor][FIX] Avoid dangling stack references in map
The old code did not account for new queries during an update, which
caused us to leave stack RQIs in the map. We are now explicit about
temporary vs non-temporary RQIs.

Fixes: https://github.com/llvm/llvm-project/issues/64959
2023-08-24 16:28:10 -07:00
Johannes Doerfert
9a80ebe63c [Attributor] Simplify assumptions "stores"
When we add an assumption about memory to the AAPointerInfo bins, we
should simplify the assumed value, like we do for stores.
2023-08-23 15:14:14 -07:00
Johannes Doerfert
78b8f1f78f [Attributor][FIX] Remove the visited set from AAInterFnReachability
The visited set was used to not visit the same function twice, however,
the (new) algorithm requires we do since we start the queries at
different call sites.
2023-08-23 11:48:18 -07:00
Johannes Doerfert
3e19416e4e [Attributor][FIX] Initialize variable 2023-08-18 21:47:57 -07:00
Johannes Doerfert
9c08e76f3e [Attributor] Introduce AAIndirectCallInfo
AAIndirectCallInfo will collect information and specialize indirect call
sites. It is similar to our IndirectCallPromotion but runs as part of
the Attributor (so with assumed callee information). It also expands
more calls and let's the rest of the pipeline figure out what is UB, for
now. We use existing call promotion logic to improve the result,
otherwise we rely on the (implicit) function pointer cast.

This effectively "fixes" #60327 as it will undo the type punning early
enough for the inliner to work with the (now specialized, thus direct)
call.

Fixes: https://github.com/llvm/llvm-project/issues/60327
2023-08-18 16:44:05 -07:00
Johannes Doerfert
361b536bbc [Attributor] Simplify switches with more than one potential condition
Before, we allowed the condition to be simplified to a simple constant
only, otherwise we assumed all successors are live. Now we allow
multiple constants, and mark the default successor as dead accordingly.
2023-08-17 22:42:38 -07:00
Johannes Doerfert
bfa1afb81c [OpenMPOpt] Improve __kmpc_alloc_shared handling
We know that __kmpc_alloc_shared is by construction matched with a
unique __kmpc_free_shared. Making the compiler aware of these facts
helps to avoid mallocs/allocas.

Fixes: https://github.com/llvm/llvm-project/issues/64551
2023-08-17 19:25:32 -07:00
Johannes Doerfert
5a406b63e9 [Attributor][FIX] Stores capture, even for readonly functions
If we end up visiting a store use, we couldn't follow to the "reloads".
The capture effect of a store is more than memory as the reloads are
unknown.

Fixes: https://github.com/llvm/llvm-project/issues/64613
2023-08-11 14:17:33 -07:00
Johannes Doerfert
d70ab63bc2 [Attributor][NFCI] Filter uninteresting accesses early
We can prevent the costly interference check if an access is not
interesting in the first place. Let the user decide via a callback.
2023-08-04 11:36:58 -07:00
Johannes Doerfert
78daab0a85 [Attributor][NFCI] Compute ReachabilityQueryInfo hash once and on demand 2023-08-03 00:12:46 -07:00
Johannes Doerfert
2a20c64a73 [Attributor][NFCI] Use DominatorTree to short circuit reachability queries
If we do not have exlusion blocks and the target is live, we only need
to reach a dominating block.
2023-08-03 00:12:46 -07:00
Johannes Doerfert
4fd9874696 [Attributor][NFCI] Exit reachability queries early if the target is not live 2023-08-03 00:12:45 -07:00
Johannes Doerfert
578ab3312f [Attributor][NFCI] Use a uniform necessary query to avoid a unique one
If we cannot reach the target from the entry of a function without
exclusion set, we cannot reach it at all. This can allow us to filter
unique queries based on a uniform one.
2023-08-03 00:12:45 -07:00
Bjorn Pettersson
e6e9a87534 Drop some typed pointer handling
Differential Revision: https://reviews.llvm.org/D156739
2023-08-02 12:08:37 +02:00
Johannes Doerfert
a598e39063 [AAInterFnReachabilityFunction][NFC] Remove unused members 2023-07-26 00:03:06 -07:00
Johannes Doerfert
b3fec1067a [Attributor] Improve NonNull deduction
We can improve our deduction if we stop at PHI and select instructions
and also iterate the returned values explicitly. The latter helps with
isImpliedByIR deductions.
2023-07-25 20:31:21 -07:00
Johannes Doerfert
88b5d23021 [Attributor] Allow multiple LHS/RHS values when simplifying comparisons
We use to deal with multiple values but not in the handleCmp function.
Now we also allow multiple simplified operands there.
2023-07-25 20:31:21 -07:00
Johannes Doerfert
0cd8a28941 [Attributor][FIX] No IntraFnReachability does not mean unreachable
Also, first check inter fn reachability as it seems to be cheaper in
practise.
2023-07-25 17:47:33 -07:00
Johannes Doerfert
ba0be698c5 [Attributor][NFC] Rename variable to be less confusing 2023-07-25 17:47:33 -07:00