1 ; RUN: opt < %s -passes=adce -disable-output
2 ; RUN: opt < %s -passes=adce -adce-remove-loops -S | FileCheck %s
4 %FILE = type { i32, ptr, ptr, i8, i8, i32, i32, i32 }
5 %spec_fd_t = type { i32, i32, i32, ptr }
6 @__iob = external global [20 x %FILE] ; <ptr> [#uses=1]
7 @dbglvl = global i32 4 ; <ptr> [#uses=3]
8 @spec_fd = external global [3 x %spec_fd_t] ; <ptr> [#uses=4]
9 @.LC9 = internal global [34 x i8] c"spec_read: fd=%d, > MAX_SPEC_FD!\0A\00" ; <ptr> [#uses=1]
10 @.LC10 = internal global [4 x i8] c"EOF\00" ; <ptr> [#uses=1]
11 @.LC11 = internal global [4 x i8] c"%d\0A\00" ; <ptr> [#uses=1]
12 @.LC12 = internal global [17 x i8] c"spec_getc: %d = \00" ; <ptr> [#uses=1]
14 declare i32 @fprintf(ptr, ptr, ...)
16 declare void @exit(i32)
18 declare i32 @remove(ptr)
20 declare i32 @fputc(i32, ptr)
22 declare i32 @fwrite(ptr, i32, i32, ptr)
24 declare void @perror(ptr)
26 define i32 @spec_getc(i32 %fd) {
27 %reg109 = load i32, ptr @dbglvl ; <i32> [#uses=1]
28 %cond266 = icmp sle i32 %reg109, 4 ; <i1> [#uses=1]
29 ; CHECK: br label %bb3
30 br i1 %cond266, label %bb3, label %bb2
33 %cast273 = getelementptr [17 x i8], ptr @.LC12, i64 0, i64 0 ; <ptr> [#uses=0]
36 bb3: ; preds = %bb2, %0
37 %cond267 = icmp sle i32 %fd, 3 ; <i1> [#uses=0]
40 bb4: ; No predecessors!
41 %reg111 = getelementptr [20 x %FILE], ptr @__iob, i64 0, i64 1, i32 3 ; <ptr> [#uses=1]
42 %cast274 = getelementptr [34 x i8], ptr @.LC9, i64 0, i64 0 ; <ptr> [#uses=0]
43 call void @exit( i32 1 )
44 br label %UnifiedExitNode
47 %reg107-idxcast1 = sext i32 %fd to i64 ; <i64> [#uses=2]
48 %reg107-idxcast2 = sext i32 %fd to i64 ; <i64> [#uses=1]
49 %reg1311 = getelementptr [3 x %spec_fd_t], ptr @spec_fd, i64 0, i64 %reg107-idxcast2 ; <ptr> [#uses=1]
50 %idx1 = getelementptr [3 x %spec_fd_t], ptr @spec_fd, i64 0, i64 %reg107-idxcast1, i32 2 ; <ptr> [#uses=1]
51 %reg1321 = load i32, ptr %idx1 ; <i32> [#uses=3]
52 %idx2 = getelementptr %spec_fd_t, ptr %reg1311, i64 0, i32 1 ; <ptr> [#uses=1]
53 %reg1331 = load i32, ptr %idx2 ; <i32> [#uses=1]
54 %cond270 = icmp slt i32 %reg1321, %reg1331 ; <i1> [#uses=1]
55 br i1 %cond270, label %bb9, label %bb6
58 %reg134 = load i32, ptr @dbglvl ; <i32> [#uses=1]
59 %cond271 = icmp sle i32 %reg134, 4 ; <i1> [#uses=1]
60 ; CHECK: br label %bb8
61 br i1 %cond271, label %bb8, label %bb7
64 %cast277 = getelementptr [4 x i8], ptr @.LC10, i64 0, i64 0 ; <ptr> [#uses=0]
67 bb8: ; preds = %bb7, %bb6
68 br label %UnifiedExitNode
71 %reg107-idxcast3 = sext i32 %fd to i64 ; <i64> [#uses=1]
72 %idx3 = getelementptr [3 x %spec_fd_t], ptr @spec_fd, i64 0, i64 %reg107-idxcast3, i32 3 ; <ptr> [#uses=1]
73 %reg1601 = load ptr, ptr %idx3 ; <ptr> [#uses=1]
74 %reg132-idxcast1 = sext i32 %reg1321 to i64 ; <i64> [#uses=1]
75 %idx4 = getelementptr i8, ptr %reg1601, i64 %reg132-idxcast1 ; <ptr> [#uses=1]
76 %reg1621 = load i8, ptr %idx4 ; <i8> [#uses=2]
77 %cast108 = zext i8 %reg1621 to i64 ; <i64> [#uses=0]
78 %reg157 = add i32 %reg1321, 1 ; <i32> [#uses=1]
79 %idx5 = getelementptr [3 x %spec_fd_t], ptr @spec_fd, i64 0, i64 %reg107-idxcast1, i32 2 ; <ptr> [#uses=1]
80 store i32 %reg157, ptr %idx5
81 %reg163 = load i32, ptr @dbglvl ; <i32> [#uses=1]
82 %cond272 = icmp sle i32 %reg163, 4 ; <i1> [#uses=1]
83 ; CHECK: br label %bb11
84 br i1 %cond272, label %bb11, label %bb10
87 %cast279 = getelementptr [4 x i8], ptr @.LC11, i64 0, i64 0 ; <ptr> [#uses=0]
90 bb11: ; preds = %bb10, %bb9
91 %cast291 = zext i8 %reg1621 to i32 ; <i32> [#uses=1]
92 br label %UnifiedExitNode
94 UnifiedExitNode: ; preds = %bb11, %bb8, %bb4
95 %UnifiedRetVal = phi i32 [ 42, %bb4 ], [ -1, %bb8 ], [ %cast291, %bb11 ] ; <i32> [#uses=1]
96 ret i32 %UnifiedRetVal
99 declare i32 @puts(ptr)
101 declare i32 @printf(ptr, ...)