Index: llvm/test/tools/llvm-reduce/simplify-cfg.ll =================================================================== --- /dev/null +++ llvm/test/tools/llvm-reduce/simplify-cfg.ll @@ -0,0 +1,32 @@ +; RUN: llvm-reduce --delta-passes=simplify-cfg --test %python --test-arg %p/Inputs/remove-bbs.py -abort-on-invalid-reduction %s -o %t + +; RUN: FileCheck --check-prefix=CHECK-FINAL %s --input-file=%t +; CHECK-FINAL-NOT: x6 +; CHECK-FINAL-NOT: x10 + +define void @f1(ptr %interesting3, i32 %interesting2) { + %x3 = alloca ptr, i32 0, align 8 + store ptr %interesting3, ptr %interesting3, align 8 + switch i32 %interesting2, label %interesting1 [ + i32 0, label %x6 + i32 1, label %x11 + ] + +x4: + %x5 = call ptr @f2() + br label %x10 + +x10: + br label %interesting1 + +x6: + br label %x11 + +x11: + br label %interesting1 + +interesting1: + ret void +} + +declare ptr @f2() Index: llvm/tools/llvm-reduce/CMakeLists.txt =================================================================== --- llvm/tools/llvm-reduce/CMakeLists.txt +++ llvm/tools/llvm-reduce/CMakeLists.txt @@ -49,6 +49,7 @@ deltas/ReduceRegisterMasks.cpp deltas/ReduceRegisterDefs.cpp deltas/ReduceRegisterUses.cpp + deltas/ReduceUsingSimplifyCFG.cpp deltas/RunIRPasses.cpp deltas/SimplifyInstructions.cpp llvm-reduce.cpp Index: llvm/tools/llvm-reduce/DeltaManager.cpp =================================================================== --- llvm/tools/llvm-reduce/DeltaManager.cpp +++ llvm/tools/llvm-reduce/DeltaManager.cpp @@ -39,6 +39,7 @@ #include "deltas/ReduceRegisterMasks.h" #include "deltas/ReduceRegisterUses.h" #include "deltas/ReduceSpecialGlobals.h" +#include "deltas/ReduceUsingSimplifyCFG.h" #include "deltas/ReduceVirtualRegisters.h" #include "deltas/RunIRPasses.h" #include "deltas/SimplifyInstructions.h" @@ -75,6 +76,7 @@ DELTA_PASS("operands-to-args", reduceOperandsToArgsDeltaPass) \ DELTA_PASS("operands-skip", reduceOperandsSkipDeltaPass) \ DELTA_PASS("operand-bundles", reduceOperandBundesDeltaPass) \ + DELTA_PASS("simplify-cfg", reduceUsingSimplifyCFGDeltaPass) \ DELTA_PASS("attributes", reduceAttributesDeltaPass) \ DELTA_PASS("module-data", reduceModuleDataDeltaPass) \ } while (false) Index: llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.h =================================================================== --- /dev/null +++ llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.h @@ -0,0 +1,23 @@ +//===- ReduceUsingSimplifyCFG.h - Specialized Delta Pass ------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file implements a function which calls the Generic Delta pass in order +// to call SimplifyCFG on individual basic blocks. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_SIMPLIFYCFG_H +#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_SIMPLIFYCFG_H + +#include "Delta.h" + +namespace llvm { +void reduceUsingSimplifyCFGDeltaPass(TestRunner &Test); +} // namespace llvm + +#endif Index: llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.cpp =================================================================== --- /dev/null +++ llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.cpp @@ -0,0 +1,34 @@ +//===- ReduceUsingSimplifyCFG.h - Specialized Delta Pass ------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file implements a function which calls the Generic Delta pass in order +// to call SimplifyCFG on individual basic blocks. +// +//===----------------------------------------------------------------------===// + +#include "ReduceUsingSimplifyCFG.h" +#include "llvm/Analysis/TargetTransformInfo.h" +#include "llvm/Transforms/Utils/Local.h" + +using namespace llvm; + +static void reduceUsingSimplifyCFG(Oracle &O, Module &Program) { + SmallVector ToSimplify; + for (auto &F : Program) + for (auto &BB : F) + if (!O.shouldKeep()) + ToSimplify.push_back(&BB); + TargetTransformInfo TTI(Program.getDataLayout()); + for (auto *BB : ToSimplify) + simplifyCFG(BB, TTI); +} + +void llvm::reduceUsingSimplifyCFGDeltaPass(TestRunner &Test) { + outs() << "*** Reducing using SimplifyCFG...\n"; + runDeltaPass(Test, reduceUsingSimplifyCFG); +}