1; RUN: opt < %s -enable-loop-distribute -passes='loop-distribute,loop-mssa(simple-loop-unswitch<nontrivial>),loop-distribute' -o /dev/null -S -verify-analysis-invalidation=0 -debug-pass-manager=verbose 2>&1 | FileCheck %s 2 3 4; Running loop-distribute will result in LoopAccessAnalysis being required and 5; cached in the LoopAnalysisManagerFunctionProxy. 6; 7; CHECK: Running analysis: LoopAccessAnalysis on test6 8 9 10; Then simple-loop-unswitch is removing/replacing some loops (resulting in 11; Loop objects used as key in the analyses cache is destroyed). So here we 12; want to see that any analysis results cached on the destroyed loop is 13; cleared. A special case here is that loop_a_inner is destroyed when 14; unswitching the parent loop. 15; 16; The bug solved and verified by this test case was related to the 17; SimpleLoopUnswitch not marking the Loop as removed, so we missed clearing 18; the analysis caches. 19; 20; CHECK: Running pass: SimpleLoopUnswitchPass on loop %loop_begin in function test6 21; CHECK-NEXT: Running analysis: OuterAnalysisManagerProxy 22; CHECK-NEXT: Clearing all analysis results for: loop_a_inner 23 24 25; When running loop-distribute the second time we can see that loop_a_inner 26; isn't analysed because the loop no longer exists (instead we find a new loop, 27; loop_a_inner.us). This kind of verifies that it was correct to remove the 28; loop_a_inner related analysis above. 29; 30; CHECK: Invalidating analysis: LoopAccessAnalysis on test6 31; CHECK-NEXT: Running pass: LoopDistributePass on test6 32; CHECK-NEXT: Running analysis: LoopAccessAnalysis on test6 33 34 35define i32 @test6(ptr %ptr, i1 %cond1, ptr %a.ptr, ptr %b.ptr) { 36entry: 37 br label %loop_begin 38 39loop_begin: 40 %v = load i1, ptr %ptr 41 br i1 %cond1, label %loop_a, label %loop_b 42 43loop_a: 44 br label %loop_a_inner 45 46loop_a_inner: 47 %va = load i1, ptr %ptr 48 %a = load i32, ptr %a.ptr 49 br i1 %va, label %loop_a_inner, label %loop_a_inner_exit 50 51loop_a_inner_exit: 52 %a.lcssa = phi i32 [ %a, %loop_a_inner ] 53 br label %latch 54 55loop_b: 56 br label %loop_b_inner 57 58loop_b_inner: 59 %vb = load i1, ptr %ptr 60 %b = load i32, ptr %b.ptr 61 br i1 %vb, label %loop_b_inner, label %loop_b_inner_exit 62 63loop_b_inner_exit: 64 %b.lcssa = phi i32 [ %b, %loop_b_inner ] 65 br label %latch 66 67latch: 68 %ab.phi = phi i32 [ %a.lcssa, %loop_a_inner_exit ], [ %b.lcssa, %loop_b_inner_exit ] 69 br i1 %v, label %loop_begin, label %loop_exit 70 71loop_exit: 72 %ab.lcssa = phi i32 [ %ab.phi, %latch ] 73 ret i32 %ab.lcssa 74} 75