236 Commits

Author SHA1 Message Date
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
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
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
3140d51cf3
llvm-reduce: Remove unsupported from bitcode uselistorder test (#134185)
This was disabled due to flakiness but I'm currently unable to
reproduce.

I'm nervous the original issue still exists. However, I downgraded the
tripped
assert in 8c18c25b1b22ea710edb40a4f167a6a8bfe6ff9d to a warning since
the same
assert can trigger for illegitimate reasons.

Fixes #64157
2025-04-03 11:04:02 +07:00
Matt Arsenault
7559c64c5e
CloneModule: Map global initializers after mapping the function (#134082) 2025-04-03 07:17:12 +07:00
Matt Arsenault
54385f5ebe
llvm-reduce: Increase operands-to-args test coverage (#133853)
This wasn't checking the output for all functions.
--match-full-lines is also particularly hazardous for the
interestingness checks for avoiding asserts and broken IR.

Also add tests for some of the filtered function user types.
This wasn't covered, and is overly conservative.
2025-04-02 17:02:53 +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
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
ac55688482
llvm-reduce: Add test for token handling in operands-skip (#133857)
Seems to work correctly but wasn't tested.
2025-04-01 22:17:44 +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
Jeremy Morse
1ebc308bba
[DebugInfo][RemoveDIs] Remove debug-intrinsic printing cmdline options (#131855)
During the transition from debug intrinsics to debug records, we used
several different command line options to customise handling: the
printing of debug records to bitcode and textual could be independent of
how the debug-info was represented inside a module, whether the
autoupgrader ran could be customised. This was all valuable during
development, but now that totally removing debug intrinsics is coming
up, this patch removes those options in favour of a single flag
(experimental-debuginfo-iterators), which enables autoupgrade, in-memory
debug records, and debug record printing to bitcode and textual IR.

We need to do this ahead of removing the
experimental-debuginfo-iterators flag, to reduce the amount of
test-juggling that happens at that time.

There are quite a number of weird test behaviours related to this --
some of which I simply delete in this commit. Things like
print-non-instruction-debug-info.ll , the test suite now checks for
debug records in all tests, and we don't want to check we can print as
intrinsics. Or the update_test_checks tests -- these are duplicated with
write-experimental-debuginfo=false to ensure file writing for intrinsics
is correct, but that's something we're imminently going to delete.

A short survey of curious test changes:
* free-intrinsics.ll: we don't need to test that debug-info is a zero
cost intrinsic, because we won't be using intrinsics in the future.
* undef-dbg-val.ll: apparently we pinned this to non-RemoveDIs in-memory
mode while we sorted something out; it works now either way.
* salvage-cast-debug-info.ll: was testing intrinsics-in-memory get
salvaged, isn't necessary now
* localize-constexpr-debuginfo.ll: was producing "dead metadata"
intrinsics for optimised-out variable values, dbg-records takes the
(correct) representation of poison/undef as an operand. Looks like we
didn't update this in the past to avoid spurious test differences.
* Transforms/Scalarizer/dbginfo.ll: this test was explicitly testing
that debug-info affected codegen, and we deferred updating the tests
until now. This is just one of those silent gnochange issues that get
fixed by RemoveDIs.

Finally: I've added a bitcode test, dbg-intrinsics-autoupgrade.ll.bc,
that checks we can autoupgrade debug intrinsics that are in bitcode into
the new debug records.
2025-04-01 14:27:11 +01: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
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
Matt Arsenault
5b3e152e16
llvm-reduce: Make run-ir-passes error more consistent (#133564)
Avoid capitalized Error. This loses the "Error constructing pass pipeline"
part, and just forwards the error to the default report_fatal_error case. Not
sure if it's worth trying to keep.
2025-03-29 14:14:09 +07:00
Matt Arsenault
e87bec622c
llvm-reduce: Make some error messages more consistent (#133563)
The coding standards states that error messages should start with
a lowercase. Also use WithColor, and add missing test coverage for
the failed to write to output file case.
2025-03-29 14:10:58 +07:00
Matt Arsenault
724f2096ce
llvm-reduce: Add -abort-on-invalid-reduction to more tests (#133390)
If I flip the default, the only failures are in MIR tests.
2025-03-29 08:07:54 +07:00
Matt Arsenault
8c18c25b1b
llvm-reduce: Do not assert if the input is no longer interesting (#133386)
If the interestingness script is flaky, we should not assert. Print
a warning, and continue. This could still happen as a result of an
llvm-reduce bug, so make a note of that.

Add a --skip-verify-interesting-after-counting-chunks option to
avoid the extra run of the reduction script, and to silence the
warning.
2025-03-29 07:44:20 +07:00
Matt Arsenault
b2e2950358
llvm-reduce: Remove xfailed test for ifunc with constant expression (#133389)
The verifier does reject this now
2025-03-29 07:43:42 +07:00
Matt Arsenault
133c1afa8e
llvm-reduce: Filter function based on uses before removing arguments (#133412)
Invokes and others are not handled, so this was leaving broken callsites
behind for anything other than CallInst
2025-03-29 00:01:14 +07:00
Matt Arsenault
44e3735ac1
llvm-reduce: Preserve original callsite calling conv when removing arguments (#133411)
In undefined mismatch cases, this was fixing the callsite to use the calling
convention of the new function. Preserve the original wrong callsite's calling
convention.
2025-03-28 23:51:09 +07:00
Matt Arsenault
6b1acdb818
llvm-reduce: Fix losing operand bundles when removing arguments (#133410) 2025-03-28 23:41:47 +07:00
Matt Arsenault
115a77df9d
llvm-reduce: Fix losing metadata when removing arguments (#133409) 2025-03-28 23:28:03 +07:00
Matt Arsenault
688df34634
llvm-reduce: Fix losing fast math flags when removing arguments (#133408) 2025-03-28 23:24:49 +07:00
Matt Arsenault
1b86867ab3
llvm-reduce: Fix losing callsite attributes when removing arguments (#133407)
The attribute APIs make this cumbersome. There seem to be missing
overloads using AttrBuilder for the function attrs. Plus there doesn't
seem to be a direct way to set the function attrs on the call.
2025-03-28 23:20:56 +07:00
Matt Arsenault
a33d789bb7
llvm-reduce: Avoid invalid reductions on x86_intrcc (#133396)
If there are arguments, the first one must be byval.
2025-03-28 23:11:28 +07:00
Matt Arsenault
0ed8b27890
llvm-reduce: Avoid removing convergent with convergence tokens (#132946)
Check if the intrinsics are declared in the module as an overly
conservative fix.

Fixes #132695
2025-03-28 12:30:35 +07:00
Matt Arsenault
37b5f77f8b
llvm-reduce: Fix asserting on TargetExtTypes that do not support zeroinit (#132733)
So far I've been unsuccessful in finding an example where the used constant
value is directly observed in the output. This avoids an assert in an intermediate
step of value replacement.
2025-03-25 11:40:55 +07:00
Matt Arsenault
bfb549ff33
llvm-reduce: Fix operand reduction asserting on target ext types (#132732)
Not all TargetExtTypes support zeroinit, so use poison as a substitute
if unavailable.
2025-03-25 11:38:04 +07:00
Matt Arsenault
896df5c4bf
llvm-reduce: Fix assert if call type mismatches function type (#131981) 2025-03-22 04:19:25 +07:00
Matt Arsenault
d43b4ede66
llvm-reduce: Do not remove appending linkage from intrinsic globals (#131713) 2025-03-18 23:51:36 +07:00
Daniel Paoliello
16e051f0b9
[win] NFC: Rename EHCatchret to EHCont to allow for EH Continuation targets that aren't catchret instructions (#129953)
This change splits out the renaming and comment updates from #129612 as a non-functional change.
2025-03-06 09:28:44 -08:00
Robert Barinov
0988bf8d75
[LLVM-Reduce] - Null pointer handling during distinct metadata reduction (#117570)
Some distinct metadata nodes, e.g DICompileUnit, have implicit nullptrs
inside them. Iterating over them with dyn_cast leads to a crash, change
the behavior so that the nullptr operands are skipped.

Add the test distinct-metadata-nullptr.ll which will crash if null
pointers are not handled correctly.
2024-11-25 14:20:45 -08:00
Yingwei Zheng
3356eb3b15
[llvm-reduce] Reduce samesign flag from icmp (#115492) 2024-11-09 00:12:09 +08:00
Lee Wei
1469d82e1c
Remove br i1 undef from some regression tests [NFC] (#115130)
As defined in LangRef, branching on `undef` is undefined behavior.
This PR aims to remove undefined behavior from tests. As UB tests break
Alive2 and may be the root cause of breaking future optimizations.

Here's an Alive2 proof for one of the examples:
https://alive2.llvm.org/ce/z/TncxhP
2024-11-07 08:11:15 +00:00
Paul Walker
38fffa630e
[LLVM][IR] Use splat syntax when printing Constant[Data]Vector. (#112548) 2024-11-06 11:53:33 +00:00
Akshat Oke
dbfca24b99
[MIR] Serialize virtual register flags (#110228)
[MIR] Serialize virtual register flags

This introduces target-specific vreg flag serialization. Flags are represented as `uint8_t` and the `TargetRegisterInfo` override provides methods `getVRegFlagValue` to deserialize and `getVRegFlagsOfReg` to serialize.
2024-10-14 14:19:53 +05:30
Matt Arsenault
9839b8cfb4
llvm-reduce: Fix assert on invokes with catchswitch (#111838)
This is the minimal change to avoid the assert. There's an API flaw in
invoke instructions where getLandingPad assumes all invoke unwind
blocks have landingpads, when some have catchswitch instead.

Fixes #111817
2024-10-10 19:32:02 +04:00
Matt Arsenault
1731bb79a9
llvm-reduce: Fix not checking shouldKeep in special-globals reduction (#111647) 2024-10-09 19:13:06 +04:00
Stephen Tozer
d826b0c90f
[LLVM] Add HasFakeUses to MachineFunction (#110097)
Following the addition of the llvm.fake.use intrinsic and corresponding
MIR instruction, two further changes are planned: to add an
-fextend-lifetimes flag to Clang that emits these intrinsics, and to
have -Og enable this flag by default. Currently, some logic for handling
fake uses is gated by the optdebug attribute, which is intended to be
switched on by -fextend-lifetimes (and by extension -Og later on).
However, the decision was made that a general optdebug attribute should
be incompatible with other opt_ attributes (e.g. optsize, optnone),
since they all express different intents for how to optimize the
program. We would still like to allow -fextend-lifetimes with optsize
however (i.e. -Os -fextend-lifetimes should be legal), since it may be a
useful configuration and there is no technical reason to not allow it.

This patch resolves this by tracking MachineFunctions that have fake
uses, allowing us to run passes that interact with them and skip passes
that clash with them.
2024-10-04 13:13:30 +01:00
Dominik Montada
8ba334bc4a
[MIR] Allow overriding isSSA, noPhis, noVRegs in MIR input (#108546)
Allow setting the computed properties IsSSA, NoPHIs, NoVRegs for MIR
functions in MIR input. The default value is still the computed value.
If the property is set to false, the computed result is ignored. Conflicting
values (e.g. setting IsSSA where the input MIR is clearly not SSA) lead to
an error.

Closes #37787
2024-09-24 14:21:45 +02:00
Robert Barinov
42067f26cd
[LLVM-Reduce] - Distinct Metadata Reduction (#104624) 2024-08-20 14:34:41 +04:00