Filter out illegal formulae after updating offsets, not before, so that
authorDan Gohman <gohman@apple.com>
Fri, 8 Oct 2010 19:33:26 +0000 (19:33 +0000)
committerDan Gohman <gohman@apple.com>
Fri, 8 Oct 2010 19:33:26 +0000 (19:33 +0000)
formulae which become illegal as a result of the offset updating don't
escape.

This is for rdar://8529692. No testcase yet, because the given cases
hit use-list ordering differences.

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

lib/Transforms/Scalar/LoopStrengthReduce.cpp

index 337adf06d7348549de1f9367dc05dcb6de85f496..5b608a0dcd556ef17e1ce3d586cd200f62c61d41 100644 (file)
@@ -2992,24 +2992,6 @@ void LSRInstance::NarrowSearchSpaceByCollapsingUnrolledCode() {
 
               LUThatHas->AllFixupsOutsideLoop &= LU.AllFixupsOutsideLoop;
 
-              // Delete formulae from the new use which are no longer legal.
-              bool Any = false;
-              for (size_t i = 0, e = LUThatHas->Formulae.size(); i != e; ++i) {
-                Formula &F = LUThatHas->Formulae[i];
-                if (!isLegalUse(F.AM,
-                                LUThatHas->MinOffset, LUThatHas->MaxOffset,
-                                LUThatHas->Kind, LUThatHas->AccessTy, TLI)) {
-                  DEBUG(dbgs() << "  Deleting "; F.print(dbgs());
-                        dbgs() << '\n');
-                  LUThatHas->DeleteFormula(F);
-                  --i;
-                  --e;
-                  Any = true;
-                }
-              }
-              if (Any)
-                LUThatHas->RecomputeRegs(LUThatHas - &Uses.front(), RegUses);
-
               // Update the relocs to reference the new use.
               for (SmallVectorImpl<LSRFixup>::iterator I = Fixups.begin(),
                    E = Fixups.end(); I != E; ++I) {
@@ -3032,6 +3014,24 @@ void LSRInstance::NarrowSearchSpaceByCollapsingUnrolledCode() {
                   Fixup.LUIdx = LUIdx;
               }
 
+              // Delete formulae from the new use which are no longer legal.
+              bool Any = false;
+              for (size_t i = 0, e = LUThatHas->Formulae.size(); i != e; ++i) {
+                Formula &F = LUThatHas->Formulae[i];
+                if (!isLegalUse(F.AM,
+                                LUThatHas->MinOffset, LUThatHas->MaxOffset,
+                                LUThatHas->Kind, LUThatHas->AccessTy, TLI)) {
+                  DEBUG(dbgs() << "  Deleting "; F.print(dbgs());
+                        dbgs() << '\n');
+                  LUThatHas->DeleteFormula(F);
+                  --i;
+                  --e;
+                  Any = true;
+                }
+              }
+              if (Any)
+                LUThatHas->RecomputeRegs(LUThatHas - &Uses.front(), RegUses);
+
               // Delete the old use.
               DeleteUse(LU, LUIdx);
               --LUIdx;