aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-reduce
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2022-10-13 14:42:15 -0700
committerMatt Arsenault <arsenm2@gmail.com>2022-10-23 15:39:39 -0700
commit08d1c43c7023a2e955c43fbf4c3f1635f91521e0 (patch)
treed57ee0e54f786921796262f743c1cda2d0b365d3 /llvm/tools/llvm-reduce
parent3e6f7ab867ac8c36f0c8a91e7fa1608742702681 (diff)
downloadllvm-08d1c43c7023a2e955c43fbf4c3f1635f91521e0.zip
llvm-08d1c43c7023a2e955c43fbf4c3f1635f91521e0.tar.gz
llvm-08d1c43c7023a2e955c43fbf4c3f1635f91521e0.tar.bz2
llvm-reduce: Add conditional reduction passes
Copy this technique from bugpoint. Before trying to blindly delete blocks, try to fold branch conditions. This intuitively makes more sense for a faster reduction, since you can find dead paths in the function to prune out before trying to bisect blocks in source order. Seems to provide some speedup on my multi-hour reduction samples. This does have the potential to produce testcases with unreachable blocks. This is already a problem with the existing block reduction pass. I'm struggling dealing with invalid reductions in these cases, so in the future this should probably start deleting those. However, I do sometimes try to reduce failures in code that becomes unreachable, so I'm not totally sure what to do here.
Diffstat (limited to 'llvm/tools/llvm-reduce')
-rw-r--r--llvm/tools/llvm-reduce/DeltaManager.cpp2
-rw-r--r--llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.cpp36
-rw-r--r--llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.h2
3 files changed, 40 insertions, 0 deletions
diff --git a/llvm/tools/llvm-reduce/DeltaManager.cpp b/llvm/tools/llvm-reduce/DeltaManager.cpp
index 048a83c..ee29b44 100644
--- a/llvm/tools/llvm-reduce/DeltaManager.cpp
+++ b/llvm/tools/llvm-reduce/DeltaManager.cpp
@@ -74,6 +74,8 @@ static cl::list<std::string>
DELTA_PASS("function-bodies", reduceFunctionBodiesDeltaPass) \
DELTA_PASS("special-globals", reduceSpecialGlobalsDeltaPass) \
DELTA_PASS("aliases", reduceAliasesDeltaPass) \
+ DELTA_PASS("simplify-conditionals-true", reduceConditionalsTrueDeltaPass) \
+ DELTA_PASS("simplify-conditionals-false", reduceConditionalsFalseDeltaPass)\
DELTA_PASS("basic-blocks", reduceBasicBlocksDeltaPass) \
DELTA_PASS("global-values", reduceGlobalValuesDeltaPass) \
DELTA_PASS("global-objects", reduceGlobalObjectsDeltaPass) \
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.cpp b/llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.cpp
index a45d571..416b165 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.cpp
@@ -13,6 +13,8 @@
#include "ReduceUsingSimplifyCFG.h"
#include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Instructions.h"
#include "llvm/Transforms/Utils/Local.h"
using namespace llvm;
@@ -31,3 +33,37 @@ static void reduceUsingSimplifyCFG(Oracle &O, Module &Program) {
void llvm::reduceUsingSimplifyCFGDeltaPass(TestRunner &Test) {
runDeltaPass(Test, reduceUsingSimplifyCFG, "Reducing using SimplifyCFG");
}
+static void reduceConditionals(Oracle &O, Module &M, bool Direction) {
+ SmallVector<BasicBlock *, 16> ToSimplify;
+
+ for (auto &F : M) {
+ for (auto &BB : F) {
+ auto *BR = dyn_cast<BranchInst>(BB.getTerminator());
+ if (!BR || !BR->isConditional() || O.shouldKeep())
+ continue;
+
+ if (Direction)
+ BR->setCondition(ConstantInt::getTrue(BR->getContext()));
+ else
+ BR->setCondition(ConstantInt::getFalse(BR->getContext()));
+
+ ToSimplify.push_back(&BB);
+ }
+ }
+
+ TargetTransformInfo TTI(M.getDataLayout());
+ for (auto *BB : ToSimplify)
+ simplifyCFG(BB, TTI);
+}
+
+void llvm::reduceConditionalsTrueDeltaPass(TestRunner &Test) {
+ runDeltaPass(
+ Test, [](Oracle &O, Module &M) { reduceConditionals(O, M, true); },
+ "Reducing conditional branches to true");
+}
+
+void llvm::reduceConditionalsFalseDeltaPass(TestRunner &Test) {
+ runDeltaPass(
+ Test, [](Oracle &O, Module &M) { reduceConditionals(O, M, false); },
+ "Reducing conditional branches to false");
+}
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.h b/llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.h
index 56cd15a..01a1460 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.h
+++ b/llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.h
@@ -18,6 +18,8 @@
namespace llvm {
void reduceUsingSimplifyCFGDeltaPass(TestRunner &Test);
+void reduceConditionalsTrueDeltaPass(TestRunner &Test);
+void reduceConditionalsFalseDeltaPass(TestRunner &Test);
} // namespace llvm
#endif