diff --git a/lib/Infer/Pruning.cpp b/lib/Infer/Pruning.cpp index f297de788..aa20abe13 100644 --- a/lib/Infer/Pruning.cpp +++ b/lib/Infer/Pruning.cpp @@ -47,6 +47,10 @@ namespace { static llvm::cl::opt EnableBB("souper-dataflow-pruning-bb", llvm::cl::desc("Prune with bivalent-bits analysis (default=true)"), llvm::cl::init(true)); + + static llvm::cl::opt InputThreshold("souper-dataflow-pruning-threshold", + llvm::cl::desc("Threshold for how many inputs pruning should try (default=10)"), + llvm::cl::init(10)); } namespace souper { @@ -237,14 +241,13 @@ bool PruningManager::isInfeasible(souper::Inst *RHS, bool FoundNonTopAnalysisResult = false; ForcedValueAnalysis FVA(RHS); for (int I = 0; I < InputVals.size(); ++I) { - if (I > 9 && !FoundNonTopAnalysisResult) { + if (I >= InputThreshold && !FoundNonTopAnalysisResult) { break; // Give up if first 10 known bits and constant range results // are all TOP. // TODO: Maybe figure out a better way to determine if an RHS // is not amenable to dataflow analysis. (example : x + HOLE) - // TODO: Maybe tune this threshold, or make it user controllable - // N = 10 results in a 2x performance boost for a 5% increase in + // Threshold = 10 results in a 2x performance boost for a 5% increase in // the final number of guesses. // Might make sense to make this threshold depend on the RHS } @@ -757,7 +760,7 @@ std::vector PruningManager::generateInputSets( std::vector InputSets; ValueCache Cache; - + // input tests 0,1,-1,smin,smax are added here constexpr unsigned PermutedLimit = 15; std::string specialInputs = "abcde"; std::unordered_set Visited; @@ -778,45 +781,10 @@ std::vector PruningManager::generateInputSets( } } while (std::next_permutation(specialInputs.begin(), specialInputs.end())); - - for (auto &&I : Inputs) { - if (I->K == souper::Inst::Var) - Cache[I] = {llvm::APInt(I->Width, 0)}; - } - if (isInputValid(Cache)) - InputSets.push_back(Cache); - - for (auto &&I : Inputs) { - if (I->K == souper::Inst::Var) - Cache[I] = {llvm::APInt(I->Width, 1)}; - } - if (isInputValid(Cache)) - InputSets.push_back(Cache); - - for (auto &&I : Inputs) { - if (I->K == souper::Inst::Var) - Cache[I] = {llvm::APInt(I->Width, -1)}; - } - if (isInputValid(Cache)) - InputSets.push_back(Cache); - - for (auto &&I : Inputs) { - if (I->K == souper::Inst::Var) - Cache[I] = {llvm::APInt::getSignedMaxValue(I->Width)}; - } - if (isInputValid(Cache)) - InputSets.push_back(Cache); - - for (auto &&I : Inputs) { - if (I->K == souper::Inst::Var) - Cache[I] = {llvm::APInt::getSignedMinValue(I->Width)}; - } - if (isInputValid(Cache)) - InputSets.push_back(Cache); - + // generate random inputs constexpr int MaxTries = 100; constexpr int NumLargeInputs = 5; - std::srand(0); + std::srand(0);//std::srand(0) is intentional. We want a diverse set of deterministic inputs, and not random ones. int i, m; for (i = 0, m = 0; i < NumLargeInputs && m < MaxTries; ++m ) { for (auto &&I : Inputs) {