mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2026-04-21 08:17:40 +00:00
Teach jump threading to "look through" a select when the branch direction of a terminator depends on it.
When it sees a promising select it now tries to figure out whether the condition of the select is known in any of the predecessors and if so it maps the operands appropriately. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121859 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -538,6 +538,40 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB, PredValueInfo &Result,
|
||||
}
|
||||
}
|
||||
|
||||
if (SelectInst *SI = dyn_cast<SelectInst>(I)) {
|
||||
// Handle select instructions where at least one operand is a known constant
|
||||
// and we can figure out the condition value for any predecessor block.
|
||||
Constant *TrueVal = getKnownConstant(SI->getTrueValue(), Preference);
|
||||
Constant *FalseVal = getKnownConstant(SI->getFalseValue(), Preference);
|
||||
PredValueInfoTy Conds;
|
||||
if ((TrueVal || FalseVal) &&
|
||||
ComputeValueKnownInPredecessors(SI->getCondition(), BB, Conds,
|
||||
WantInteger)) {
|
||||
for (unsigned i = 0, e = Conds.size(); i != e; ++i) {
|
||||
Constant *Cond = Conds[i].first;
|
||||
|
||||
// Figure out what value to use for the condition.
|
||||
bool KnownCond;
|
||||
if (ConstantInt *CI = dyn_cast<ConstantInt>(Cond)) {
|
||||
// A known boolean.
|
||||
KnownCond = CI->isOne();
|
||||
} else {
|
||||
assert(isa<UndefValue>(Cond) && "Unexpected condition value");
|
||||
// Either operand will do, so be sure to pick the one that's a known
|
||||
// constant.
|
||||
// FIXME: Do this more cleverly if both values are known constants?
|
||||
KnownCond = (TrueVal != 0);
|
||||
}
|
||||
|
||||
// See if the select has a known constant value for this predecessor.
|
||||
if (Constant *Val = KnownCond ? TrueVal : FalseVal)
|
||||
Result.push_back(std::make_pair(Val, Conds[i].second));
|
||||
}
|
||||
|
||||
return !Result.empty();
|
||||
}
|
||||
}
|
||||
|
||||
// If all else fails, see if LVI can figure out a constant value for us.
|
||||
Constant *CI = LVI->getConstant(V, BB);
|
||||
if (Constant *KC = getKnownConstant(CI, Preference)) {
|
||||
|
||||
Reference in New Issue
Block a user