[llvm-reduce] Reduce metadata references.
authorMichael Kruse <llvm-project@meinersbur.de>
Wed, 29 Sep 2021 15:51:13 +0000 (10:51 -0500)
committerMichael Kruse <llvm-project@meinersbur.de>
Wed, 29 Sep 2021 16:25:35 +0000 (11:25 -0500)
commitd9562a8e4528411aa22bd960a6487c0e2708dd4e
treec63c6fc627071436a6f2b6c9c2fd77b417ee5024
parent26db178cc2b39167a2fd69acfc8ba7ea564f3746
[llvm-reduce] Reduce metadata references.

The ReduceMetadata pass before this patch removed metadata on a per-MDNode (or NamedMDNode) basis. Either all references to an MDNode are kept, or all of them are removed. However, MDNodes are uniqued, meaning that references to MDNodes with the same data become references to the same MDNodes. As a consequence, e.g. tbaa references to the same type will all have the same MDNode reference and hence make it impossible to reduce only keeping metadata on those memory access for which they are interesting.
Moreover, MDNodes can also be referenced by some intrinsics or other MDNodes. These references were not considered for removal leading to the possibility that MDNodes are not actually removed even if selected to be removed by the oracle.

This patch changes ReduceMetadata to reduces based on removable metadata references instead. MDNodes without references implicitly dropped anyway. References by intrinsic calls should be removed by ReduceOperands or ReduceInstructions. References in other MDNodes cannot be removed as it would violate the immutability of MDNodes.

Additionally, ReduceMetadata pass before this patch used `setMetadata(I, NULL)` to remove references, where `I` is the index in the array returned by `getAllMetadata`. However, `setMetadata` expects a MDKind (such as `MD_tbaa`) as first argument. `getAllMetadata` does not return those in consecutive order (otherwise it would not need to be a `std::pair` with `first` representing the MDKind).

Reviewed By: aeubanks, swamulism

Differential Revision: https://reviews.llvm.org/D110534
llvm/test/tools/llvm-reduce/remove-metadata-args.ll [new file with mode: 0644]
llvm/tools/llvm-reduce/deltas/ReduceMetadata.cpp