Index: llvm/test/Reduce/no-replace-intrinsic-callee-with-undef.ll =================================================================== --- /dev/null +++ llvm/test/Reduce/no-replace-intrinsic-callee-with-undef.ll @@ -0,0 +1,24 @@ +; 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=CHECK-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=CHECK-ALL,CHECK-FINAL %s + +; STDERR-NOT: Function has metadata parameter but isn't an intrinsic + +declare i32 @llvm.amdgcn.reloc.constant(metadata) +declare void @uninteresting() + +define i32 @interesting() { +entry: + ; CHECK-INTERESTINGNESS-LABEL: define i32 @interesting( + ; CHECK-INTERESTINGNESS: 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 +} Index: llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp =================================================================== --- llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp +++ llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp @@ -30,7 +30,13 @@ // Record all out-of-chunk functions. std::vector> 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, and changing to an arbitrary call may radically + // change codegen. + 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 +59,12 @@ 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;