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