[llvm] 2f1fa62 - this pass calls simplifyCFG on individual basic blocks; we want this
John Regehr via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 15 14:46:35 PDT 2022
Author: John Regehr
Date: 2022-08-15T15:45:20-06:00
New Revision: 2f1fa6242a1fff0743f74b67f9ea6c08259acfa1
URL: https://github.com/llvm/llvm-project/commit/2f1fa6242a1fff0743f74b67f9ea6c08259acfa1
DIFF: https://github.com/llvm/llvm-project/commit/2f1fa6242a1fff0743f74b67f9ea6c08259acfa1.diff
LOG: this pass calls simplifyCFG on individual basic blocks; we want this
so that we can reduce away incidental parts of the CFG in cases where
the full simplifyCFG pass makes the test case uninteresting
Differential Revision: https://reviews.llvm.org/D131920
Added:
llvm/test/tools/llvm-reduce/simplify-cfg.ll
llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.cpp
llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.h
Modified:
llvm/tools/llvm-reduce/CMakeLists.txt
llvm/tools/llvm-reduce/DeltaManager.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-reduce/simplify-cfg.ll b/llvm/test/tools/llvm-reduce/simplify-cfg.ll
new file mode 100644
index 0000000000000..71fa70921cd43
--- /dev/null
+++ b/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()
diff --git a/llvm/tools/llvm-reduce/CMakeLists.txt b/llvm/tools/llvm-reduce/CMakeLists.txt
index 969da364bfa43..a782d39c495b7 100644
--- a/llvm/tools/llvm-reduce/CMakeLists.txt
+++ b/llvm/tools/llvm-reduce/CMakeLists.txt
@@ -49,6 +49,7 @@ add_llvm_tool(llvm-reduce
deltas/ReduceRegisterMasks.cpp
deltas/ReduceRegisterDefs.cpp
deltas/ReduceRegisterUses.cpp
+ deltas/ReduceUsingSimplifyCFG.cpp
deltas/RunIRPasses.cpp
deltas/SimplifyInstructions.cpp
llvm-reduce.cpp
diff --git a/llvm/tools/llvm-reduce/DeltaManager.cpp b/llvm/tools/llvm-reduce/DeltaManager.cpp
index 5fa0376545487..89fd33b24be12 100644
--- a/llvm/tools/llvm-reduce/DeltaManager.cpp
+++ b/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 @@ static cl::opt<std::string>
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)
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.cpp b/llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.cpp
new file mode 100644
index 0000000000000..504f4c218e1fd
--- /dev/null
+++ b/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<BasicBlock *, 16> 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);
+}
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.h b/llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.h
new file mode 100644
index 0000000000000..0105ad2b29744
--- /dev/null
+++ b/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
More information about the llvm-commits
mailing list