453 Commits

Author SHA1 Message Date
Philip Reames
49b17a0c1c
[MIR] Further cleanup on mutliple save/restore point support [nfc] (#153250)
Remove the type alias now that the std::variant aspect is gone, directly
using std::vector in the few places that need it is more idiomatic.

Move a routine from a core header to single user.
2025-08-12 14:16:41 -07:00
Elizaveta Noskova
bbde6be841
[llvm] Support multiple save/restore points in mir (#119357)
Currently mir supports only one save and one restore point
specification:

```
  savePoint:       '%bb.1'
  restorePoint:    '%bb.2'
```

This patch provide possibility to have multiple save and multiple
restore points in mir:

```
  savePoints:
    - point:           '%bb.1'
  restorePoints:
    - point:           '%bb.2'
```

Shrink-Wrap points split Part 3.
RFC:
https://discourse.llvm.org/t/shrink-wrap-save-restore-points-splitting/83581

Part 1: https://github.com/llvm/llvm-project/pull/117862
Part 2: https://github.com/llvm/llvm-project/pull/119355
Part 4: https://github.com/llvm/llvm-project/pull/119358
Part 5: https://github.com/llvm/llvm-project/pull/119359
2025-08-12 16:34:29 +03:00
Nikita Popov
549990124d
[llvm-reduce] Do not replace lifetime pointer arg with zero/one/poison (#151697)
The lifetime argument is now required to be an alloca, so we should not
try to replace it with a constant.

We also shouldn't try to change the size argument to zero/one, similar
to how we avoid zero-size allocas.
2025-08-04 09:06:38 +02:00
Nikita Popov
c4c0a59741
[llvm-reduce] Do not convert lifetime operand to argument (#151694)
The lifetime argument is now required to be an alloca, so do not try to
convert it to a function argument.

The reduction is now going to leave behind an unused alloca with
lifetime markers, which should be cleaned up separately.

I'd say this fixes https://github.com/llvm/llvm-project/issues/93713. It
doesn't remove the lifetime markers as the issue suggests, but at least
they're now not going to be on the argument.
2025-08-01 15:34:52 +02:00
Eli Friedman
9f82ac5738
Remove GlobalObject::getAlign/setAlignment (#143188)
Currently, GlobalObject has an "alignment" property... but it's
basically nonsense: alignment doesn't mean the same thing for variables
and functions, and it's completely meaningless for ifuncs.

This "removes" (actually marking protected) the methods from
GlobalObject, adds the relevant methods to Function and GlobalVariable,
and adjusts the code appropriately.

This should make future alignment-related cleanups easier.
2025-06-09 13:51:03 -07:00
Kazu Hirata
54d836a080
[llvm] Use *Set::insert_range (NFC) (#138237) 2025-06-02 19:48:13 -07:00
Kazu Hirata
ef2531b63c
[llvm-reduce] Remove unused includes (NFC) (#141322)
These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.
2025-05-23 23:58:52 -07:00
Matt Arsenault
d76a1639e0
llvm-reduce: Support exotic terminators in instructions-to-return (#134794)
Use splitBasicBlock and avoid directly dealing with the specific of
how to trim the existing terminators. We just need to deal with
unconditional branch to return.
2025-05-02 22:46:28 +02:00
Matt Arsenault
e3a81df38c
llvm-reduce: Change function return types if function is not called (#134035)
Extend the early return on value reduction to mutate the function return
type if the function has no call uses. This could be generalized to rewrite
cases where all callsites are used, but it turns out that complicates the
visitation order given we try to compute all opportunities up front.

This is enough to cleanup the common case where we end up with one
function with a return of an uninteresting constant.
2025-05-02 16:19:58 +02:00
Matt Arsenault
26bc8b0ffa
llvm-reduce: Reduce with early return of arguments (#133627)
Extend the instruction -> return reduction with one that inserts
return of function arguments. Not sure how useful this really is. This
has more freedom since we could insert the return anywhere in the function,
but this just inserts the return in the entry block.
2025-05-02 16:17:14 +02:00
Matt Arsenault
e66592509b
llvm-reduce: Add values to return reduction (#132686)
In void functions, try to replace instruction uses
with a new non-void return. If the return type matches
the instruction, also try to directly return it.

This handles most of the cases, but doesn't try to handle
all of the weird exception related terminators.

Also doesn't try to replace argument uses, although it could. We
could also handle cases where we can insert a simple cast to an
original return value. I didn't think too hard about where to put this
in the default pass order. In many cases it obviates the need for most
of the CFG folds, but I've left it near the end initially.

I also think this is too aggressive about removing dead code, and
should leave existing dead code alone. I'm also not sure why we have
both "removeUnreachableBlocks" and EliminateUnreachableBlocks" in Utils.

Fixes #66039, fixes #107327
2025-05-02 16:11:14 +02:00
Matt Arsenault
72f5ac442d llvm-reduce: Stop setting intermediate cloned function names
The name will be stolen from the original function, so there's
no point in setting an initial suffixed name.
2025-05-02 13:31:58 +02:00
Nikita Popov
4109bac330
[IR] Do not store Function inside BlockAddress (#137958)
Currently BlockAddresses store both the Function and the BasicBlock they
reference, and the BlockAddress is part of the use list of both the
Function and BasicBlock.

This is quite awkward, because this is not really a use of the function
itself (and walks of function uses generally skip block addresses for
that reason). This also has weird implications on function RAUW (as that
will replace the function in block addresses in a way that generally
doesn't make sense), and causes other peculiar issues, like the ability
to have multiple block addresses for one block (with different
functions).

Instead, I believe it makes more sense to specify only the basic block
and let the function be implied by the BB parent. This does mean that we
may have block addresses without a function (if the BB is not inserted),
but this should only happen during IR construction.
2025-05-02 09:40:50 +02:00
Kazu Hirata
ee17ca77e5
[llvm] Construct SmallVector with ArrayRef (NFC) (#136063) 2025-04-16 19:29:30 -07:00
Matt Arsenault
bae08dad69
llvm-reduce: Preserve uselistorder when writing thinlto bitcode (#133369)
Fixes #63621
2025-04-14 20:36:59 +02:00
Stephen Tozer
58211f55c5
[llvm-reduce] Fix incorrectly ignored null MD in ReduceDIMetadata (#108541)
Commit c2e62c7 updated the ReduceDIMetadata pass to be able to remove
DIGlobalVariableExpressions from MDNode operands; it also accidentally
prevented null operands from being preserved, which results in an
assertion being triggered:
`Targets == NoChunksCounter.count() && "number of chunks changes when
reducing"'

This patch allows us to correctly preserve null operands once again.
I've not got a test case for this yet - I'm hoping this patch is just
trivially correct as-is, because I've not got the hang of reducing a
test case for llvm-reduce yet, but I can get a test case generated if
needed.
2025-04-11 15:38:58 +01:00
Matt Arsenault
843fb7be38
llvm-reduce: Fix overly conservative operands-to-args user restriction (#133854)
I assume this was a leftover from typed pointers. It's easier to replace
the non-callee uses, they are just replacable pointer values.
2025-04-10 07:10:25 +02:00
Matt Arsenault
5587932e20
llvm-reduce: Use simpleSimplifyCFG in block reduction (#135028) 2025-04-10 06:12:24 +02:00
Matt Arsenault
2828328611
llvm-reduce: Link to command guide in help like bugpoint does (#134810) 2025-04-10 06:11:19 +02:00
Matt Arsenault
989bc69ceb
llvm-reduce: Trim includes in ReduceInstructions (#135022) 2025-04-09 21:14:42 +02:00
Jeremy Morse
40f9bb9e25
[DebugInfo][RemoveDIs] Eliminate another debug-info variation flag (#133917)
The "preserve input debug-info format" flag allowed some tooling to opt
into not seeing the new debug records yet, and to not autoupgrade. This
was good at the time, but un-necessary now that we'll be ditching
intrinsics shortly.

It also hides errors now: verify-uselistorder was hardcoding this flag
to on, and as a result it hasn't seen debug records before. Thus, we
missed a uselistorder variation: constant-expressions such as GEPs can
be contained within debug records and completely isolated from the value
hierachy, see the metadata-use-uselistorder.ll test. These Values didn't
get ordered, but were legitimate uses of constants like "i64 0", and we
now run into difficulty handling that. The patch to AsmWriter seeks
Values to order even through debug-info now.

Finally there are a few intrinsics-tests relying on this flag that we
can just delete, such as one in llvm-reduce and another few in the
LocalTest unit tests. For the fast-isel test, it was added in
https://reviews.llvm.org/D67703 explicitly for checking the size of
blocks without debug-info and in 1525abb9c94 the codepath it tests moved
towards being sunsetted. It'll be totally redundant once RemoveDIs is on
permanently.

Note that there's now no explicit test for the textual-IR autoupgrade
path. I submit that we can rely on the thousands of .ll files where
we've only been bothered to update the outputs, not the inputs, to debug
records.
2025-04-09 18:00:28 +01:00
Matt Arsenault
f0131c327e
llvm-reduce: Avoid reallocating per chunk iteration (#135029) 2025-04-09 18:57:53 +02:00
Matt Arsenault
1e9f46c1b3
llvm-reduce: Fix taking wrong error before exit (#135020) 2025-04-09 18:11:08 +02:00
Matt Arsenault
b6f4ec72f9
llvm-reduce: Add scope braces (#135025) 2025-04-09 18:10:13 +02:00
Matt Arsenault
3a0c95fb50
llvm-reduce: Fix introducing unreachable code in simplify conditionals (#133842)
After replacing the branch condition, this was calling simplifyCFG to
perform the cleanups of the branch. This is far too heavy of a hammer.
We do not want all of the extra optimizations in simplifyCFG, and
this could also leave behind dead code. Instead, minimally fold the
terminator and try to delete the newly dead code.

This is pretty much a direct copy of what bugpoint does.
2025-04-08 08:51:20 +07:00
Matt Arsenault
efca37fda5
llvm-reduce: Change exit code for uninteresting inputs (#134021)
This makes it easier to reduce llvm-reduce with llvm-reduce to filter
cases where the input reduced too much.

Not sure if it's possible to test the exit code in lit.
2025-04-02 23:43:06 +07:00
Matt Arsenault
2b7fe90a01
llvm-reduce: Avoid worklist in simplify-instruction (#134066) 2025-04-02 22:21:28 +07:00
Matt Arsenault
cde2ea377d
llvm-reduce: Defer a shouldKeep call in operand reduction (#133387)
Ideally shouldKeep is only called in contexts that will successfully
do something.
2025-04-02 15:00:41 +07:00
Matt Arsenault
09e19cfacf
llvm-reduce: Do not reduce alloca array sizes to 0 (#132864)
Fixes #64340
2025-04-02 13:44:45 +07:00
Matt Arsenault
964650b69e
llvm-reduce: Add reduceOperandsToPoison reduction (#132862)
For now use it only for TargetExtTypes, which do not always support
zero initializers.
2025-04-02 13:38:46 +07:00
Matt Arsenault
23d894e0a3 llvm-reduce: Fix comment typo 2025-04-02 11:43:09 +07:00
Matt Arsenault
adbe9e20bf
llvm-reduce: Skip setting br conditions on already constant branches (#133841)
If we are trying to simplify branch conditions to true, ignore branches
already set to a constant true. If we are simplifying to constant false,
ignore the already constant false cases. This saves steps in this edge
case, and avoids the side effect of running simplifycfg on blocks we
did not intend to modify.
2025-04-02 11:41:47 +07:00
Matt Arsenault
55ac652745
llvm-reduce: Do not delete convergencectrl in operand-bundles (#133858)
The IR verifier will fail if there are any convergent calls without
a convergencectrl bundle, if there are any convergencectrl bundles.

With the current verifier rules, we would need to drop all the instances
of convergencectrl in the function as a set, and strip all the
convergence
token intrinsics. As such, I think it would be more appropriate to have
a
separate convergence reduction pass.
2025-04-02 08:48:02 +07:00
Matt Arsenault
f60eed9344
llvm-reduce: Add target-features-attr reduction (#133887)
Try to reduce individual subtarget features in the "target-features"
attribute. This attempts a textual removal of the fields in the string,
not a semantic removal. Typically there's a lot of redundant feature spam
in the feature list implied by the target-cpu (which I really wish clang
would stop emitting). If we could parse these out, we could easily drop
the fields without testing anything.
2025-04-02 00:03:43 +07:00
Matt Arsenault
5c4302442b
llvm-reduce: Reduce global variable code model (#133865)
The current API doesn't have a way to unset it. The query returns
an optional, but the set doesn't. Alternatively I could switch the
set to also use optional.
2025-04-01 23:54:10 +07:00
Matt Arsenault
ec290a43f6
llvm-reduce: Reduce externally_initialized (#133859)
Not sure this is the right place to put it. This is a property
of GlobalVariable, not GlobalValue. But the ReduceGlobalVars
reduction tries to delete the value entirely.
2025-04-01 23:51:45 +07:00
Matt Arsenault
664e847916
llvm-reduce: Fix invalid reduction on tokens in operands-to-args (#133855) 2025-04-01 22:14:47 +07:00
Matt Arsenault
290d7b82cb
llvm-reduce: Prune some unneeded includes and forward declares (#133883) 2025-04-01 18:23:27 +07:00
Matt Arsenault
14c5098640
llvm-reduce: Use takeName when moving arguments in operands-to-args (#133851) 2025-04-01 14:48:14 +07:00
Matt Arsenault
f77f2b9c56
llvm-reduce: Try to preserve instruction metadata as argument attributes (#133557)
Fixes #131825
2025-04-01 07:34:31 +07:00
Matt Arsenault
f82283a84e
llvm-reduce: Use 80 dashes for section separator in status printing (#133686) 2025-03-31 18:06:37 +07:00
Matt Arsenault
057b3c2452 llvm-reduce: Trim unnecessary includes 2025-03-30 14:59:43 +07:00
Matt Arsenault
a03367fd01 llvm-reduce: Remove trailing whitespace 2025-03-30 12:44:14 +07:00
YLChenZ
fea6b38805
[llvm-reduce]: print short form, actionable names in the log (#133561)
Closes #132696

before the patch like this:
```
----------------------------
*** Reducing GlobalObjects...
----------------------------
*** Reducing GV Initializers...
----------------------------
*** Reducing GlobalVariables...
----------------------------
```
after the patch like this:
```
----------------------------
*** Reducing GlobalObjects (global-objects)...
----------------------------
*** Reducing GV Initializers (global-initializers)...
----------------------------
*** Reducing GlobalVariables (global-variables)...
----------------------------
```
2025-03-30 12:37:48 +07:00
Shilei Tian
847cdd46e5 [NFC][llvm-reduce] Fix an used variable warning in ReduceOperandsToArgs.cpp 2025-03-29 11:39:05 -04:00
Tim Gymnich
0bed72160c
Revert "[NFC] LLVM reduce: remove unused variable" (#133586)
Reverts llvm/llvm-project#133584
2025-03-29 14:59:56 +01:00
Tim Gymnich
9451617d56
[NFC] LLVM reduce: fix unused variable (#133584) 2025-03-29 14:50:55 +01:00
Matt Arsenault
d852cc5311
llvm-reduce: Fix losing call metadata in operands-to-args (#133422) 2025-03-29 16:20:49 +07:00
Matt Arsenault
d3d4a242de
llvm-reduce: Fix losing fast math flags in operands-to-args (#133421) 2025-03-29 16:17:43 +07:00
Matt Arsenault
5b5f40283d
llvm-reduce: Fix losing callsite attributes in operand-to-args (#133420) 2025-03-29 16:14:46 +07:00