Skip to content
This repository was archived by the owner on Oct 30, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 9 additions & 41 deletions lib/Infer/Pruning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ namespace {
static llvm::cl::opt<bool> EnableBB("souper-dataflow-pruning-bb",
llvm::cl::desc("Prune with bivalent-bits analysis (default=true)"),
llvm::cl::init(true));

static llvm::cl::opt<int> InputThreshold("souper-dataflow-pruning-threshold",
llvm::cl::desc("Threshold for how many inputs pruning should try (default=10)"),
llvm::cl::init(10));
}

namespace souper {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -757,7 +760,7 @@ std::vector<ValueCache> PruningManager::generateInputSets(
std::vector<ValueCache> InputSets;

ValueCache Cache;

// input tests 0,1,-1,smin,smax are added here
constexpr unsigned PermutedLimit = 15;
std::string specialInputs = "abcde";
std::unordered_set<std::string> Visited;
Expand All @@ -778,45 +781,10 @@ std::vector<ValueCache> 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) {
Expand Down