989 Commits

Author SHA1 Message Date
Yingwei Zheng
d8b1b46cd3
[IR] Handle fabs LHS in fcmpImpliesClass (#152913)
Closes https://github.com/llvm/llvm-project/issues/152824.
2025-08-10 22:55:04 +08:00
Alexander Richardson
3a4b351ba1
[IR] Introduce the ptrtoaddr instruction
This introduces a new `ptrtoaddr` instruction which is similar to
`ptrtoint` but has two differences:

1) Unlike `ptrtoint`, `ptrtoaddr` does not capture provenance
2) `ptrtoaddr` only extracts (and then extends/truncates) the low
   index-width bits of the pointer

For most architectures, difference 2) does not matter since index (address)
width and pointer representation width are the same, but this does make a
difference for architectures that have pointers that aren't just plain
integer addresses such as AMDGPU fat pointers or CHERI capabilities.

This commit introduces textual and bitcode IR support as well as basic code
generation, but optimization passes do not handle the new instruction yet
so it may result in worse code than using ptrtoint. Follow-up changes will
update capture tracking, etc. for the new instruction.

RFC: https://discourse.llvm.org/t/clarifiying-the-semantics-of-ptrtoint/83987/54

Reviewed By: nikic

Pull Request: https://github.com/llvm/llvm-project/pull/139357
2025-08-08 10:12:39 -07:00
Nikita Popov
c23b4fbdbb
[IR] Remove size argument from lifetime intrinsics (#150248)
Now that #149310 has restricted lifetime intrinsics to only work on
allocas, we can also drop the explicit size argument. Instead, the size
is implied by the alloca.

This removes the ability to only mark a prefix of an alloca alive/dead.
We never used that capability, so we should remove the need to handle
that possibility everywhere (though many key places, including stack
coloring, did not actually respect this).
2025-08-08 11:09:34 +02:00
Nikita Popov
c1b387e23d
[MemoryLocation] Compute lifetime size from alloca size (#151982)
Split out from #150248:

Since #150944 the size passed to lifetime.start/end is considered
meaningless. The lifetime always applies to the whole alloca.

This adjusts MemoryLocation to determine the MemoryLocation size from
the alloca size, instead of using the argument.
2025-08-05 10:47:07 +02:00
jeremyd2019
e5402c977f
[llvm] Enable building Analysis plugins on Cygwin (#151397)
In #112303 they were enabled for Windows dylib builds, but the condition
excluded Cygwin in that case. Their dynamic libraries work the same way,
so adjust the condition accordingly.

This fixes the plugin tests on Cygwin.
2025-07-31 10:41:02 -07:00
Alexander Richardson
fc2850fc76
[IR2VecTest] Avoid magic constants
Instead make the members of Vocabulary public. This was causing test
failures with https://github.com/llvm/llvm-project/pull/139357.

Reviewed By: svkeerthy, boomanaiden154

Pull Request: https://github.com/llvm/llvm-project/pull/150878
2025-07-28 09:50:51 -07:00
Jasmine Tang
e7ac49977a
[InstSimplify] Add poison propagation for trivially vectorizable intrinsics (#149243)
Fixes https://github.com/llvm/llvm-project/issues/146769

Test cases added to
`llvm/test/Transforms/InstSimplify/fold-intrinsics.ll`
2025-07-19 19:37:21 -07:00
S. VenkataKeerthy
61a45d20cf
[IR2Vec][NFC] Add helper methods for numeric ID mapping in Vocabulary (#149212)
Add helper methods to IR2Vec's Vocabulary class for numeric ID mapping and vocabulary size calculation. These APIs will be useful in triplet generation for `llvm-ir2vec` tool (See #149214). 

(Tracking issue - #141817)
2025-07-17 13:40:51 -07:00
jjasmine
2206c7d4af
[InstSimplify] Fold trig functions call of poison to poison (#148969)
Fold trig functions call of poison to poison.

This includes sin, cos, asin, acos, atan, atan2, sinh, cosh, sincos,
sincospi.

Test cases are fixed and also added to
llvm/test/Transforms/InstSimplify/fold-intrinsics.ll just like in
https://github.com/llvm/llvm-project/pull/146750
2025-07-16 08:35:13 -07:00
S. VenkataKeerthy
e86bd05bdc
[IR2Vec] Restructuring Vocabulary (#145119)
This PR restructures the vocabulary. 

* String based look-ups are removed. Vocabulary is changed from a map to vector. (#141832)
* Grouped all the vocabulary related methods under a single class - `ir2vec::Vocabulary`. This replaces `IR2VecVocabResult`.
* `ir2vec::Vocabulary` effectively abstracts out the _layout_ and other internal details of the vector structure. Exposes necessary APIs for accessing the Vocabulary. 

These changes ensure that _all_ known opcodes and types are present in the vocabulary. We have retained the original operands. This can be extended going forward. 

(Tracking issue - #141817)
2025-07-14 11:07:29 -07:00
Arthur Eubanks
1cd2165afe
[SCEV] Take global variable linkage into account when comparing values (#148071)
Current the comparator is inconsistent when we have two external globals
and one internal globals due to
```
    if (IsGVNameSemantic(LGV) && IsGVNameSemantic(RGV))
      return LGV->getName().compare(RGV->getName());
```

The internal global compares equal to (not strictly less than) the
external globals, but the external globals are not equal.

Fixes #147862.
2025-07-11 09:36:34 -07:00
jjasmine
07286b1fcd
[InstCombine] Propagate poison pow[i], [us]add, [us]sub and [us]mul (#146750)
Fixes #146560 as well as propagate poison for [us]add, [us]sub and
[us]mul
2025-07-04 22:55:07 +01:00
Nikita Popov
1d5d125648
[ConstantFolding] Consolidate poison propagation for intrinsics (#146878)
This consolidates the "fold poison arg to poison result" constant
folding logic for intrinsics, based on a common
intrinsicPropagatesPoison() helper, which is also used for poison
propagation reasoning in ValueTracking. This ensures that the set of
supported intrinsics is consistent.

This add ucmp, scmp, smul.fix, smul.fix.sat, canonicalize and sqrt to
the intrinsicPropagatesPoison list, as these were handled by
ConstantFolding but not ValueTracking. The ctpop test is an example of
the converse, where it was handled by ValueTracking but not
ConstantFolding.
2025-07-04 09:16:28 +02:00
Kazu Hirata
bbf4402635
[Analysis] Remove a redundant control flow statement (NFC) (#146708) 2025-07-02 09:32:30 -07:00
S. VenkataKeerthy
119292c40b
[IR2Vec] Add out-of-place arithmetic operators to Embedding class (#145118)
This PR adds out-of-place arithmetic operators (`+`, `-`, `*`) to the `Embedding` class in IR2Vec, complementing the existing in-place operators (`+=`, `-=`, `*=`). 

Tests have been added to verify the functionality of these new operators.

(Tracking issue - #141817)
2025-07-01 12:09:54 -07:00
S. VenkataKeerthy
efe0deae3f
[NFC][IR2Vec] Increasing tolerance in approximatelyEquals() of Embedding (#145117)
Increase the default tolerance for `approximatelyEquals` in IR2Vec's Embedding class from 1e-6 to 1e-4.

(Tracking issue - #141817)
2025-07-01 12:03:37 -07:00
Simon Pilgrim
67be4fe3d5 Fix MSVC implicit double -> float truncation warning. NFC. 2025-07-01 08:48:16 +01:00
S. VenkataKeerthy
0a69c83421
[NFC][IR2Vec] Remove unreachable code and simplify invalid mode test (#146459)
The code following `llvm_unreachable`  is optimized out in Release builds. In this case, `Embedder::create` do not seem to return `nullptr` causing `CreateInvalidMode` test to break. Hence removing `llvm_unreachable`.
2025-06-30 20:31:47 -07:00
Kazu Hirata
8cf3b989a9 [Analysis] Fix a warning
This patch fixes:

  llvm/unittests/Analysis/FunctionPropertiesAnalysisTest.cpp:132:12:
  error: moving a local object in a return statement prevents copy
  elision [-Werror,-Wpessimizing-move]
2025-06-30 18:44:45 -07:00
S. VenkataKeerthy
9438048816
[IR2Vec] Simplifying creation of Embedder (#143999)
This change simplifies the API by removing the error handling complexity. 

- Changed `Embedder::create()` to return `std::unique_ptr<Embedder>` directly instead of `Expected<std::unique_ptr<Embedder>>`
- Updated documentation and tests to reflect the new API
- Added death test for invalid IR2Vec kind in debug mode
- In release mode, simply returns nullptr for invalid kinds instead of creating an error

(Tracking issue - #141817)
2025-06-30 18:24:08 -07:00
S. VenkataKeerthy
0745eb501d
[IR2Vec] Scale embeddings once in vocab analysis instead of repetitive scaling (#143986)
Changes to scale opcodes, types and args once in `IR2VecVocabAnalysis` so that we can avoid scaling each time while computing embeddings. This PR refactors the vocabulary to explicitly define 3 sections---Opcodes, Types, and Arguments---used for computing Embeddings. 

(Tracking issue - #141817 ; partly fixes - #141832)
2025-06-30 23:09:19 +02:00
S. VenkataKeerthy
dcf8ec9218
Reland "[MLGO][IR2Vec] Integrating IR2Vec with MLInliner (#143479)" (#145664)
Relanding #143479 after fixes. 

Removed `NumberOfFeatures` from the `FeatureIndex` enum as the number of features used depends on whether IR2Vec embeddings are used.
2025-06-30 22:37:39 +02:00
Antonio Frighetto
69b8e59f29 [ValueTracking] Forward-declare class instead of including header (NFC)
The header inclusion was previously causing a build time regression.
2025-06-28 11:21:24 +02:00
Antonio Frighetto
c11ea449e5 [ValueTracking] Add matchSimpleBinaryIntrinsicRecurrence helper
Similarly to what it is being done to match simple recurrence cycle
relations, attempt to match value-accumulating recurrences of kind:
```
  %umax.acc = phi i8 [ %umax, %backedge ], [ %a, %entry ]
  %umax = call i8 @llvm.umax.i8(i8 %umax.acc, i8 %b)
```
Preliminary work to let InstCombine avoid folding such recurrences,
so that simple loop-invariant computation may get hoisted. Minor
opportunity to refactor out code as well.
2025-06-27 19:04:28 +02:00
Matt Arsenault
c91cbafad2
TargetLibraryInfo: Delete default TargetLibraryInfoImpl constructor (#145826)
It should not be possible to construct one without a triple. It would
also be nice to delete TargetLibraryInfoWrapperPass, but that is more
difficult.
2025-06-26 16:12:36 +09:00
Andrew Rogers
1abe1aa7b2
[llvm] annotate remaining Analysis library interfaces for DLL export (#145359) 2025-06-25 12:18:07 -07:00
S. VenkataKeerthy
d37325ea95
Revert "[MLGO][IR2Vec] Integrating IR2Vec with MLInliner (#143479)" (#145418)
This reverts commit af2c06ecd610735dfa5d236c6d5f109e4f2334e6 as it
causes failure of lit test (Transforms/Inline/ML/interactive-mode.ll)
2025-06-24 00:48:16 +02:00
S. VenkataKeerthy
af2c06ecd6
[MLGO][IR2Vec] Integrating IR2Vec with MLInliner (#143479)
Changes to use Symbolic embeddings in MLInliner. 

(Fixes #141836, Tracking issue - #141817)
2025-06-23 14:07:45 -07:00
Marco Elver
0662045bdf
[TLI] Add support for pvalloc() (#144949)
While pvalloc() is a legacy POSIX function, it remains widely available
in common C libraries like glibc.

Model pvalloc() in TargetLibraryInfo, allowing LLVM to correctly infer
its attributes.
2025-06-23 12:03:35 +02:00
S. VenkataKeerthy
09c54c2e9e
[IR2Vec] Minor vocab changes and exposing weights (#143200)
This PR changes some asserts in Vocab to hard checks that emit error and exposes flags and constructor to help in unit tests.

(Tracking issue - #141817)
2025-06-13 10:43:22 -07:00
S. VenkataKeerthy
32649e017e
[IR2Vec] Exposing Embedding as an data type wrapped around std::vector<double> (#143197)
Currently `Embedding` is `std::vector<double>`. This PR makes it a data type wrapped around `std::vector<double>` to overload basic arithmetic operators and expose comparison operations. It _simplifies_ the usage here and in the passes where operations on `Embedding` would be performed.

(Tracking issue - #141817)
2025-06-10 15:12:16 -07:00
Jeremy Morse
0e4b8b8f81
[DebugInfo][RemoveDIs] Rip out the UseNewDbgInfoFormat flag (#143207)
Start removing debug intrinsics support -- starting with the flag that
controls production of their replacement, debug records. This patch
removes the command-line-flag and with it the ability to switch back to
intrinsics. The module / function / block level "IsNewDbgInfoFormat"
flags get hardcoded to true, I'll to incrementally remove things that
depend on those flags.
2025-06-09 19:36:34 +01:00
Yingwei Zheng
2f15637e04
[ValueTracking] Update Ordered when both operands are non-NaN. (#143349)
When the original predicate is ordered and both operands are non-NaN,
`Ordered` should be set to true. This variable still matters even if
both operands are non-NaN because FMF only applies to select, not fcmp.

Closes https://github.com/llvm/llvm-project/issues/143123.
2025-06-09 15:46:09 +08:00
Ramkumar Ramachandra
b40e4ceaa6
[ValueTracking] Make Depth last default arg (NFC) (#142384)
Having a finite Depth (or recursion limit) for computeKnownBits is very
limiting, but is currently a load-bearing necessity, as all KnownBits
are recomputed on each call and there is no caching. As a prerequisite
for an effort to remove the recursion limit altogether, either using a
clever caching technique, or writing a easily-invalidable KnownBits
analysis, make the Depth argument in APIs in ValueTracking uniformly the
last argument with a default value. This would aid in removing the
argument when the time comes, as many callers that currently pass 0
explicitly are now updated to omit the argument altogether.
2025-06-03 17:12:24 +01:00
S. VenkataKeerthy
741136a8ac
[NFC][IR2Vec] Removing Dimension from Embedder::Create (#142486)
This PR removes the necessity to know the dimension of the embeddings while invoking `Embedder::Create`. Having the `Dimension` parameter introduces complexities in downstream consumers. 

(Tracking issue - #141817)
2025-06-02 15:05:11 -07:00
Yingwei Zheng
1984c7539e
[ValueTracking] Do not use FMF from fcmp (#142266)
This patch introduces an FMF parameter for
`matchDecomposedSelectPattern` to pass FMF flags from select, instead of
fcmp.

Closes https://github.com/llvm/llvm-project/issues/137998.
Closes https://github.com/llvm/llvm-project/issues/141017.
2025-06-02 18:21:14 +08:00
S. VenkataKeerthy
494c82e709
[IR2Vec] Support for lazy computation of BB Embeddings (#142033)
This PR exposes interfaces to compute embeddings at BB level. This would be necessary for delta patching the embeddings in MLInliner (#141836).

(Tracking issue - #141817)
2025-05-29 15:29:55 -07:00
S. VenkataKeerthy
e74b45e078
[IR2Vec] Adding unit tests (#141873)
This PR adds unit tests for IR2Vec

(Tracking issue - #141817)
2025-05-29 13:35:29 -07:00
Helena Kotas
945e7d33e8
[DirectX] Update resource type names in DXIL metadata to include element type (#140937)
Update resource type names for globals variables that we generate in `DXILTranslateMetadata` pass to include element type. This change prevents duplicate types for identical resources and brings the DXIL metadata names it closer to what DXC generates.
2025-05-29 11:44:34 -07:00
Teresa Johnson
cc6f446d38
[MemProf] Add basic summary section support (#141805)
This patch adds support for a basic MemProf summary section, which is
built along with the indexed MemProf profile (e.g. when reading the raw
or YAML profiles), and serialized through the indexed profile just after
the header.

Currently only 6 fields are written, specifically the number of contexts
(total, cold, hot), and the max context size (cold, warm, hot).

To support forwards and backwards compatibility for added fields in the
indexed profile, the number of fields serialized first. The code is
written to support forwards compatibility (reading newer profiles with
additional summary fields), and comments indicate how to implement
backwards compatibility (reading older profiles with fewer summary
fields) as needed.

Support is added to print the summary as YAML comments when displaying
both the raw and indexed profiles via `llvm-profdata show`. Because they
are YAML comments, the YAML reader ignores these (the summary is always
recomputed when building the indexed profile as described above).

This necessitated moving some options and a couple of interfaces out of
Analysis/MemoryProfileInfo.cpp and into the new
ProfileData/MemProfSummary.cpp file, as we need to classify context
hotness earlier and also compute context ids to build the summary from
older indexed profiles.
2025-05-28 13:12:41 -07:00
Helena Kotas
219312c623
[DirectX] Gather resource names in DXIL resource analysis (#140633)
Gather resource names from `llvm.dx.resource.handlefrombinding` calls during DXIL resource analysis and add them to `DXILResourceMap`.

Part 3/4 of llvm/llvm-project#105059
2025-05-28 08:55:11 -07:00
Andrew Rogers
d4d4a04771
[llvm] annotate interfaces in llvm/Analysis for DLL export (#136623)
## Purpose

This patch is one in a series of code-mods that annotate LLVM’s public
interface for export. This patch annotates the `llvm/Analysis` library.
These annotations currently have no meaningful impact on the LLVM build;
however, they are a prerequisite to support an LLVM Windows DLL (shared
library) build.

## Background

This effort is tracked in #109483. Additional context is provided in
[this
discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307),
and documentation for `LLVM_ABI` and related annotations is found in the
LLVM repo
[here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst).

The bulk of these changes were generated automatically using the
[Interface Definition Scanner (IDS)](https://github.com/compnerd/ids)
tool, followed formatting with `git clang-format`.

The following manual adjustments were also applied after running IDS on
Linux:
- Add `#include "llvm/Support/Compiler.h"` to files where it was not
auto-added by IDS due to no pre-existing block of include statements.
- Add `LLVM_TEMPLATE_ABI` and `LLVM_EXPORT_TEMPLATE` to exported
instantiated templates
- Add `LLVM_ABI` to a subset of private class methods and fields that
require export
- Add `LLVM_ABI` to a small number of symbols that require export but
are not declared in headers

## Validation

Local builds and tests to validate cross-platform compatibility. This
included llvm, clang, and lldb on the following configurations:

- Windows with MSVC
- Windows with Clang
- Linux with GCC
- Linux with Clang
- Darwin with Clang
2025-05-27 15:14:20 -07:00
Peter Collingbourne
645f0e6723
IR: Make Module::getOrInsertGlobal() return a GlobalVariable.
After pointer element types were removed this function can only return
a GlobalVariable, so reflect that in the type and comments and clean
up callers.

Reviewers: nikic

Reviewed By: nikic

Pull Request: https://github.com/llvm/llvm-project/pull/141323
2025-05-27 12:23:12 -07:00
Tim Gymnich
571a24c314
Reland [llvm] add GenericFloatingPointPredicateUtils #140254 (#141065)
#140254 was previously missing 2 files in the bazel build config.
2025-05-22 17:17:02 +02:00
Kewen12
c47a5fbb22
Revert "[llvm] add GenericFloatingPointPredicateUtils (#140254)" (#140968)
This reverts commit d00d74bb2564103ae3cb5ac6b6ffecf7e1cc2238. 

The PR breaks our buildbots and blocks downstream merge.
2025-05-21 19:31:14 -04:00
Tim Gymnich
d00d74bb25
[llvm] add GenericFloatingPointPredicateUtils (#140254)
add `GenericFloatingPointPredicateUtils` in order to generalize
effects of floating point comparisons on `KnownFPClass` for both IR and
MIR.

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-05-21 23:45:31 +02:00
Teresa Johnson
c526683c7f
[MemProf] Simplify unittest save and restore of options (#139117)
Address post-commit review feedback for PR139092 (and fix another
instance of the same code). Save and restore option values via a saved
bool value, instead of invoking cl::ResetAllOptionOccurrences.
2025-05-08 10:57:20 -07:00
Teresa Johnson
9c4c2426d5
[MemProf] Fix bug introduced by restructuring in optional handling (#139092)
The restructuring of the context pruning patch in PR138792
(764614e6355e214c6b64c715d105007b1a4b97fd) introduced a bug under the
non-default -memprof-keep-all-not-cold-contexts handling.

Added more testing of this mode which would have caught the issue.

While here, fix the newly added function name to match code style.
2025-05-08 08:37:45 -07:00
Matt Arsenault
609a8331a0
ValueTracking: Handle minimumnum and maximumnum in computeKnownFPClass (#138737)
For now use the same treatment as minnum/maxnum, but these should
diverge. alive2 seems happy with this, except for some preexisting bugs
with weird denormal modes.
2025-05-07 08:02:24 +02:00
Kazu Hirata
2f3067ed69
[llvm] Remove unused local variables (NFC) (#138454) 2025-05-04 09:38:16 -07:00