Bill Wendling | cd6df16 | 2012-04-24 09:15:38 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -basicaa -gvn -instcombine -S | FileCheck %s |
Nick Lewycky | 2abb108 | 2008-12-19 06:39:12 +0000 | [diff] [blame] | 2 | |
| 3 | declare i32* @test(i32* nocapture) |
| 4 | |
| 5 | define i32 @test2() { |
Bill Wendling | cd6df16 | 2012-04-24 09:15:38 +0000 | [diff] [blame] | 6 | ; CHECK: ret i32 0 |
Nick Lewycky | 2abb108 | 2008-12-19 06:39:12 +0000 | [diff] [blame] | 7 | %P = alloca i32 |
| 8 | %Q = call i32* @test(i32* %P) |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 9 | %a = load i32, i32* %P |
Nick Lewycky | 2abb108 | 2008-12-19 06:39:12 +0000 | [diff] [blame] | 10 | store i32 4, i32* %Q ;; cannot clobber P since it is nocapture. |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 11 | %b = load i32, i32* %P |
Nick Lewycky | 2abb108 | 2008-12-19 06:39:12 +0000 | [diff] [blame] | 12 | %c = sub i32 %a, %b |
| 13 | ret i32 %c |
| 14 | } |
| 15 | |
Richard Osborne | a1fffcf | 2012-11-05 10:48:24 +0000 | [diff] [blame] | 16 | declare void @test3(i32** %p, i32* %q) nounwind |
| 17 | |
| 18 | define 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 Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 22 | ; CHECK: %y = load i32, i32* %p |
Richard Osborne | a1fffcf | 2012-11-05 10:48:24 +0000 | [diff] [blame] | 23 | ; CHECK: ret i32 %y |
| 24 | entry: |
| 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 Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 30 | %x = load i32*, i32** %q |
Richard Osborne | a1fffcf | 2012-11-05 10:48:24 +0000 | [diff] [blame] | 31 | ; This store might write to %p and so we can't eliminate the subsequent |
| 32 | ; load |
| 33 | store i32 1, i32* %x |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 34 | %y = load i32, i32* %p |
Richard Osborne | a1fffcf | 2012-11-05 10:48:24 +0000 | [diff] [blame] | 35 | ret i32 %y |
| 36 | } |