1; RUN: opt < %s -enable-loop-distribute -passes='loop-distribute,loop-mssa(simple-loop-unswitch<nontrivial>),loop-distribute' -o /dev/null -S -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 Loop at depth 2 containing: %loop_a_inner<header><latch><exiting> 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 at depth 1 containing: %loop_begin<header>,%loop_b,%loop_b_inner,%loop_b_inner_exit,%loop_a,%loop_a_inner,%loop_a_inner_exit,%latch<latch><exiting> 21; CHECK-NEXT: Clearing all analysis results for: loop_a_inner 22 23 24; When running loop-distribute the second time we can see that loop_a_inner 25; isn't analysed because the loop no longer exists (instead we find a new loop, 26; loop_a_inner.us). This kind of verifies that it was correct to remove the 27; loop_a_inner related analysis above. 28; 29; CHECK: Running analysis: LoopAccessAnalysis on Loop at depth 2 containing: %loop_a_inner.us<header><latch><exiting> 30 31 32define i32 @test6(i1* %ptr, i1 %cond1, i32* %a.ptr, i32* %b.ptr) { 33entry: 34 br label %loop_begin 35 36loop_begin: 37 %v = load i1, i1* %ptr 38 br i1 %cond1, label %loop_a, label %loop_b 39 40loop_a: 41 br label %loop_a_inner 42 43loop_a_inner: 44 %va = load i1, i1* %ptr 45 %a = load i32, i32* %a.ptr 46 br i1 %va, label %loop_a_inner, label %loop_a_inner_exit 47 48loop_a_inner_exit: 49 %a.lcssa = phi i32 [ %a, %loop_a_inner ] 50 br label %latch 51 52loop_b: 53 br label %loop_b_inner 54 55loop_b_inner: 56 %vb = load i1, i1* %ptr 57 %b = load i32, i32* %b.ptr 58 br i1 %vb, label %loop_b_inner, label %loop_b_inner_exit 59 60loop_b_inner_exit: 61 %b.lcssa = phi i32 [ %b, %loop_b_inner ] 62 br label %latch 63 64latch: 65 %ab.phi = phi i32 [ %a.lcssa, %loop_a_inner_exit ], [ %b.lcssa, %loop_b_inner_exit ] 66 br i1 %v, label %loop_begin, label %loop_exit 67 68loop_exit: 69 %ab.lcssa = phi i32 [ %ab.phi, %latch ] 70 ret i32 %ab.lcssa 71} 72