Skip to content

Increase number of icmps needed for converting to a switch statement #99269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 6 additions & 2 deletions llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ static cl::opt<unsigned> MaxSwitchCasesPerResult(
"max-switch-cases-per-result", cl::Hidden, cl::init(16),
cl::desc("Limit cases to analyze when converting a switch to select"));

static cl::opt<unsigned> MinICmpsToSwitch(
"min-icmps-to-switch", cl::Hidden, cl::init(9),
cl::desc("Minimum number of icmp sequences to convert to switch"));

STATISTIC(NumBitMaps, "Number of switch instructions turned into bitmaps");
STATISTIC(NumLinearMaps,
"Number of switch instructions turned into linear mapping");
Expand Down Expand Up @@ -4893,8 +4897,8 @@ bool SimplifyCFGOpt::SimplifyBranchOnICmpChain(BranchInst *BI,
if (!CompVal)
return false;

// Avoid turning single icmps into a switch.
if (UsedICmps <= 1)
// Avoid turning few icmps into a switch.
if (UsedICmps < MinICmpsToSwitch)
return false;

bool TrueWhenEqual = match(Cond, m_LogicalOr(m_Value(), m_Value()));
Expand Down
Loading