1; RUN: opt -basicaa -gvn -S < %s | FileCheck %s
2@y = external global i32
3@z = external global i32
4
5; Function Attrs: nounwind ssp uwtable
6define void @foo(i32 %x) {
7; CHECK: @foo(i32 %x)
8; CHECK: %.pre = load i32* @y
9; CHECK: call void @bar(i32 %.pre)
10
11  %t = sub i32 %x, %x
12  %.pre = load i32* @y, align 4
13  %cmp = icmp sgt i32 %t, 2
14  br i1 %cmp, label %if.then, label %entry.if.end_crit_edge
15
16entry.if.end_crit_edge:                           ; preds = %entry
17  br label %if.end
18
19if.then:                                          ; preds = %entry
20  %add = add nsw i32 %x, 3
21  store i32 %add, i32* @y, align 4
22  br label %if.end
23
24if.end:                                           ; preds = %entry.if.end_crit_edge, %if.then
25  %1 = phi i32 [ %.pre, %entry.if.end_crit_edge ], [ %add, %if.then ]
26  tail call void @bar(i32 %1)
27  ret void
28}
29
30define void @foo2(i32 %x) {
31; CHECK: @foo2(i32 %x)
32; CHECK: %.pre = load i32* @y
33; CHECK: tail call void @bar(i32 %.pre)
34entry:
35  %t = sub i32 %x, %x
36  %.pre = load i32* @y, align 4
37  %cmp = icmp sgt i32 %t, 2
38  br i1 %cmp, label %if.then, label %if.else
39
40if.then:                                          ; preds = %entry
41  %add = add nsw i32 %x, 3
42  store i32 %add, i32* @y, align 4
43  br label %if.end
44
45if.else:                                          ; preds = %entry
46  store i32 1, i32* @z, align 4
47  br label %if.end
48
49if.end:                                           ; preds = %if.else, %if.then
50  %0 = phi i32 [ %.pre, %if.else ], [ %add, %if.then ]
51  tail call void @bar(i32 %0)
52  ret void
53}
54
55declare void @bar(i32)
56