xref: /llvm-project/llvm/test/Transforms/SimpleLoopUnswitch/preserve-scev-exiting-multiple-loops.ll (revision a40d5e37836984ad833c68ed62409b5113072b42)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2
3; We run -passes=indvars before -passes=simple-loop-unswitch to compute SCEV exit counts before
4; running -simple-loop-unswitch.
5; RUN:  opt -passes=indvars,simple-loop-unswitch -S %s -verify-scev | FileCheck %s
6
7; Test for PR43972.
8
9; We have a 3 nested loops (l1 <- l2 <- l3). %for.cond.5 is the exit block of
10; l3 and the loop for it is l2. But it is also the exiting block of l1. That
11; means we have to invalidate l1 to preserve SCEV.
12
13define void @f() {
14; CHECK-LABEL: @f(
15; CHECK-NEXT:  entry:
16; CHECK-NEXT:    [[LNOT:%.*]] = xor i1 undef, true
17; CHECK-NEXT:    br label [[FOR_COND:%.*]]
18; CHECK:       for.cond.loopexit:
19; CHECK-NEXT:    br label [[FOR_COND]]
20; CHECK:       for.cond:
21; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
22; CHECK:       for.cond1:
23; CHECK-NEXT:    br i1 true, label [[FOR_BODY]], label [[FOR_COND_LOOPEXIT:%.*]]
24; CHECK:       for.body:
25; CHECK-NEXT:    br i1 [[LNOT]], label [[FOR_BODY_SPLIT:%.*]], label [[FOR_COND5_SPLIT:%.*]]
26; CHECK:       for.body.split:
27; CHECK-NEXT:    br label [[LAND_RHS:%.*]]
28; CHECK:       for.cond2:
29; CHECK-NEXT:    br i1 true, label [[LAND_RHS]], label [[FOR_COND5:%.*]]
30; CHECK:       land.rhs:
31; CHECK-NEXT:    br label [[FOR_COND2:%.*]]
32; CHECK:       for.cond5:
33; CHECK-NEXT:    br label [[FOR_COND5_SPLIT]]
34; CHECK:       for.cond5.split:
35; CHECK-NEXT:    br i1 true, label [[FOR_BODY7:%.*]], label [[FOR_COND1:%.*]]
36; CHECK:       for.body7:
37; CHECK-NEXT:    ret void
38;
39entry:
40  %lnot = xor i1 undef, true
41  br label %for.cond
42
43for.cond:                                         ; preds = %for.cond1, %entry
44  br label %for.body
45
46for.cond1:                                        ; preds = %for.cond5
47  br i1 true, label %for.body, label %for.cond
48
49for.body:                                         ; preds = %for.cond1, %for.cond
50  br label %land.rhs
51
52for.cond2:                                        ; preds = %land.rhs
53  br i1 true, label %land.rhs, label %for.cond5
54
55land.rhs:                                         ; preds = %for.cond2, %for.body
56  br i1 %lnot, label %for.cond2, label %for.cond5
57
58for.cond5:                                        ; preds = %land.rhs, %for.cond2
59  br i1 true, label %for.body7, label %for.cond1
60
61for.body7:                                        ; preds = %for.cond5
62  ret void
63}
64