1; RUN: opt < %s -basicaa -gvn -instcombine -S | FileCheck %s
2
3declare i32* @test(i32* nocapture)
4
5define i32 @test2() {
6; CHECK: ret i32 0
7       %P = alloca i32
8       %Q = call i32* @test(i32* %P)
9       %a = load i32* %P
10       store i32 4, i32* %Q   ;; cannot clobber P since it is nocapture.
11       %b = load i32* %P
12       %c = sub i32 %a, %b
13       ret i32 %c
14}
15
16declare void @test3(i32** %p, i32* %q) nounwind
17
18define i32 @test4(i32* noalias nocapture %p) nounwind {
19; CHECK: call void @test3
20; CHECK: store i32 0, i32* %p
21; CHECK: store i32 1, i32* %x
22; CHECK: %y = load i32* %p
23; CHECK: ret i32 %y
24entry:
25       %q = alloca i32*
26       ; Here test3 might store %p to %q. This doesn't violate %p's nocapture
27       ; attribute since the copy doesn't outlive the function.
28       call void @test3(i32** %q, i32* %p) nounwind
29       store i32 0, i32* %p
30       %x = load i32** %q
31       ; This store might write to %p and so we can't eliminate the subsequent
32       ; load
33       store i32 1, i32* %x
34       %y = load i32* %p
35       ret i32 %y
36}
37