429 Commits

Author SHA1 Message Date
Nikita Popov
4ab87ffd1e
[SCCP] Enable PredicateInfo for non-interprocedural SCCP (#153003)
SCCP can use PredicateInfo to constrain ranges based on assume and
branch conditions. Currently, this is only enabled during IPSCCP.

This enables it for SCCP as well, which runs after functions have
already been simplified, while IPSCCP runs pre-inline. To a large
degree, CVP already handles range-based optimizations, but SCCP is more
reliable for the cases it can handle. In particular, SCCP works reliably
inside loops, which is something that CVP struggles with due to LVI
cycles.

I have made various optimizations to make PredicateInfo more efficient,
but unfortunately this still has significant compile-time cost (around
0.1-0.2%).
2025-08-19 10:59:38 +02:00
Andreas Jonson
1840106ddf
[SCCP] Add support for trunc nuw range. (#152990)
proof: https://alive2.llvm.org/ce/z/_7PVxq
2025-08-12 13:48:55 +02:00
Nikita Popov
ab323eb0c6 [SCCP][PredicateInfo] Do not predicate argument of lifetime intrinsic
Replacing the argument with a no-op bitcast violates a verifier
constraint, even if only temporarily. Any replacement based on it
would result in a violation even after the copy has been removed.

Fixes https://github.com/llvm/llvm-project/issues/153013.
2025-08-12 12:56:08 +02:00
Nikita Popov
ccd35e5b2f [SCCP] Add common prefix in test (NFC) 2025-08-11 14:58:36 +02:00
Nikita Popov
957312413b [SCCP] Generate test checks (NFC) 2025-08-11 14:42:47 +02:00
Andreas Jonson
330a589450
[PredicateInfo] Handle trunc nuw i1 condition. (#152988)
proof: https://alive2.llvm.org/ce/z/mxtn4L
2025-08-11 13:00:54 +02:00
Nikita Popov
35bad229c1
[PredicateInfo] Use bitcast instead of ssa.copy (#151174)
PredicateInfo needs some no-op to which the predicate can be attached.
Currently this is an ssa.copy intrinsic. This PR replaces it with a
no-op bitcast.
    
Using a bitcast is more efficient because we don't have the overhead of
an overloaded intrinsic. It also makes things slightly simpler overall.
2025-08-11 09:25:01 +02:00
Paul Walker
1528ddbe76
[ConstantFolding][SVE] Do not fold fcmp of denormal without known mode. (#150614)
This is a follow on to
https://github.com/llvm/llvm-project/pull/115407 that introduced code
which bypasses the splat handling for scalable vectors. To maintain
existing tests I have moved the early return until after the splat
handling so all vector types are treated equally.
2025-07-29 12:37:59 +01:00
Yingwei Zheng
9e587ce6f0
[SCCP] Simplify [us]cmp(X, Y) into X - Y (#144717)
If the difference between [us]cmp's operands is not greater than 1, we
can simplify it into `X - Y`.
Alive2: https://alive2.llvm.org/ce/z/JS55so
llvm-opt-benchmark diff:
https://github.com/dtcxzyw/llvm-opt-benchmark/pull/2464/files
2025-07-20 15:01:44 +08:00
Yingwei Zheng
519cb460f6
[SCCP] Remove masking operations (#142736)
CVP version:
2d5820cd72
Compile-time impact:
https://llvm-compile-time-tracker.com/compare.php?from=3ec0c5c7fef03985b43432c6b914c289d8a5435e&to=92b4df90695dd37defdabf8a30f0b0322b648a00&stat=instructions:u
2025-06-04 22:31:08 +08:00
Jeremy Morse
792a6f8119
[RemoveDIs] Remove "try-debuginfo-iterators..." test flags (#130298)
These date back to when the non-intrinsic format of variable locations
was still being tested and was behind a compile-time flag, so not all
builds / bots would correctly run them. The solution at the time, to get
at least some test coverage, was to have tests opt-in to non-intrinsic
debug-info if it was built into LLVM.

Nowadays, non-intrinsic format is the default and has been on for more
than a year, there's no need for this flag to exist.

(I've downgraded the flag from "try" to explicitly requesting
non-intrinsic format in some places, so that we can deal with tests that
are explicitly about non-intrinsic format in their own commit).
2025-03-14 15:50:49 +00:00
Nikita Popov
29441e4f5f
[IR] Convert from nocapture to captures(none) (#123181)
This PR removes the old `nocapture` attribute, replacing it with the new
`captures` attribute introduced in #116990. This change is
intended to be essentially NFC, replacing existing uses of `nocapture`
with `captures(none)` without adding any new analysis capabilities.
Making use of non-`none` values is left for a followup.

Some notes:
* `nocapture` will be upgraded to `captures(none)` by the bitcode
   reader.
* `nocapture` will also be upgraded by the textual IR reader. This is to
   make it easier to use old IR files and somewhat reduce the test churn in
   this PR.
* Helper APIs like `doesNotCapture()` will check for `captures(none)`.
* MLIR import will convert `captures(none)` into an `llvm.nocapture`
   attribute. The representation in the LLVM IR dialect should be updated
   separately.
2025-01-29 16:56:47 +01:00
Stephen Senran Zhang
2feffecb88
[ConstantRange] Estimate tighter lower (upper) bounds for masked binary and (or) (#120352)
Fixes #118108.

Co-author: Yingwei Zheng (@dtcxzyw)
2024-12-31 18:40:17 -08:00
Nikita Popov
10f315dc9c
[ConstantFolding] Infer getelementptr nuw flag (#119214)
Infer nuw from nusw and nneg. This is the constant expression variant of
https://github.com/llvm/llvm-project/pull/111144.

Proof: https://alive2.llvm.org/ce/z/ihztLy
2024-12-09 16:44:05 +01:00
Nikita Popov
b569ec6de6
[SCCP] Infer nuw for gep nusw with non-negative offsets (#118819)
If the GEP is nusw/inbounds and has all-non-negative offsets infer nuw
as well.

This doesn't have measurable compile-time impact.

Proof: https://alive2.llvm.org/ce/z/ihztLy
2024-12-06 09:52:32 +01:00
Nikita Popov
2bd3174226 [SCCP] Add tests for gep nuw inference (NFC) 2024-12-05 16:10:13 +01:00
Nikita Popov
bb03a18470 [SCCP] Regenerate test checks (NFC)
The checks generated by old UTC version fail on this test due to
missing signature matching, so regenerate it with a newer one.
2024-12-05 14:55:29 +01:00
Lee Wei
9bf6365237
[llvm] Remove br i1 undef from some regression tests [NFC] (#118419)
This PR removes tests with `br i1 undef` under
`llvm/tests/Transforms/ObjCARC, Reassociate, SCCP, SLPVectorizer...`.
After this PR, I'll continue to fix tests under `llvm/tests/CodeGen`,
which has more UB tests than `llvm/tests/Transforms`.
2024-12-03 20:54:36 +00:00
Paul Walker
56c091ea71
[LLVM][IR] Use splat syntax when printing ConstantExpr based splats. (#116856)
This brings the printing of scalable vector constant splats inline with
their fixed length counterparts.
2024-11-21 11:21:12 +00:00
Matt Arsenault
cd88bfcb59
ConstantFolding: Do not fold fcmp of denormal without known mode (#115407)
Fixes #114947
2024-11-13 07:43:50 -08:00
Paul Walker
38fffa630e
[LLVM][IR] Use splat syntax when printing Constant[Data]Vector. (#112548) 2024-11-06 11:53:33 +00:00
Hari Limaye
b396921d0c
[SCCP] Handle llvm.vscale intrinsic calls (#114033)
Teach SCCP to compute a constant range for calls to llvm.vscale
intrinsics.
2024-10-31 12:22:15 +00:00
Serge Pavlov
819abe412d
[Test] Fix usage of constrained intrinsics (#113523)
Some tests contain errors in constrained intrinsic usage, such as missed
or extra type parameters, wrong type parameters order and some other.

---------

Co-authored-by: Andy Kaylor <andy_kaylor@yahoo.com>
2024-10-28 14:07:32 +07:00
Hari Limaye
c6931c2525
[FuncSpec] Only compute Latency bonus when necessary (#113159)
Only compute the Latency component of a specialisation's Bonus when
necessary, to avoid unnecessarily computing the Block Frequency
Information for a Function.
2024-10-23 09:05:44 +01:00
Yonghong Song
becc02ce93 Revert "[Transforms][IPO] Add func suffix in ArgumentPromotion and DeadArgume… (#105742)"
This reverts commit 959448fbd6bc6f74fb3f9655b1387d0e8a272ab8.
Reverting because multiple test failures e.g.
  https://lab.llvm.org/buildbot/#/builders/187/builds/1290
  https://lab.llvm.org/buildbot/#/builders/153/builds/9389
and maybe a few others.
2024-09-19 03:54:13 -07:00
yonghong-song
959448fbd6
[Transforms][IPO] Add func suffix in ArgumentPromotion and DeadArgume… (#105742)
…ntElimination

ArgumentPromotion and DeadArgumentElimination passes could change
function signatures but the function name remains the same as before the
transformation. This makes it hard for tracing with bpf programs where
user tends to use function signature in the source. See discussion [1]
for details.

This patch added suffix to functions whose signatures are changed. The
suffix lets users know that function signature has changed and they need
to impact the IR or binary to find modified signature before tracing
those functions.

The suffix for ArgumentPromotion is ".argprom" and the suffixes for
DeadArgumentElimination are ".argelim" and ".retelim". The suffix also
gives user hints about what kind of transformation has been done.

With this patch, I built a recent linux kernel with full LTO enabled. I
got 4 functions with only argpromotion like
```
  set_track_update.argelim.argprom
  pmd_trans_huge_lock.argprom
  ...
```
I got 1058 functions with only deadargelim like
```
  process_bit0.argelim
  pci_io_ecs_init.argelim
  ...
```
I got 3 functions with both argpromotion and deadargelim
```
  set_track_update.argelim.argprom
  zero_pud_populate.argelim.argprom
  zero_pmd_populate.argelim.argprom
```

  [1] https://github.com/llvm/llvm-project/issues/104678
2024-09-19 10:21:58 +02:00
Nikita Popov
b7e51b4f13
[IPSCCP] Infer attributes on arguments (#107114)
During inter-procedural SCCP, also infer attributes on arguments, not
just return values. This allows other non-interprocedural passes to make
use of the information later.
2024-09-16 10:23:41 +02:00
Nikita Popov
04742f34b3 [SCCP] Add test for nonnull argument inference (NFC) 2024-09-09 10:28:49 +02:00
Nikita Popov
c80cabfcbe [SCCP] Avoid use of undef value in test (NFC)
Avoid optimization away most of the code if we resolve this to
a specific value.
2024-09-03 14:25:07 +02:00
Nikita Popov
fe1a1eee2f [Tests] Regenerate test checks (NFC) 2024-09-03 11:42:47 +02:00
Nikita Popov
24fe1d4fd6
[SCCP] Infer return attributes in SCCP as well (#106732)
We can infer the range/nonnull attributes in non-interprocedural SCCP as
well. The results may be better after the function has been simplified.
2024-09-02 11:44:37 +02:00
Nikita Popov
d6ad551670
[IPSCCP] Infer nonnull return attribute (#106553)
Similarly to the existing range attribute inference, also infer the
nonnull attribute on function return values.

I think in practice FunctionAttrs will handle nearly all cases, the main
one I think it doesn't is cases involving branch conditions. But as we
already have the information here, we may as well materialize it.
2024-08-30 09:38:15 +02:00
Nikita Popov
ba52a09abe [IPSCCP] Add test for returning nonnull pointer (NFC) 2024-08-29 14:43:38 +02:00
Nikita Popov
7f59264d46
[IPSCCP] Intersect attribute info for interprocedural args (#106397)
IPSCCP can currently return worse results than SCCP for arguments that
are tracked interprocedurally, because information from attributes is
not used for them.

Fix this by intersecting in the attribute information when propagating
lattice values from calls.
2024-08-29 09:34:56 +02:00
Nikita Popov
b8c0e8ad10 [IPSCCP] Add extra tests for interprocedural arg attr handling (NFC) 2024-08-28 15:55:14 +02:00
Nikita Popov
657f26f038 [SCCP] Add more non-null roots
Also consider allocas non-null (subject to the usual caveats),
and consider nonnull/dereferenceable metadata on calls.
2024-08-27 15:53:22 +02:00
Nikita Popov
ed1c1da048 [SCCP] Add tests for more non-null roots (NFC) 2024-08-27 15:17:51 +02:00
Nikita Popov
1cea5c2138
[SCCP] Propagate non-null pointers (#106090)
Add NotConstant(Null) roots for nonnull arguments and then propagate
them through nuw/inbounds GEPs.

Having this functionality in SCCP is useful because it allows reliably
eliminating null comparisons, independently of how deeply nested they
are in selects/phis. This handles cases that would hit a cutoff in
ValueTracking otherwise.

The implementation is something of a MVP, there are a number of obvious
extensions (e.g. allocas are also non-null).
2024-08-27 09:13:41 +02:00
Nikita Popov
41f2f1f028 [SCCP] Add tests for non-null pointers (NFC) 2024-08-26 16:35:26 +02:00
Nikita Popov
03e0be90ca [SCCP] Make use of argument attributes in non-ip SCCP
Initialize arguments based on attributes instead of hardcoding them
to overdefined. This was already properly done for ipsccp.
2024-08-26 15:09:33 +02:00
Nikita Popov
1e5f336a72 [SCCP] Run test with both ipsccp and sccp (NFC) 2024-08-26 15:09:33 +02:00
Pedro Lobo
dad14d4d72
[SCCP] Merge return range attributes (#105998)
Take the intersection of the existing range attribute for the return
value and the inferred range.
2024-08-26 09:35:05 +02:00
Alexis Engelke
933b80006a
[Support][NFC] Use DomTreeBase methods in SemiNCA (#101059)
Previously, there were two implementations with identical behavior to
erase a node from a dominator tree, one in the DomTreeBase and one in
SemiNCAInfo. Remove the latter, as it is completely redundant.

Also, use getNode() instead of a direct access into DomTreeNodes. This
will simplify replacing the data structure of DomTreeNodes later on.

While at it, also use swap+pop_back instead of erase when removing a
node from the children vector to avoid O(n) copy. This slightly changes
the order of the tree nodes after removal, but should have no impact.
2024-07-30 12:00:59 +02:00
Thomas Hashem
e6fa09f445
[SCCP] Add context to SimplifyQuery (#100831) 2024-07-29 15:21:57 +02:00
James Y Knight
b7e4fba6e5
Cleanup x86_mmx after removing IR type (#100646)
After #98505, the textual IR keyword `x86_mmx` was temporarily made to
parse as `<1 x i64>`, so as not to require a lot of test update noise.

This completes the removal of the type, by removing the`x86_mmx` keyword
from the IR parser, and making the (now no-op) test updates via `sed -i
's/\bx86_mmx\b/<1 x i64>/g' $(git grep -l x86_mmx llvm/test/)`.
Resulting bitcasts from <1 x i64> to itself were then manually deleted.

Changes to llvm/test/Bitcode/compatibility-$VERSION.ll were reverted, as
they're intended to be equivalent to the .bc file, if parsed by old
LLVM, so shouldn't be updated.

A few tests were removed, as they're no longer testing anything, in the
following files:
- llvm/test/Transforms/GlobalOpt/x86_mmx_load.ll
- llvm/test/Transforms/InstCombine/cast.ll
- llvm/test/Transforms/InstSimplify/ConstProp/gep-zeroinit-vector.ll

Works towards issue #98272.
2024-07-28 18:12:47 -04:00
Nikita Popov
7d74ca9513
[ValueLattice] Support constant vectors in mergeIn() (#99466)
This is a followup to vector support in LVI/CVP/SCCP. In mergeIn(), if
one of the operands is a vector of integer constant, we should try to
convert it into a constant range, in case that allows performing a range
union to something better than overdefined.
2024-07-18 16:48:21 +02:00
Nikita Popov
c1263b3264 [SCCP] Add tests for vectors ins phis (NFC) 2024-07-18 10:45:33 +02:00
Sudharsan Veeravalli
26af44b398
[DebugInfo][SCCPSolver] Fix missing debug locations (#98876)
Fixes #98875
2024-07-18 09:03:03 +01:00
Nikita Popov
6b76c1e64c
[SCCP] Add support for vectors (#98026)
Add preliminary support for vectors of integers by using the
`ValueLatticeElement::asConstantRange()` helper instead of a custom
implementation, and relxing various integer type checks.

This enables just the part that works automatically, e.g. icmps with a
constant vector operand aren't supported yet.

The change in ssa.copy handling is because asConstantRange() returns an
unknown LV for empty range, while SCCP's getConstantRange() returned a
full range. I've made the change to preserve the existing behavior.
2024-07-09 12:25:53 +02:00
Nikita Popov
16bb8c16aa [SCCP] Use poison instead of undef when zapping returns 2024-06-25 12:35:25 +02:00