1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

[LVI] Cut short search if we know we can't return a useful result

Previously we were recursing on our operands for unary and binary operators regardless of whether we knew how to reason about the operator in question.  This has the effect of doing a potentially large amount of work, only to throw it away.  By checking whether the operation is one LVI can handle, we can cut short the search and return the (overdefined) answer more quickly.  The quality of the results produced should not change.

llvm-svn: 267626
This commit is contained in:
Philip Reames 2016-04-26 23:27:33 +00:00
parent 51a5a5649b
commit cb75ab3a5d

View File

@ -1009,6 +1009,24 @@ bool LazyValueInfoCache::solveBlockValueCast(LVILatticeVal &BBLV,
BBLV.markOverdefined();
return true;
}
// Filter out casts we don't know how to reason about before attempting to
// recurse on our operand. This can cut a long search short if we know we're
// not going to be able to get any useful information anways.
switch (BBI->getOpcode()) {
case Instruction::Trunc:
case Instruction::SExt:
case Instruction::ZExt:
case Instruction::BitCast:
break;
default:
// Unhandled instructions are overdefined.
DEBUG(dbgs() << " compute BB '" << BB->getName()
<< "' - overdefined (unknown cast).\n");
BBLV.markOverdefined();
return true;
}
// Figure out the range of the LHS. If that fails, we still apply the
// transfer rule on the full set since we may be able to locally infer
@ -1048,11 +1066,9 @@ bool LazyValueInfoCache::solveBlockValueCast(LVILatticeVal &BBLV,
case Instruction::BitCast:
Result.markConstantRange(LHSRange);
break;
// Unhandled instructions are overdefined.
default:
DEBUG(dbgs() << " compute BB '" << BB->getName()
<< "' - overdefined (unknown cast).\n");
Result.markOverdefined();
// Should be dead if the code above is correct
llvm_unreachable("inconsistent with above");
break;
}
@ -1066,6 +1082,28 @@ bool LazyValueInfoCache::solveBlockValueBinaryOp(LVILatticeVal &BBLV,
assert(BBI->getOperand(0)->getType()->isSized() &&
"all operands to binary operators are sized");
// Filter out operators we don't know how to reason about before attempting to
// recurse on our operand(s). This can cut a long search short if we know
// we're not going to be able to get any useful information anways.
switch (BBI->getOpcode()) {
case Instruction::Add:
case Instruction::Sub:
case Instruction::Mul:
case Instruction::UDiv:
case Instruction::Shl:
case Instruction::LShr:
case Instruction::And:
case Instruction::Or:
// continue into the code below
break;
default:
// Unhandled instructions are overdefined.
DEBUG(dbgs() << " compute BB '" << BB->getName()
<< "' - overdefined (unknown binary operator).\n");
BBLV.markOverdefined();
return true;
};
// Figure out the range of the LHS. If that fails, use a conservative range,
// but apply the transfer rule anyways. This lets us pick up facts from
@ -1117,12 +1155,9 @@ bool LazyValueInfoCache::solveBlockValueBinaryOp(LVILatticeVal &BBLV,
case Instruction::Or:
Result.markConstantRange(LHSRange.binaryOr(RHSRange));
break;
// Unhandled instructions are overdefined.
default:
DEBUG(dbgs() << " compute BB '" << BB->getName()
<< "' - overdefined (unknown binary operator).\n");
Result.markOverdefined();
// Should be dead if the code above is correct
llvm_unreachable("inconsistent with above");
break;
}