OSDN Git Service

[PATCH] Force LoopReroll to reset the loop trip count value after reroll.
authorZinovy Nis <zinovy.nis@gmail.com>
Tue, 22 Mar 2016 13:50:57 +0000 (13:50 +0000)
committerZinovy Nis <zinovy.nis@gmail.com>
Tue, 22 Mar 2016 13:50:57 +0000 (13:50 +0000)
It's a bug fix.
For rerolled loops SE trip count remains unchanged. It leads to incorrect work of the next passes.
My patch just resets SE info for rerolled loop forcing SE to re-evaluate it next time it requested.
I also added a verifier call in the exisitng test to be sure no invalid SE data remain. Without my fix this test would fail with -verify-scev.

Differential Revision: http://reviews.llvm.org/D18316

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

lib/Transforms/Scalar/LoopRerollPass.cpp
test/Transforms/LoopReroll/basic32iters.ll

index fae80d9..3fb0a10 100644 (file)
@@ -1551,14 +1551,12 @@ bool LoopReroll::runOnLoop(Loop *L, LPPassManager &LPM) {
         "] Loop %" << Header->getName() << " (" <<
         L->getNumBlocks() << " block(s))\n");
 
-  bool Changed = false;
-
   // For now, we'll handle only single BB loops.
   if (L->getNumBlocks() > 1)
-    return Changed;
+    return false;
 
   if (!SE->hasLoopInvariantBackedgeTakenCount(L))
-    return Changed;
+    return false;
 
   const SCEV *LIBETC = SE->getBackedgeTakenCount(L);
   const SCEV *IterCount = SE->getAddExpr(LIBETC, SE->getOne(LIBETC->getType()));
@@ -1572,11 +1570,12 @@ bool LoopReroll::runOnLoop(Loop *L, LPPassManager &LPM) {
 
   if (PossibleIVs.empty()) {
     DEBUG(dbgs() << "LRR: No possible IVs found\n");
-    return Changed;
+    return false;
   }
 
   ReductionTracker Reductions;
   collectPossibleReductions(L, Reductions);
+  bool Changed = false;
 
   // For each possible IV, collect the associated possible set of 'root' nodes
   // (i+1, i+2, etc.).
@@ -1587,5 +1586,9 @@ bool LoopReroll::runOnLoop(Loop *L, LPPassManager &LPM) {
       break;
     }
 
+  // Trip count of L has changed so SE must be re-evaluated.
+  if (Changed)
+    SE->forgetLoop(L);
+
   return Changed;
 }
index d39b0e6..758fd8a 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: opt < %s -loop-reroll -S | FileCheck %s
+; RUN: opt < %s -loop-reroll -verify-scev -S | FileCheck %s
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"