1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=internalize,ipsccp %s | FileCheck %s
5 ; If BasicBlocks are unreachable, IPSCCP should convert them to unreachable.
6 ; Unless they have their address taken, delete them. If they do have their
7 ; address taken, let other passes replace these "dead" blockaddresses with some
10 ; CHECK: @bar.l = internal constant [2 x ptr] [ptr blockaddress(@bar, %lab0), ptr blockaddress(@bar, %end)]
13 @code = global [5 x i32] [i32 0, i32 0, i32 0, i32 0, i32 1], align 4 ; <ptr> [#uses=0]
14 @bar.l = internal constant [2 x ptr] [ptr blockaddress(@bar, %lab0), ptr blockaddress(@bar, %end)] ; <ptr> [#uses=1]
16 define void @foo(i32 %x) nounwind readnone {
19 ; CHECK-NEXT: unreachable
22 %b = alloca i32, align 4 ; <ptr> [#uses=1]
23 store volatile i32 -1, ptr %b
27 define void @bar(ptr nocapture %pc) nounwind readonly {
30 ; CHECK-NEXT: unreachable
32 ; CHECK-NEXT: unreachable
34 ; CHECK-NEXT: unreachable
37 br label %indirectgoto
39 lab0: ; preds = %indirectgoto
40 %indvar.next = add i32 %indvar, 1 ; <i32> [#uses=1]
41 br label %indirectgoto
43 end: ; preds = %indirectgoto
46 indirectgoto: ; preds = %lab0, %entry
47 %indvar = phi i32 [ %indvar.next, %lab0 ], [ 0, %entry ] ; <i32> [#uses=2]
48 %pc.addr.0 = getelementptr i32, ptr %pc, i32 %indvar ; <ptr> [#uses=1]
49 %tmp1.pn = load i32, ptr %pc.addr.0 ; <i32> [#uses=1]
50 %indirect.goto.dest.in = getelementptr inbounds [2 x ptr], ptr @bar.l, i32 0, i32 %tmp1.pn ; <ptr> [#uses=1]
51 %indirect.goto.dest = load ptr, ptr %indirect.goto.dest.in ; <ptr> [#uses=1]
52 indirectbr ptr %indirect.goto.dest, [label %lab0, label %end]
55 define i32 @main() nounwind readnone {
58 ; CHECK-NEXT: unreachable
64 ; https://github.com/llvm/llvm-project/issues/54238
65 ; https://github.com/llvm/llvm-project/issues/54251
66 ; https://github.com/llvm/llvm-project/issues/54328
68 ; CHECK-LABEL: @test1(
69 ; CHECK-NEXT: unreachable
71 ; CHECK-NEXT: unreachable
73 %1 = bitcast ptr blockaddress(@test1, %redirected) to ptr
74 call void @set_return_addr(ptr %1)
81 define internal void @set_return_addr(ptr %addr) {
82 ; CHECK-LABEL: @set_return_addr(
83 ; CHECK-NEXT: unreachable
85 %addr.addr = alloca ptr, i32 0, align 8
86 store ptr %addr, ptr %addr.addr, align 8