[llvm] r318237 - [LoopRotate] processLoop should return true even if it just simplified the loop latch without making any other changes
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 14 16:22:42 PST 2017
Author: ctopper
Date: Tue Nov 14 16:22:42 2017
New Revision: 318237
URL: http://llvm.org/viewvc/llvm-project?rev=318237&view=rev
Log:
[LoopRotate] processLoop should return true even if it just simplified the loop latch without making any other changes
Simplifying a loop latch changes the IR and we need to make sure the pass manager knows to invalidate analysis passes if that happened.
PR35210 discovered a case where we failed to invalidate the post dominator tree after this simplification because we no changes other than simplifying the loop latch.
Fixes PR35210.
Differential Revision: https://reviews.llvm.org/D40035
Added:
llvm/trunk/test/Transforms/LoopRotate/pr35210.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp?rev=318237&r1=318236&r2=318237&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp Tue Nov 14 16:22:42 2017
@@ -634,7 +634,7 @@ bool LoopRotate::processLoop(Loop *L) {
if ((MadeChange || SimplifiedLatch) && LoopMD)
L->setLoopID(LoopMD);
- return MadeChange;
+ return MadeChange || SimplifiedLatch;
}
LoopRotatePass::LoopRotatePass(bool EnableHeaderDuplication)
Added: llvm/trunk/test/Transforms/LoopRotate/pr35210.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopRotate/pr35210.ll?rev=318237&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/LoopRotate/pr35210.ll (added)
+++ llvm/trunk/test/Transforms/LoopRotate/pr35210.ll Tue Nov 14 16:22:42 2017
@@ -0,0 +1,70 @@
+;RUN: opt %s -passes='adce,loop(rotate),adce' -S -debug-pass-manager -debug-only=loop-rotate 2>&1 | FileCheck %s
+
+; This test is to make sure we invalidate the post dominator pass after loop rotate simplifies the loop latch.
+; The adce passes are here to make sure post dominator analysis is required.
+
+; CHECK: Starting llvm::Function pass manager run.
+; CHECK-NEXT: Running pass: ADCEPass on f
+; CHECK-NEXT: Running analysis: DominatorTreeAnalysis on f
+; CHECK-NEXT: Running analysis: PostDominatorTreeAnalysis on f
+; CHECK-NEXT: Running pass: FunctionToLoopPassAdaptor{{.*}} on f
+; CHECK-NEXT: Running analysis: LoopAnalysis on f
+; CHECK-NEXT: Running analysis: AssumptionAnalysis on f
+; CHECK-NEXT: Running analysis: AAManager on f
+; CHECK-NEXT: Running analysis: TargetLibraryAnalysis on f
+; CHECK-NEXT: Running analysis: ScalarEvolutionAnalysis on f
+; CHECK-NEXT: Running analysis: TargetIRAnalysis on f
+; CHECK-NEXT: Running analysis: InnerAnalysisManagerProxy{{.*}} on f
+; CHECK-NEXT: Starting Loop pass manager run.
+; CHECK-NEXT: Running pass: LoopRotatePass on Loop at depth 1 containing: %bb<header><exiting>,%bb4<latch>
+; CHECK-NEXT: Folding loop latch bb4 into bb
+; CHECK-NEXT: Invalidating all non-preserved analyses for: bb
+; CHECK-NEXT: Finished Loop pass manager run.
+; CHECK-NEXT: Invalidating all non-preserved analyses for: f
+; CHECK-NEXT: Invalidating analysis: PostDominatorTreeAnalysis on f
+; CHECK-NEXT: Running pass: ADCEPass on f
+; CHECK-NEXT: Running analysis: PostDominatorTreeAnalysis on f
+; CHECK-NEXT: Finished llvm::Function pass manager run.
+
+; CHECK-LABEL: define i8 @f() {
+; CHECK-NEXT : entry:
+; CHECK-NEXT : br label %bb
+; CHECK-NEXT :
+; CHECK-NEXT : bb: ; preds = %bb, %entry
+; CHECK-NEXT : %mode.0 = phi i8 [ 0, %entry ], [ %indvar.next, %bb ]
+; CHECK-NEXT : %tmp5 = icmp eq i8 %mode.0, 1
+; CHECK-NEXT : %indvar.next = add i8 %mode.0, 1
+; CHECK-NEXT : br i1 %tmp5, label %bb5, label %bb
+; CHECK-NEXT :
+; CHECK-NEXT : bb5: ; preds = %bb
+; CHECK-NEXT : tail call void @raise_exception() #0
+; CHECK-NEXT : unreachable
+; CHECK-NEXT : }
+; CHECK-NEXT :
+; CHECK-NEXT : ; Function Attrs: noreturn
+; CHECK-NEXT : declare void @raise_exception() #0
+; CHECK-NEXT :
+; CHECK-NEXT : attributes #0 = { noreturn }
+
+define i8 @f() {
+entry:
+ br label %bb
+
+bb: ; preds = %bb4, %entry
+ %mode.0 = phi i8 [ 0, %entry ], [ %indvar.next, %bb4 ]
+ %tmp5 = icmp eq i8 %mode.0, 1
+ br i1 %tmp5, label %bb5, label %bb4
+
+bb4: ; preds = %bb2
+ %indvar.next = add i8 %mode.0, 1
+ br label %bb
+
+bb5: ; preds = %bb2
+ tail call void @raise_exception() #0
+ unreachable
+}
+
+; Function Attrs: noreturn
+declare void @raise_exception() #0
+
+attributes #0 = { noreturn }
More information about the llvm-commits
mailing list