[PATCH] D88684: llvm-reduce: Don't replace intrinsic calls with undef

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 10:56:38 PDT 2020


arsenm created this revision.
arsenm added reviewers: lebedev.ri, fhahn, Tyker, diegotf.
Herald added a project: LLVM.
arsenm requested review of this revision.
Herald added a subscriber: wdng.

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.


https://reviews.llvm.org/D88684

Files:
  llvm/test/Reduce/no-replace-intrinsic-callee-with-undef.ll
  llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp


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,7 @@
   // 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) { 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.
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,26 @@
+; REQUIRES: amdgpu-registered-target
+
+; 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
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88684.295625.patch
Type: text/x-patch
Size: 1982 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201001/a1cdc4f6/attachment.bin>


More information about the llvm-commits mailing list