summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ScalarEvolution.cpp
diff options
context:
space:
mode:
authorSanjoy Das <sanjoy@playingwithpointers.com>2016-10-18 17:45:16 +0000
committerSanjoy Das <sanjoy@playingwithpointers.com>2016-10-18 17:45:16 +0000
commit507dd40a4abadbfdaa4f49a4823ddae6c7dfec4f (patch)
tree763b4571b06f252c6b763b98dfb98722aa13148f /llvm/lib/Analysis/ScalarEvolution.cpp
parent9cd877a25a5092b1553c693530f1ffc0c6edbdfe (diff)
downloadbcm5719-llvm-507dd40a4abadbfdaa4f49a4823ddae6c7dfec4f.tar.gz
bcm5719-llvm-507dd40a4abadbfdaa4f49a4823ddae6c7dfec4f.zip
[SCEV] Make CompareValueComplexity a little bit smarter
This helps canonicalization in some cases. Thanks to Pankaj Chawla for the investigation and the test case! llvm-svn: 284501
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r--llvm/lib/Analysis/ScalarEvolution.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index fd3cd17ec19..9fa0de1aff8 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -449,7 +449,10 @@ bool SCEVUnknown::isOffsetOf(Type *&CTy, Constant *&FieldNo) const {
//===----------------------------------------------------------------------===//
static int CompareValueComplexity(const LoopInfo *const LI, Value *LV,
- Value *RV) {
+ Value *RV, unsigned DepthLeft = 2) {
+ if (DepthLeft == 0)
+ return 0;
+
// Order pointer values after integer values. This helps SCEVExpander form
// GEPs.
bool LIsPointer = LV->getType()->isPointerTy(),
@@ -487,7 +490,14 @@ static int CompareValueComplexity(const LoopInfo *const LI, Value *LV,
// Compare the number of operands.
unsigned LNumOps = LInst->getNumOperands(),
RNumOps = RInst->getNumOperands();
- return (int)LNumOps - (int)RNumOps;
+ if (LNumOps != RNumOps || LNumOps != 1)
+ return (int)LNumOps - (int)RNumOps;
+
+ // We only bother "recursing" if we have one operand to look at (so we don't
+ // really recurse as much as we iterate). We can consider expanding this
+ // logic in the future.
+ return CompareValueComplexity(LI, LInst->getOperand(0),
+ RInst->getOperand(0), DepthLeft - 1);
}
return 0;
OpenPOWER on IntegriCloud