1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S --passes='simplifycfg<hoist-common-insts>' -simplifycfg-hoist-common-skip-limit=0 %s | FileCheck %s --check-prefix=LIMIT0
3 ; RUN: opt -S --passes='simplifycfg<hoist-common-insts>' -simplifycfg-hoist-common-skip-limit=1 %s | FileCheck %s --check-prefix=LIMIT1
4 ; RUN: opt -S --passes='simplifycfg<hoist-common-insts>' -simplifycfg-hoist-common-skip-limit=2 %s | FileCheck %s --check-prefix=LIMIT2
6 define void @f(i1 %c, ptr nocapture noundef %d, ptr nocapture noundef readonly %m, ptr nocapture noundef readonly %b) {
9 ; LIMIT0-NEXT: [[TMP0:%.*]] = load i16, ptr [[B:%.*]], align 2
10 ; LIMIT0-NEXT: br i1 [[C:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
12 ; LIMIT0-NEXT: call void @no_side_effects0()
13 ; LIMIT0-NEXT: [[ADD:%.*]] = add nsw i16 [[TMP0]], 1
14 ; LIMIT0-NEXT: [[TMP1:%.*]] = load i16, ptr [[M:%.*]], align 2
15 ; LIMIT0-NEXT: [[U:%.*]] = add i16 [[ADD]], [[TMP1]]
16 ; LIMIT0-NEXT: br label [[IF_END:%.*]]
18 ; LIMIT0-NEXT: call void @no_side_effects1()
19 ; LIMIT0-NEXT: [[SUB:%.*]] = sub nsw i16 [[TMP0]], 1
20 ; LIMIT0-NEXT: [[TMP2:%.*]] = load i16, ptr [[M]], align 2
21 ; LIMIT0-NEXT: [[V:%.*]] = add i16 [[SUB]], [[TMP2]]
22 ; LIMIT0-NEXT: br label [[IF_END]]
24 ; LIMIT0-NEXT: [[UV:%.*]] = phi i16 [ [[V]], [[IF_ELSE]] ], [ [[U]], [[IF_THEN]] ]
25 ; LIMIT0-NEXT: store i16 [[UV]], ptr [[D:%.*]], align 2
26 ; LIMIT0-NEXT: ret void
30 ; LIMIT1-NEXT: [[TMP0:%.*]] = load i16, ptr [[B:%.*]], align 2
31 ; LIMIT1-NEXT: br i1 [[C:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
33 ; LIMIT1-NEXT: call void @no_side_effects0()
34 ; LIMIT1-NEXT: [[ADD:%.*]] = add nsw i16 [[TMP0]], 1
35 ; LIMIT1-NEXT: [[TMP1:%.*]] = load i16, ptr [[M:%.*]], align 2
36 ; LIMIT1-NEXT: [[U:%.*]] = add i16 [[ADD]], [[TMP1]]
37 ; LIMIT1-NEXT: br label [[IF_END:%.*]]
39 ; LIMIT1-NEXT: call void @no_side_effects1()
40 ; LIMIT1-NEXT: [[SUB:%.*]] = sub nsw i16 [[TMP0]], 1
41 ; LIMIT1-NEXT: [[TMP2:%.*]] = load i16, ptr [[M]], align 2
42 ; LIMIT1-NEXT: [[V:%.*]] = add i16 [[SUB]], [[TMP2]]
43 ; LIMIT1-NEXT: br label [[IF_END]]
45 ; LIMIT1-NEXT: [[UV:%.*]] = phi i16 [ [[V]], [[IF_ELSE]] ], [ [[U]], [[IF_THEN]] ]
46 ; LIMIT1-NEXT: store i16 [[UV]], ptr [[D:%.*]], align 2
47 ; LIMIT1-NEXT: ret void
51 ; LIMIT2-NEXT: [[TMP0:%.*]] = load i16, ptr [[B:%.*]], align 2
52 ; LIMIT2-NEXT: [[TMP1:%.*]] = load i16, ptr [[M:%.*]], align 2
53 ; LIMIT2-NEXT: br i1 [[C:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
55 ; LIMIT2-NEXT: call void @no_side_effects0()
56 ; LIMIT2-NEXT: [[ADD:%.*]] = add nsw i16 [[TMP0]], 1
57 ; LIMIT2-NEXT: [[U:%.*]] = add i16 [[ADD]], [[TMP1]]
58 ; LIMIT2-NEXT: br label [[IF_END:%.*]]
60 ; LIMIT2-NEXT: call void @no_side_effects1()
61 ; LIMIT2-NEXT: [[SUB:%.*]] = sub nsw i16 [[TMP0]], 1
62 ; LIMIT2-NEXT: [[V:%.*]] = add i16 [[SUB]], [[TMP1]]
63 ; LIMIT2-NEXT: br label [[IF_END]]
65 ; LIMIT2-NEXT: [[UV:%.*]] = phi i16 [ [[V]], [[IF_ELSE]] ], [ [[U]], [[IF_THEN]] ]
66 ; LIMIT2-NEXT: store i16 [[UV]], ptr [[D:%.*]], align 2
67 ; LIMIT2-NEXT: ret void
70 br i1 %c, label %if.then, label %if.else
73 %0 = load i16, ptr %b, align 2
74 call void @no_side_effects0()
75 %add = add nsw i16 %0, 1
76 %1 = load i16, ptr %m, align 2
81 %2 = load i16, ptr %b, align 2
82 call void @no_side_effects1()
83 %sub = sub nsw i16 %2, 1
84 %3 = load i16, ptr %m, align 2
89 %uv = phi i16 [ %v, %if.else ], [ %u, %if.then ]
90 store i16 %uv, ptr %d, align 2
94 declare void @side_effects0()
95 declare void @side_effects1()
96 declare void @no_side_effects0() readonly nounwind willreturn
97 declare void @no_side_effects1() readonly nounwind willreturn