blob: 26cb69bffcc02ccc2be3d7c33c03de07c20b7dc0 [file] [log] [blame]
Bill Wendlingcd6df162012-04-24 09:15:38 +00001; RUN: opt < %s -basicaa -gvn -instcombine -S | FileCheck %s
Nick Lewycky2abb1082008-12-19 06:39:12 +00002
3declare i32* @test(i32* nocapture)
4
5define i32 @test2() {
Bill Wendlingcd6df162012-04-24 09:15:38 +00006; CHECK: ret i32 0
Nick Lewycky2abb1082008-12-19 06:39:12 +00007 %P = alloca i32
8 %Q = call i32* @test(i32* %P)
David Blaikiea79ac142015-02-27 21:17:42 +00009 %a = load i32, i32* %P
Nick Lewycky2abb1082008-12-19 06:39:12 +000010 store i32 4, i32* %Q ;; cannot clobber P since it is nocapture.
David Blaikiea79ac142015-02-27 21:17:42 +000011 %b = load i32, i32* %P
Nick Lewycky2abb1082008-12-19 06:39:12 +000012 %c = sub i32 %a, %b
13 ret i32 %c
14}
15
Richard Osbornea1fffcf2012-11-05 10:48:24 +000016declare 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
David Blaikiea79ac142015-02-27 21:17:42 +000022; CHECK: %y = load i32, i32* %p
Richard Osbornea1fffcf2012-11-05 10:48:24 +000023; 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
David Blaikiea79ac142015-02-27 21:17:42 +000030 %x = load i32*, i32** %q
Richard Osbornea1fffcf2012-11-05 10:48:24 +000031 ; This store might write to %p and so we can't eliminate the subsequent
32 ; load
33 store i32 1, i32* %x
David Blaikiea79ac142015-02-27 21:17:42 +000034 %y = load i32, i32* %p
Richard Osbornea1fffcf2012-11-05 10:48:24 +000035 ret i32 %y
36}