OSDN Git Service

[SCEV][NFC] Check NoWrap flags before lexicographical comparison of SCEVs
authorMax Kazantsev <max.kazantsev@azul.com>
Wed, 6 Dec 2017 12:44:56 +0000 (12:44 +0000)
committerMax Kazantsev <max.kazantsev@azul.com>
Wed, 6 Dec 2017 12:44:56 +0000 (12:44 +0000)
Lexicographical comparison of SCEV trees is potentially expensive for big
expression trees. We can define ordering between them for AddRecs and
N-ary operations by SCEV NoWrap flags to make non-equality check
cheaper.

This change does not prevent grouping eqivalent SCEVs together and is
not supposed to have any meaningful impact on behavior of any transforms.

Reviewed By: sanjoy
Differential Revision: https://reviews.llvm.org/D40645

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319889 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ScalarEvolution.cpp

index 48c08b3..9bc8f2d 100644 (file)
@@ -694,6 +694,10 @@ static int CompareSCEVComplexity(
     if (LNumOps != RNumOps)
       return (int)LNumOps - (int)RNumOps;
 
+    // Compare NoWrap flags.
+    if (LA->getNoWrapFlags() != RA->getNoWrapFlags())
+      return (int)LA->getNoWrapFlags() - (int)RA->getNoWrapFlags();
+
     // Lexicographically compare.
     for (unsigned i = 0; i != LNumOps; ++i) {
       int X = CompareSCEVComplexity(EqCacheSCEV, EqCacheValue, LI,
@@ -718,6 +722,10 @@ static int CompareSCEVComplexity(
     if (LNumOps != RNumOps)
       return (int)LNumOps - (int)RNumOps;
 
+    // Compare NoWrap flags.
+    if (LC->getNoWrapFlags() != RC->getNoWrapFlags())
+      return (int)LC->getNoWrapFlags() - (int)RC->getNoWrapFlags();
+
     for (unsigned i = 0; i != LNumOps; ++i) {
       int X = CompareSCEVComplexity(EqCacheSCEV, EqCacheValue, LI,
                                     LC->getOperand(i), RC->getOperand(i), DT,