989 Commits

Author SHA1 Message Date
Nikita Popov
e414ba33b4 [ValueTracking] Shufflevector produces poison rather than undef
Shufflevector semantics have changed so that poison mask elements
return poison rather than undef. Reflect this in the
canCreateUndefOrPoison() implementation.
2023-12-21 15:21:23 +01:00
Paschalis Mpeis
c4ff0a67d1
[TLI] Add getLibFunc that accepts an Opcode and scalar Type. (#75919)
It sets a LibFunc similarly with the other two getLibFunc methods.
Currently, it supports only the FRem Instruction.

Add tests for FRem.
2023-12-21 11:02:54 +00:00
Paschalis Mpeis
ddb6db4d09
[VFABI] Create FunctionType for vector functions (#75058)
`createFunctionType` returns a FunctionType  that may contain a mask,
which is currently placed as the last parameter to the Function.
The placement happens according to `VFParameters` of `VFInfo`, and it
should be able to handle VFABI specification changes.

Regarding the return type, it uses the scalar type of the input instruction,
as the specification does not encode in the mangled name such information.
If that ever happens, that information should be available from `VFInfo`.
2023-12-19 12:05:28 +00:00
Kazu Hirata
6eaf15d05e [Analysis] Use llvm::erase (NFC) 2023-12-17 09:41:20 -08:00
Kazu Hirata
5c9d82de6b [llvm] Use StringRef::{starts,ends}_with (NFC)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-13 22:46:02 -08:00
Paschalis Mpeis
3c1e7fb95e
[VFABI] Improve VFABI unit tests (#73907)
The below changes were made:
- test the vector and scalar names, the ISA, and the presence or absence of a
  mask in all tests that is relevant
- test the number of the parameters, the order/types and for masks if present
- replaced methods like `sin` to `foo` to make it more clear that these are not
  existing functions but they are rather tests.
- using mostly `i32` for parameters where it is not relevant, except when the VF
  of elements in explicitly checked, and `ptr` for references.
  Also using `void` for return types.
- all `VFABIParserTest` tests are now listed contiguously in the source.
- Removed duplicate ISA tests
- Added an extra test to clearly show that the mangled name becomes the
  VectorName, when no VectorName is specified.
- Use `VFInfo` for `isMasked`
- Minor code refactoring, cleanup, and improved comments
2023-12-11 11:20:47 +00:00
Kazu Hirata
6c87a0af95 [Analysis] Remove unnecessary includes (NFC) 2023-12-07 22:15:32 -08:00
Paschalis Mpeis
7b83f69db4
[NFC] Replace CallInst with FunctionType in VFABI, VFShape API (#74569)
Minor simplification applied to VFShape::getScalarShape,
VFShape::get, and VFABI::tryDemangleForVFABI methods.

Also, remove unnecessary `static_cast` in `SLPVectorizer.cpp`
2023-12-06 17:14:58 +00:00
Craig Topper
5c3496ff33
[InstCombine] Check isGuaranteedNotToBeUndef in haveNoCommonBitsSetSpecialCases. (#74390)
It's not safe for InstCombine to add disjoint metadata when converting
Add to Or otherwise.

I've added noundef attribute to preserve existing test behavior.
2023-12-05 10:33:44 -08:00
Fangrui Song
dd3184c30f [unittest,examples] Replace uses of IRBuilder::getInt8PtrTy with getPtrTy. NFC 2023-11-27 08:29:13 -08:00
Graham Hunter
b1fba568f6
[SVE] Don't require lookup when demangling vector function mappings (#72260)
We can determine the VF from a combination of the mangled name (which
indicates the arguments that take vectors) and the element sizes of
the arguments for the scalar function the mapping has been established
for.

The assert when demangling fails has been removed in favour of just
not adding the mapping, which prevents the crash seen in
https://github.com/llvm/llvm-project/issues/71892

This patch also stops using _LLVM_ as an ISA for scalable vector tests,
since there aren't defined rules for the way vector arguments should be
handled (e.g. packed vs. unpacked representation).
2023-11-23 17:15:48 +00:00
Youngsuk Kim
23d41ed5c9
[CGSCCPassManagerTest] Replace no-op bitcast to create constant using the old function (#72460)
With opaque pointers enabled, the existing ptr-to-ptr bitcast is a no-op
and no longer creates a constant that references the old function.

Replace the no-op bitcast with code that creates a constant that
references the old function. The test now fails if the 1 new line of
code added to `CallGraphUpdater::replaceFunctionWith()` in
cb0ecc5c33bd56a3eed0fa30ac787accec45d637 is removed (test passes if kept
intact).

---------

Co-authored-by: Nikita Popov <github@npopov.com>
2023-11-16 06:00:36 -05:00
Simon Pilgrim
be252b4e28 Fix MSVC unused variable warning. NFCI.
RunRandTest is driven by a fixed seed, not a random_device
2023-11-15 11:59:07 +00:00
Matt Arsenault
0e1a52f556
ValueTracking: Handle compare gt to -inf in class identification (#72086)
This apparently shows up somewhere in chromium. We also are missing a
canonicalization to an equality compare with inf.
2023-11-14 10:05:38 +09:00
Tom Stellard
2750a22745
Passes: Consolidate EnableKnowledgeRetention declarations into a header file (#71695) 2023-11-13 11:03:49 -08:00
Paulo Matos
7b9d73c2f9
[NFC] Remove Type::getInt8PtrTy (#71029)
Replace this with PointerType::getUnqual().
Followup to the opaque pointer transition. Fixes an in-code TODO item.
2023-11-07 17:26:26 +01:00
Kazu Hirata
9c5a5a421d [llvm] Stop including llvm/ADT/iterator_range.h (NFC)
Identified with misc-include-cleaner.
2023-10-22 15:41:18 -07:00
Yingwei Zheng
9451004987
[InstCombine][TLI] Fix function prototype of labs (#69077)
`i64 @labs(i32)` is incorrectly recognized as `LibFunc_labs` because
type ID `Long` matches both `i32` and `i64`. This PR requires the type
of argument to match the return value.

Fixes #69059.
2023-10-15 17:00:50 +08:00
Fangrui Song
2d854dd3e7 Move global namespace cl::opt inside llvm:: or internalize them 2023-10-10 19:58:03 -07:00
Matt Arsenault
7a46baa465
ValueTracking: Use fcAllFlags for unknown value (#66393)
In the failure case we return null, which callers are checking. We were
also returning an fcNone which was unused. It's more consistent to
return fcAllFlags as any possible value, such that the value is always
directly usable without checking the returned value.
2023-10-05 13:10:28 -07:00
Matthias Braun
5181156b37
Use BlockFrequency type in more places (NFC) (#68266)
The `BlockFrequency` class abstracts `uint64_t` frequency values. Use it
more consistently in various APIs and disable implicit conversion to
make usage more consistent and explicit.

- Use `BlockFrequency Freq` parameter for `setBlockFreq`,
`getProfileCountFromFreq` and `setBlockFreqAndScale` functions.
- Return `BlockFrequency` in `getEntryFreq()` functions.
- While on it change some `const BlockFrequency& Freq` parameters to
plain `BlockFreqency Freq`.
- Mark `BlockFrequency(uint64_t)` constructor as explicit.
- Add missing `BlockFrequency::operator!=`.
- Remove `uint64_t BlockFreqency::getMaxFrequency()`.
- Add `BlockFrequency BlockFrequency::max()` function.
2023-10-05 11:40:17 -07:00
JOE1994
81ee059073 [llvm] Replace uses of Type::getPointerTo (NFC)
opaque pointer clean-up effort (NFC)
2023-10-05 10:08:38 -04:00
JolantaJensen
01797dad86
Fix mechanism propagating mangled names for TLI function mappings (#66656)
Currently the mappings from TLI are used to generate the list of
available "scalar to vector" mappings attached to scalar calls as
"vector-function-abi-variant" LLVM IR attribute. Function names from TLI
are wrapped in mangled name following the pattern:
_ZGV<isa><mask><vlen><parameters>_<scalar_name>[(<vector_redirection>)]
The problem is the mangled name uses _LLVM_ as the ISA name which
prevents the compiler to compute vectorization factor for scalable
vectors as it cannot make any decision based on the _LLVM_ ISA. If we
use "s" as the ISA name, the compiler can make decisions based on VFABI
specification where SVE spacific rules are described.

This patch is only a refactoring stage where there is no change to the
compiler's behaviour.
2023-10-02 18:58:39 +01:00
Nikita Popov
739c86df80 [llvm] Use more explicit cast methods (NFC)
Instead of ConstantExpr::getCast() with a fixed opcode, use the
corresponding getXYZ methods instead. For the one place creating
a pointer bitcast drop it entirely, as this is redundant with
opaque pointers.
2023-09-29 11:21:13 +02:00
Bjorn Pettersson
4d5906e0bf [llvm][unittests] Remove unneeded header includes 2023-09-12 18:47:44 +02:00
Aiden Grossman
aad3641e80 [FunctionPropertiesAnalysis] Add CFG and call properties
This patch adds in a couple more properties related to call instructions
and the CFG within the function that should expose a little bit more
about the characteristics of the function.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D158681
2023-08-25 15:02:09 -07:00
Aiden Grossman
b8f191e054 [FunctionPropertiesAnalysis] Add operand type counts
This patch adds operand type counts to the detailed function properties
analysis. This is intended to enable more interesting and detailed
comparisons across different languages on specific metrics (like usage
of inline assembly or global values).

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D158018
2023-08-18 13:27:19 -07:00
Jon Roelofs
25e2b4aa1e
Revert "Revert "cmake: add missing dependencies on Attributes.inc""
This reverts commit d462f65b8242a82d2430605a741825bf10ebaca0.

It breaks the modules build again, but also may inhibit the use of `-DLLVM_TABLEGEN=`.

See the discussion here: https://reviews.llvm.org/D150144#4578311

rdar://113696899
2023-08-10 14:54:22 -07:00
Bjorn Pettersson
e53b28c833 [llvm] Drop some bitcasts and references related to typed pointers
Differential Revision: https://reviews.llvm.org/D157551
2023-08-10 15:07:07 +02:00
Jon Roelofs
d462f65b82
Revert "cmake: add missing dependencies on Attributes.inc"
This reverts commit 30b4351c7c75296dc60fc887212cdc98e85e9996.

This caused a dependency cycle that the Swift build picked up on:

```
CMake Error: The inter-target dependency graph contains the following strongly connected component (cycle):
  "llvm-tblgen" of type EXECUTABLE
    depends on "LLVMCodeGenTypes" (weak)
    depends on "LLVMTableGenGlobalISel" (weak)
    depends on "intrinsics_gen" (strong)
  "LLVMTableGenGlobalISel" of type STATIC_LIBRARY
    depends on "LLVMCodeGenTypes" (weak)
    depends on "vt_gen" (strong)
  "vt_gen" of type UTILITY
    depends on "llvm-tblgen" (strong)
  "autogen_intrinsics_RISCV" of type UTILITY
    depends on "llvm-tblgen" (strong)
  "intrinsics_gen" of type UTILITY
    depends on "llvm-tblgen" (strong)
    depends on "autogen_intrinsics_RISCV" (strong)
  "LLVMCodeGenTypes" of type STATIC_LIBRARY
    depends on "vt_gen" (strong)
```

rdar://113636528
2023-08-09 10:45:11 -07:00
Aiden Grossman
fe6bb84c7e [FunctionPropertiesAnalysis] Add detailed analysis
This patch adds more detailed function properties gated behind a command
line flag for use primarily in experimentation and gathering statistics
on the functions in a module or project. The runtime cost should be
minimal as the computation is only done when the flag is set. There will
be a slight memory overhead when the ML inliner is enabled, but it
should be fairly small at a handful of bytes per function.

This is an adapted form of https://reviews.llvm.org/D109661.

Reviewed By: mtrofin

Differential Revision: https://reviews.llvm.org/D157358
2023-08-08 18:03:16 -07:00
Bjorn Pettersson
fd05c34b18 Stop using legacy helpers indicating typed pointer types. NFC
Since we no longer support typed LLVM IR pointer types, the code can
be simplified into for example using PointerType::get directly instead
of using Type::getInt8PtrTy and Type::getInt32PtrTy etc.

Differential Revision: https://reviews.llvm.org/D156733
2023-08-02 12:08:37 +02:00
Nikita Popov
8e55e33749 [llvm] Remove calls to setOpaquePointers() (NFC)
True is the default (and only possible) value.
2023-07-14 09:31:55 +02:00
Carlo Bramini
a6ea0185d6 [llvm] CYGWIN: Fix build of some plugins/library/unittests
CYGWIN uses the same format of WIN32 for shared libraries.
As the comment says: "a shared library can't have undefined references", in this case CYGWIN must be handled like WIN32 by CMakeLists.txt, otherwise you will get several errors when linking because some symbols are undefined.
Attached patch fixes this issue and allows to complete the build process for those targets.

Differential Revision: https://reviews.llvm.org/D154794
2023-07-10 22:43:03 +03:00
Nikita Popov
8d3856836c [ValueTracking] Don't handle ptrtoint with mismatches sizes
When processing assumes, we also handle assumes on ptrtoint of the
value. In canonical IR, these will have the same size as the value.
However, in non-canonical IR there may be an implicit zext or
trunc, which results in a bit width mismatch. We currently handle
this by adjusting bitwidth everywhere, but this is fragile and I'm
pretty sure that the way we do this is incorrect for some predicates,
because we effectively end up commuting an ext/trunc and an icmp.

Instead, add an m_PtrToIntSameSize() matcher that will only handle
bitwidth preserving cases. For the bitwidth-changing cases, wait
until they have been canonicalized.

The original handling for this was added purely to prevent crashes
in an earlier implementation which failed to account for this
entirely.
2023-07-05 12:18:00 +02:00
Liren Peng
75a73c983f Revert "[ScalarEvolution] Infer loop max trip count from array accesses"
This reverts commit 57e093162e27334730d8ed8f7b25b1b6f65ec8c8.
2023-06-29 17:27:38 +08:00
Juan Manuel MARTINEZ CAAMAÑO
cc8a346e3f [InlineCost][TargetTransformInfo][AMDGPU] Consider cost of alloca instructions in the caller (1/2)
On AMDGPU, alloca instructions have penalty that can
be avoided when SROA is applied after inlining.

This patch introduces the default implementation of
TargetTransformInfo::getCallerAllocaCost.

Reviewed By: mtrofin

Differential Revision: https://reviews.llvm.org/D149740
2023-06-29 09:49:16 +02:00
Matt Arsenault
19a35041c0 ValueTracking: Handle !absolute_symbol in computeKnownBits
Use a unit test since I don't see any existing uses try to make use of
the high bits of a pointer.

This will also assert if the metadata type doesn't match the pointer
width, but I consider that a defect in the verifier and shouldn't be
handled.

AMDGPU allocates LDS globals by assigning !absolute_symbol with the
final fixed address. Tracking the high bits are 0 may help with
addressing mode matching.
2023-06-28 07:33:27 -04:00
Antonio Frighetto
355dab0b5a [ConstraintSystem] Fix mislabeling in unittests (NFC)
Possible misleading comment has been addressed.
2023-06-21 12:54:25 +02:00
Matt Arsenault
06f942016b ValueTracking: Ignore -0 for nsz sqrt with UseInstrInfo in computeKnownFPClass
This avoids a regression when SignBitMustBeZero is moved to computeKnownFPClass.
2023-06-20 21:30:09 -04:00
Matt Arsenault
cb9b01f910 ValueTracking: Handle compare to nan and -inf constants in fcmpToClassTest
This will help enable a cleanup of simplifyFCmpInst
2023-06-19 11:31:58 -04:00
Nikita Popov
f7d1baa414 [KnownBits] Return zero instead of unknown for always poison shifts
For always poison shifts, any KnownBits return value is valid.
Currently we return unknown, but returning zero is generally more
profitable. We had some code in ValueTracking that tried to do this,
but was actually dead code.

Differential Revision: https://reviews.llvm.org/D150648
2023-05-23 14:41:22 +02:00
Mircea Trofin
01c5ec3d62 [NFC] Surface the validation of FunctionPropertiesAnalysis
Avoids relying on `assert` for some of the validation.

Differential Revision: https://reviews.llvm.org/D150827
2023-05-22 16:13:28 -07:00
Matt Arsenault
5b18d84380 Reapply "ValueTracking: Handle phi in computeKnownFPClass"
This reverts commit e13f88d1ff5234946af6349a9a7cf56fcb6c040e.

Fix off by one recursion limit check.
2023-05-18 12:58:09 +01:00
Matt Arsenault
e13f88d1ff Revert "ValueTracking: Handle phi in computeKnownFPClass"
This reverts commit cac9e427eb1ff3dabda8ac08968b998c3bc5ab47.

Causing crashes in lencod
2023-05-18 09:43:46 +01:00
Matt Arsenault
cac9e427eb ValueTracking: Handle phi in computeKnownFPClass
Doesn't try the all the tricks computeKnownBits does.
2023-05-18 08:04:38 +01:00
Matt Arsenault
fe5786d416 ValueTracking: Implement computeKnownFPClass for sqrt
Could be slightly smarter in cases that are probably uninteresting.
2023-05-16 12:41:43 +01:00
Jon Roelofs
30b4351c7c
cmake: add missing dependencies on Attributes.inc
Differential revision: https://reviews.llvm.org/D150144
2023-05-08 15:35:57 -07:00
Teresa Johnson
57d71cba0a Fix for windows bot failure (switch uint to unsigned)
Fix windows bot failure from b8d2f7177c39af7be371ba7f46cb00b9c63ef8f5:

https://lab.llvm.org/buildbot/#/builders/216/builds/20923

by switching uint to unsigned, as the former is not recognized there.
2023-05-08 11:26:36 -07:00
Kan Wu
b8d2f7177c [MemProf] Add hot allocation type
Add "Hot" AllocationType (in addition to existing cold, notcold).

Use lifetime access density as metric to identify hot allocations.
Treat hot as notcold for MemProfContextDisambiguation for now
before the disambiguation for "hot" is done.

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D149932
2023-05-08 10:34:53 -07:00