[llvm] r267626 - [LVI] Cut short search if we know we can't return a useful result
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 26 16:27:34 PDT 2016
Author: reames
Date: Tue Apr 26 18:27:33 2016
New Revision: 267626
URL: http://llvm.org/viewvc/llvm-project?rev=267626&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/Analysis/LazyValueInfo.cpp
Modified: llvm/trunk/lib/Analysis/LazyValueInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LazyValueInfo.cpp?rev=267626&r1=267625&r2=267626&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LazyValueInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/LazyValueInfo.cpp Tue Apr 26 18:27:33 2016
@@ -1009,6 +1009,24 @@ bool LazyValueInfoCache::solveBlockValue
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::solveBlockValue
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::solveBlockValue
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::solveBlockValue
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;
}
More information about the llvm-commits
mailing list