[llvm] ee6e25e - llvm-reduce: Don't replace intrinsic calls with undef
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 16 07:11:27 PDT 2020
Author: Matt Arsenault
Date: 2020-10-16T10:10:53-04:00
New Revision: ee6e25e4391a6d3ac0a3c89615474e512f44cda6
URL: https://github.com/llvm/llvm-project/commit/ee6e25e4391a6d3ac0a3c89615474e512f44cda6
DIFF: https://github.com/llvm/llvm-project/commit/ee6e25e4391a6d3ac0a3c89615474e512f44cda6.diff
LOG: llvm-reduce: Don't replace intrinsic calls with undef
These don't really have function bodies to try to eliminate. This also
has a good chance of just producing invalid IR since intrinsics can
have special operand constraints (e.g. metadata arguments aren't valid
for an arbitrary call). This was wasting quite a bit of time producing
and failing on invalid IR when replacing dbg.values with undefs.
Added:
llvm/test/Reduce/no-replace-intrinsic-callee-with-undef.ll
Modified:
llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp
Removed:
################################################################################
diff --git a/llvm/test/Reduce/no-replace-intrinsic-callee-with-undef.ll b/llvm/test/Reduce/no-replace-intrinsic-callee-with-undef.ll
new file mode 100644
index 000000000000..7792fa782095
--- /dev/null
+++ b/llvm/test/Reduce/no-replace-intrinsic-callee-with-undef.ll
@@ -0,0 +1,30 @@
+; It's invalid to have a non-intrinsic call with a metadata argument,
+; so it's unproductive to replace the users of the intrinsic
+; declaration with undef.
+
+; RUN: llvm-reduce --test FileCheck --test-arg --check-prefixes=ALL,CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t 2> %t.log
+; RUN: FileCheck -check-prefix=STDERR %s < %t.log
+; RUN: cat %t | FileCheck -implicit-check-not=uninteresting --check-prefixes=ALL,CHECK-FINAL %s
+
+; Check that the call is removed by instruction reduction passes
+; RUN: llvm-reduce --test FileCheck --test-arg --check-prefixes=ALL,CHECK-FUNC --test-arg %s --test-arg --input-file %s -o %t
+; RUN: cat %t | FileCheck -implicit-check-not=uninteresting --check-prefixes=ALL,CHECK-NOCALL %s
+
+
+; STDERR-NOT: Function has metadata parameter but isn't an intrinsic
+
+declare i32 @llvm.amdgcn.reloc.constant(metadata)
+declare void @uninteresting()
+
+; ALL-LABEL: define i32 @interesting(
+define i32 @interesting() {
+entry:
+ ; CHECK-INTERESTINGNESS: call
+ ; CHECK-NOCALL-NOT: call
+
+ ; CHECK-FINAL: %call = call i32 @llvm.amdgcn.reloc.constant(metadata !"arst")
+ ; CHECK-FINAL-NEXT: ret i32 %call
+ %call = call i32 @llvm.amdgcn.reloc.constant(metadata !"arst")
+ call void @uninteresting()
+ ret i32 %call
+}
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp b/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp
index 223d6adbd140..6bb8f81c3dbd 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp
@@ -30,7 +30,12 @@ static void extractFunctionsFromModule(const std::vector<Chunk> &ChunksToKeep,
// Record all out-of-chunk functions.
std::vector<std::reference_wrapper<Function>> FuncsToRemove;
copy_if(Program->functions(), std::back_inserter(FuncsToRemove),
- [&O](auto &unused) { return !O.shouldKeep(); });
+ [&O](Function &F) {
+ // Intrinsics don't have function bodies that are useful to
+ // reduce. Additionally, intrinsics may have additional operand
+ // constraints.
+ return !F.isIntrinsic() && !O.shouldKeep();
+ });
// Then, drop body of each of them. We want to batch this and do nothing else
// here so that minimal number of remaining exteranal uses will remain.
@@ -53,8 +58,12 @@ static int countFunctions(Module *Program) {
errs() << "----------------------------\n";
errs() << "Function Index Reference:\n";
int FunctionCount = 0;
- for (auto &F : *Program)
- errs() << "\t" << ++FunctionCount << ": " << F.getName() << "\n";
+ for (auto &F : *Program) {
+ if (F.isIntrinsic())
+ continue;
+
+ errs() << '\t' << ++FunctionCount << ": " << F.getName() << '\n';
+ }
errs() << "----------------------------\n";
return FunctionCount;
More information about the llvm-commits
mailing list