[PATCH] D86849: [llvm-reduce] Create returns with undef values for non-void functions.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 30 12:12:47 PDT 2020


fhahn updated this revision to Diff 288865.
fhahn added a comment.

Update test to use FileCheck for interestingness. Diff should now make the change clear, no switch required.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86849/new/

https://reviews.llvm.org/D86849

Files:
  llvm/test/Reduce/remove-bbs-ret-nonvoid.ll
  llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp


Index: llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
===================================================================
--- llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
+++ llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
@@ -45,7 +45,10 @@
   Term->eraseFromParent();
 
   if (ChunkSucessors.empty()) {
-    ReturnInst::Create(BB.getContext(), nullptr, &BB);
+    auto *FnRetTy = BB.getParent()->getReturnType();
+    ReturnInst::Create(BB.getContext(),
+                       FnRetTy->isVoidTy() ? nullptr : UndefValue::get(FnRetTy),
+                       &BB);
     return;
   }
 
@@ -66,7 +69,10 @@
 static void removeUninterestingBBsFromSwitch(SwitchInst &SwInst,
                                              std::set<BasicBlock *> BBsToKeep) {
   if (!BBsToKeep.count(SwInst.getDefaultDest())) {
-    ReturnInst::Create(SwInst.getContext(), nullptr, SwInst.getParent());
+    auto *FnRetTy = SwInst.getParent()->getParent()->getReturnType();
+    ReturnInst::Create(SwInst.getContext(),
+                       FnRetTy->isVoidTy() ? nullptr : UndefValue::get(FnRetTy),
+                       SwInst.getParent());
     SwInst.eraseFromParent();
   } else
     for (int I = 0, E = SwInst.getNumCases(); I != E; ++I) {
Index: llvm/test/Reduce/remove-bbs-ret-nonvoid.ll
===================================================================
--- llvm/test/Reduce/remove-bbs-ret-nonvoid.ll
+++ llvm/test/Reduce/remove-bbs-ret-nonvoid.ll
@@ -13,10 +13,7 @@
 ; CHECK-NEXT:    br label %interesting2
 
 ; CHECK-LABEL: interesting2:
-; CHECK-NEXT:    br label %uninteresting1
-
-; CHECK-LABEL: uninteresting1:
-; CHECK-NEXT:    ret i32 10
+; CHECK-NEXT:    ret i32 undef
 
 interesting:
   br label %interesting2


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86849.288865.patch
Type: text/x-patch
Size: 1728 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200830/805fb20e/attachment.bin>


More information about the llvm-commits mailing list