xref: /llvm-project/llvm/test/Transforms/CodeExtractor/BlockAddressSelfReference.ll (revision bbbbbfbdcb1ab1ba9857138dfa0f2355da8e4499)
10ca8ddd8SRoman Lebedev; RUN: opt < %s -passes='function(loop-simplify),loop-extract'  -S | FileCheck %s
2cee313d2SEric Christopher
3*bbbbbfbdSNikita Popov@choum.addr = internal unnamed_addr constant [3 x ptr] [ptr blockaddress(@choum, %bb10), ptr blockaddress(@choum, %bb14), ptr blockaddress(@choum, %bb18)]
4cee313d2SEric Christopher
5cee313d2SEric Christopher; CHECK: define
6cee313d2SEric Christopher; no outlined function
7cee313d2SEric Christopher; CHECK-NOT: define
8cee313d2SEric Christopher
9*bbbbbfbdSNikita Popovdefine void @choum(i32 %arg, ptr nocapture %arg1, i32 %arg2) {
10cee313d2SEric Christopherbb:
11cee313d2SEric Christopher  %tmp = icmp sgt i32 %arg, 0
12cee313d2SEric Christopher  br i1 %tmp, label %bb3, label %bb24
13cee313d2SEric Christopher
14cee313d2SEric Christopherbb3:                                              ; preds = %bb
15cee313d2SEric Christopher  %tmp4 = sext i32 %arg2 to i64
16*bbbbbfbdSNikita Popov  %tmp5 = getelementptr inbounds [3 x ptr], ptr @choum.addr, i64 0, i64 %tmp4
17*bbbbbfbdSNikita Popov  %tmp6 = load ptr, ptr %tmp5
18cee313d2SEric Christopher  %tmp7 = zext i32 %arg to i64
19cee313d2SEric Christopher  br label %bb8
20cee313d2SEric Christopher
21cee313d2SEric Christopherbb8:                                              ; preds = %bb18, %bb3
22cee313d2SEric Christopher  %tmp9 = phi i64 [ 0, %bb3 ], [ %tmp22, %bb18 ]
23*bbbbbfbdSNikita Popov  indirectbr ptr %tmp6, [label %bb10, label %bb14, label %bb18]
24cee313d2SEric Christopher
25cee313d2SEric Christopherbb10:                                             ; preds = %bb8
26*bbbbbfbdSNikita Popov  %tmp11 = getelementptr inbounds i32, ptr %arg1, i64 %tmp9
27*bbbbbfbdSNikita Popov  %tmp12 = load i32, ptr %tmp11
28cee313d2SEric Christopher  %tmp13 = add nsw i32 %tmp12, 1
29*bbbbbfbdSNikita Popov  store i32 %tmp13, ptr %tmp11
30cee313d2SEric Christopher  br label %bb14
31cee313d2SEric Christopher
32cee313d2SEric Christopherbb14:                                             ; preds = %bb10, %bb8
33*bbbbbfbdSNikita Popov  %tmp15 = getelementptr inbounds i32, ptr %arg1, i64 %tmp9
34*bbbbbfbdSNikita Popov  %tmp16 = load i32, ptr %tmp15
35cee313d2SEric Christopher  %tmp17 = shl nsw i32 %tmp16, 1
36*bbbbbfbdSNikita Popov  store i32 %tmp17, ptr %tmp15
37cee313d2SEric Christopher  br label %bb18
38cee313d2SEric Christopher
39cee313d2SEric Christopherbb18:                                             ; preds = %bb14, %bb8
40*bbbbbfbdSNikita Popov  %tmp19 = getelementptr inbounds i32, ptr %arg1, i64 %tmp9
41*bbbbbfbdSNikita Popov  %tmp20 = load i32, ptr %tmp19
42cee313d2SEric Christopher  %tmp21 = add nsw i32 %tmp20, -3
43*bbbbbfbdSNikita Popov  store i32 %tmp21, ptr %tmp19
44cee313d2SEric Christopher  %tmp22 = add nuw nsw i64 %tmp9, 1
45cee313d2SEric Christopher  %tmp23 = icmp eq i64 %tmp22, %tmp7
46cee313d2SEric Christopher  br i1 %tmp23, label %bb24, label %bb8
47cee313d2SEric Christopher
48cee313d2SEric Christopherbb24:                                             ; preds = %bb18, %bb
49cee313d2SEric Christopher  ret void
50cee313d2SEric Christopher}
51