567 Commits

Author SHA1 Message Date
Youngsuk Kim
2051736f7b [llvm][Transforms] Avoid 'raw_string_ostream::str' (NFC)
Since `raw_string_ostream` doesn't own the string buffer, it is
desirable (in terms of memory safety) for users to directly reference
the string buffer rather than use `raw_string_ostream::str()`.

Work towards TODO comment to remove `raw_string_ostream::str()`.
2024-06-30 09:03:29 -05:00
Nikita Popov
9df71d7673
[IR] Add getDataLayout() helpers to Function and GlobalValue (#96919)
Similar to https://github.com/llvm/llvm-project/pull/96902, this adds
`getDataLayout()` helpers to Function and GlobalValue, replacing the
current `getParent()->getDataLayout()` pattern.
2024-06-28 08:36:49 +02:00
Nikita Popov
2d209d964a
[IR] Add getDataLayout() helpers to BasicBlock and Instruction (#96902)
This is a helper to avoid writing `getModule()->getDataLayout()`. I
regularly try to use this method only to remember it doesn't exist...

`getModule()->getDataLayout()` is also a common (the most common?)
reason why code has to include the Module.h header.
2024-06-27 16:38:15 +02:00
Stephen Tozer
d75f9dd1d2 Revert "[IR][NFC] Update IRBuilder to use InsertPosition (#96497)"
Reverts the above commit, as it updates a common header function and
did not update all callsites:

  https://lab.llvm.org/buildbot/#/builders/29/builds/382

This reverts commit 6481dc57612671ebe77fe9c34214fba94e1b3b27.
2024-06-24 18:00:22 +01:00
Stephen Tozer
6481dc5761
[IR][NFC] Update IRBuilder to use InsertPosition (#96497)
Uses the new InsertPosition class (added in #94226) to simplify some of
the IRBuilder interface, and removes the need to pass a BasicBlock
alongside a BasicBlock::iterator, using the fact that we can now get the
parent basic block from the iterator even if it points to the sentinel.
This patch removes the BasicBlock argument from each constructor or call
to setInsertPoint.

This has no functional effect, but later on as we look to remove the
`Instruction *InsertBefore` argument from instruction-creation
(discussed
[here](https://discourse.llvm.org/t/psa-instruction-constructors-changing-to-iterator-only-insertion/77845)),
this will simplify the process by allowing us to deprecate the
InsertPosition constructor directly and catch all the cases where we use
instructions rather than iterators.
2024-06-24 17:27:43 +01:00
Fangrui Song
89e8e63f47 [Attributor] Stabilize llvm.assume output
Don't rely on the iteration order of DenseSet<StringRef>, which is not
guaranteed to be deterministic.
2024-06-19 15:36:46 -07:00
Vidush Singhal
bea329ecb0
[Attributor]: allow more than one offset for a pass through user in AAPointerInfo (#94416)
Co-authored-by: Vidush Singhal <singhal2@ruby964.llnl.gov>
2024-06-17 16:31:39 -07:00
Kazu Hirata
7c6d0d26b1
[llvm] Use llvm::unique (NFC) (#95628) 2024-06-14 22:49:36 -07:00
Johannes Doerfert
f33310e450
[Attributor][FIX] Ensure nonnull IR deduction is not optimistic (#93322)
We cannot use assumed dead information for nonnull IR-implied deduction
as we will never go back and re-check. This was reported in
  https://github.com/llvm/llvm-project/pull/85810
2024-06-13 08:42:36 +03:00
Vidush Singhal
bfc0f856b6
[NFC] : Run clang-format on Attributor.h and AttributorAttributes.cpp (#94484)
This PR just runs Clang format on Attributor.h and AttributorAttributes.cpp

Co-authored-by: Vidush Singhal <singhal2@ruby964.llnl.gov>
2024-06-05 11:32:22 -07:00
Nikita Popov
deab451e7a
[IR] Remove support for icmp and fcmp constant expressions (#93038)
Remove support for the icmp and fcmp constant expressions.

This is part of:
https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179

As usual, many of the updated tests will no longer test what they were
originally intended to -- this is hard to preserve when constant
expressions get removed, and in many cases just impossible as the
existence of a specific kind of constant expression was the cause of the
issue in the first place.
2024-06-04 08:31:03 +02:00
Johannes Doerfert
d48d108bc6
[Attributor][FIX] Replace AANoFPClass MBEC propagation (#91030)
The old use of must-be-executed-context (MBEC) did propagate
through calls even if that was not allowed. We now only propagate from
call site arguments. If there are calls/intrinsics that allows
propagation, we need to add them explicitly.

Fixes: https://github.com/llvm/llvm-project/issues/78507

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2024-06-03 20:41:52 -07:00
Matt Arsenault
2d61692d4b
Attributor: Do not assume function context in AANoCapture (#91462)
If the calling function has the null_pointer_is_valid attribute, somehow
a null constant reaches here. I'm not sure why exactly, it doesn't
happen for other types of constants.

Fixes #87856
2024-05-23 19:31:33 +02:00
Harald van Dijk
60de56c743
[ValueTracking] Restore isKnownNonZero parameter order. (#88873)
Prior to #85863, the required parameters of llvm::isKnownNonZero were
Value and DataLayout. After, they are Value, Depth, and SimplifyQuery,
where SimplifyQuery is implicitly constructible from DataLayout. The
change to move Depth before SimplifyQuery needed callers to be updated
unnecessarily, and as commented in #85863, we actually want Depth to be
after SimplifyQuery anyway so that it can be defaulted and the caller
does not need to specify it.
2024-04-16 15:21:09 +01:00
Yingwei Zheng
e0a628715a
[ValueTracking] Convert isKnownNonZero to use SimplifyQuery (#85863)
This patch converts `isKnownNonZero` to use SimplifyQuery. Then we can
use the context information from `DomCondCache`.

Fixes https://github.com/llvm/llvm-project/issues/85823.
Alive2: https://alive2.llvm.org/ce/z/QUvHVj
2024-04-12 23:47:20 +08:00
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