]> granicus.if.org Git - llvm/commit
[SCEV] Fix sorting order for AddRecExprs
authorMax Kazantsev <max.kazantsev@azul.com>
Tue, 16 May 2017 07:27:06 +0000 (07:27 +0000)
committerMax Kazantsev <max.kazantsev@azul.com>
Tue, 16 May 2017 07:27:06 +0000 (07:27 +0000)
commite413590ae24728862a4b277d67485bce7e190301
tree681f8852b1068dc607ddb90dc48a5bfaad07bca6
parent1f5970481f178136a704acbfbdb9d7b194665705
[SCEV] Fix sorting order for AddRecExprs

The existing sorting order in defined CompareSCEVComplexity sorts AddRecExprs
by loop depth, but does not pay attention to dominance of loops. This can
lead us to the following buggy situation:

for (...) { // loop1
  op1 = {A,+,B}
}
for (...) { // loop2
  op2 = {A,+,B}
  S = add op1, op2
}

In this case there is no guarantee that in operand list of S the op2 comes
before op1 (loop depth is the same, so they will be sorted just
lexicographically), so we can incorrectly treat S as a recurrence of loop1,
which is wrong.

This patch changes the sorting logic so that it places the dominated recs
before the dominating recs. This ensures that when we pick the first recurrency
in the operands order, it will be the bottom-most in terms of domination tree.
The attached test set includes some tests that produce incorrect SCEV
estimations and crashes with oldlogic.

Reviewers: sanjoy, reames, apilipenko, anna

Reviewed By: sanjoy

Subscribers: llvm-commits, mzolotukhin

Differential Revision: https://reviews.llvm.org/D33121

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303148 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Analysis/ScalarEvolution.cpp
test/Analysis/ScalarEvolution/different-loops-recs.ll [new file with mode: 0644]