[llvm] a5bb247 - [llvm-reduce] Create returns with undef values for non-void functions.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 31 08:38:59 PDT 2020
Author: Florian Hahn
Date: 2020-08-31T16:33:46+01:00
New Revision: a5bb24758d02e1e42b72561d0ddbd682776d1a4d
URL: https://github.com/llvm/llvm-project/commit/a5bb24758d02e1e42b72561d0ddbd682776d1a4d
DIFF: https://github.com/llvm/llvm-project/commit/a5bb24758d02e1e42b72561d0ddbd682776d1a4d.diff
LOG: [llvm-reduce] Create returns with undef values for non-void functions.
Currently replaceBranchTerminator/removeUninterestingBBsFromSwitch
always creates `ret void` instructions if no successor is in the chunk.
This results in invalid IR for functions with non-void return types,
which makes those reductions unfeasible. Instead, create `ret ty undef`
for functions with non-void return types.
Reviewed By: lebedev.ri
Differential Revision: https://reviews.llvm.org/D86849
Added:
Modified:
llvm/test/Reduce/remove-bbs-ret-nonvoid.ll
llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
Removed:
################################################################################
diff --git a/llvm/test/Reduce/remove-bbs-ret-nonvoid.ll b/llvm/test/Reduce/remove-bbs-ret-nonvoid.ll
index 198da95ad901..8a87064315a9 100644
--- a/llvm/test/Reduce/remove-bbs-ret-nonvoid.ll
+++ b/llvm/test/Reduce/remove-bbs-ret-nonvoid.ll
@@ -13,10 +13,7 @@ define i32 @main(i1 %c) {
; 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
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
index 9dee738d4906..8c0832dd884a 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
@@ -45,7 +45,10 @@ static void replaceBranchTerminator(BasicBlock &BB,
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 replaceBranchTerminator(BasicBlock &BB,
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) {
More information about the llvm-commits
mailing list