xref: /llvm-project/llvm/test/Transforms/LoopFlatten/pr49571.ll (revision 72482c5167247f74592e9642fe2dbee9eb0e7297)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -S -passes='loop(loop-flatten),verify' -verify-loop-info -verify-dom-info -verify-scev | FileCheck %s
3
4; Testcase of PR49571
5; Previously we had an assertion that the incoming value from the
6; loop latch (%inc) is the same as the operator in the compare
7; statement (%0). This does not necessarily hold as demonstrated
8; in the following case.
9
10define dso_local void @main() {
11; CHECK-LABEL: @main(
12; CHECK-NEXT:  entry:
13; CHECK-NEXT:    br label [[FOR_COND:%.*]]
14; CHECK:       for.cond:
15; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
16; CHECK:       for.body:
17; CHECK-NEXT:    [[A_03:%.*]] = phi i32 [ 0, [[FOR_COND]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
18; CHECK-NEXT:    br label [[FOR_INC]]
19; CHECK:       for.inc:
20; CHECK-NEXT:    [[TMP0:%.*]] = add i32 [[A_03]], 1
21; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[TMP0]], 10
22; CHECK-NEXT:    [[INC]] = add nsw i32 [[A_03]], 1
23; CHECK-NEXT:    br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END:%.*]]
24; CHECK:       for.end:
25; CHECK-NEXT:    br label [[FOR_COND]]
26;
27entry:
28  br label %for.cond
29
30for.cond:                                         ; preds = %for.end, %entry
31  br label %for.body
32
33for.body:                                         ; preds = %for.inc, %for.cond
34  %a.03 = phi i32 [ 0, %for.cond ], [ %inc, %for.inc ]
35  br label %for.inc
36
37for.inc:                                          ; preds = %for.body
38  %0 = add i32 %a.03, 1
39  %cmp = icmp slt i32 %0, 10
40  %inc = add nsw i32 %a.03, 1
41  br i1 %cmp, label %for.body, label %for.end
42
43for.end:                                          ; preds = %for.inc
44  br label %for.cond
45}
46