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