1; RUN: opt < %s -globals-aa -gvn -S | FileCheck %s 2 3target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 4 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 9 10; Make sure we globals-aa doesn't get confused and allow hoisting 11; the load from @a out of the loop. 12 13; CHECK-LABEL: define i32 @main() 14; CHECK: for.body: 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 20 21define i32 @main() { 22entry: 23 %0 = load i32, i32* @d, align 4 24 br label %for.cond 25 26for.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 30 31for.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 37 38if.then: ; preds = %for.body 39 br label %return 40 41if.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 45 br label %for.cond 46 47for.end: ; preds = %for.cond 48 br label %return 49 50return: ; preds = %for.end, %if.then 51 %retval.0 = phi i32 [ 1, %if.then ], [ 0, %for.end ] 52 ret i32 %retval.0 53} 54 55