1 ; RUN: opt < %s -globals-aa -gvn -S | FileCheck %s
3 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5 @a = internal global i32* null, align 8
6 @b = global i32** @a, align 8
7 @c = global i32** @a, align 8
8 @d = common global i32 0, align 4
10 ; Make sure we globals-aa doesn't get confused and allow hoisting
11 ; the load from @a out of the loop.
13 ; CHECK-LABEL: define i32 @main()
15 ; CHECK-NEXT: %2 = load i32**, i32*** @b, align 8
16 ; CHECK-NEXT: store i32* @d, i32** %2, align 8
17 ; CHECK-NEXT: %3 = load i32*, i32** @a, align 8
18 ; CHECK-NEXT: %cmp1 = icmp ne i32* %3, @d
19 ; CHECK-NEXT: br i1 %cmp1, label %if.then, label %if.end
23 %0 = load i32, i32* @d, align 4
26 for.cond: ; preds = %if.end, %entry
27 %1 = phi i32 [ %inc, %if.end ], [ %0, %entry ]
28 %cmp = icmp slt i32 %1, 1
29 br i1 %cmp, label %for.body, label %for.end
31 for.body: ; preds = %for.cond
32 %2 = load i32**, i32*** @b, align 8
33 store i32* @d, i32** %2, align 8
34 %3 = load i32*, i32** @a, align 8
35 %cmp1 = icmp ne i32* %3, @d
36 br i1 %cmp1, label %if.then, label %if.end
38 if.then: ; preds = %for.body
41 if.end: ; preds = %for.body
42 %4 = load i32, i32* @d, align 4
43 %inc = add nsw i32 %4, 1
44 store i32 %inc, i32* @d, align 4
47 for.end: ; preds = %for.cond
50 return: ; preds = %for.end, %if.then
51 %retval.0 = phi i32 [ 1, %if.then ], [ 0, %for.end ]