Dan Gohman | d363ae5 | 2013-01-31 00:01:45 +0000 | [diff] [blame] | 1 | ; This test checks to make sure that constant exprs don't fold in some simple |
| 2 | ; situations |
| 3 | |
| 4 | ; RUN: llvm-as < %s | llvm-dis | FileCheck %s |
Duncan P. N. Exon Smith | 13f5c58 | 2014-08-19 21:08:27 +0000 | [diff] [blame] | 5 | ; RUN: verify-uselistorder %s |
Dan Gohman | d363ae5 | 2013-01-31 00:01:45 +0000 | [diff] [blame] | 6 | |
| 7 | ; Even give it a datalayout, to tempt folding as much as possible. |
| 8 | target datalayout = "p:32:32" |
| 9 | |
| 10 | @A = global i64 0 |
| 11 | @B = global i64 0 |
| 12 | |
| 13 | ; Don't fold this. @A might really be allocated next to @B, in which case the |
| 14 | ; icmp should return true. It's not valid to *dereference* in @B from a pointer |
| 15 | ; based on @A, but icmp isn't a dereference. |
| 16 | |
David Blaikie | 5a70dd1 | 2015-03-13 18:20:45 +0000 | [diff] [blame] | 17 | ; CHECK: @C = global i1 icmp eq (i64* getelementptr inbounds (i64, i64* @A, i64 1), i64* @B) |
| 18 | @C = global i1 icmp eq (i64* getelementptr inbounds (i64, i64* @A, i64 1), i64* @B) |
Dan Gohman | d363ae5 | 2013-01-31 00:01:45 +0000 | [diff] [blame] | 19 | |
| 20 | ; Don't fold this completely away either. In theory this could be simplified |
| 21 | ; to only use a gep on one side of the icmp though. |
| 22 | |
David Blaikie | 5a70dd1 | 2015-03-13 18:20:45 +0000 | [diff] [blame] | 23 | ; CHECK: @D = global i1 icmp eq (i64* getelementptr inbounds (i64, i64* @A, i64 1), i64* getelementptr inbounds (i64, i64* @B, i64 2)) |
| 24 | @D = global i1 icmp eq (i64* getelementptr inbounds (i64, i64* @A, i64 1), i64* getelementptr inbounds (i64, i64* @B, i64 2)) |
Matt Arsenault | 59d3ae6 | 2013-11-15 01:34:59 +0000 | [diff] [blame] | 25 | |
| 26 | ; CHECK: @E = global i64 addrspace(1)* addrspacecast (i64* @A to i64 addrspace(1)*) |
| 27 | @E = global i64 addrspace(1)* addrspacecast(i64* @A to i64 addrspace(1)*) |
Duncan P. N. Exon Smith | 7a5cb43 | 2014-08-16 01:54:32 +0000 | [diff] [blame] | 28 | |
| 29 | ; Don't add an inbounds on @weak.gep, since @weak may be null. |
David Blaikie | 5a70dd1 | 2015-03-13 18:20:45 +0000 | [diff] [blame] | 30 | ; CHECK: @weak.gep = global i32* getelementptr (i32, i32* @weak, i32 1) |
| 31 | @weak.gep = global i32* getelementptr (i32, i32* @weak, i32 1) |
Duncan P. N. Exon Smith | 7a5cb43 | 2014-08-16 01:54:32 +0000 | [diff] [blame] | 32 | @weak = extern_weak global i32 |
| 33 | |
David Majnemer | 278bbac | 2014-12-06 11:58:33 +0000 | [diff] [blame] | 34 | ; An object with weak linkage cannot have it's identity determined at compile time. |
| 35 | ; CHECK: @F = global i1 icmp eq (i32* @weakany, i32* @glob) |
| 36 | @F = global i1 icmp eq (i32* @weakany, i32* @glob) |
| 37 | @weakany = weak global i32 0 |
| 38 | |
David Majnemer | 8eef439 | 2014-12-08 19:35:31 +0000 | [diff] [blame] | 39 | ; Empty globals might end up anywhere, even on top of another global. |
| 40 | ; CHECK: @empty.cmp = global i1 icmp eq ([0 x i8]* @empty.1, [0 x i8]* @empty.2) |
| 41 | @empty.1 = external global [0 x i8], align 1 |
| 42 | @empty.2 = external global [0 x i8], align 1 |
| 43 | @empty.cmp = global i1 icmp eq ([0 x i8]* @empty.1, [0 x i8]* @empty.2) |
| 44 | |
Matt Arsenault | 737191d | 2018-06-26 18:55:43 +0000 | [diff] [blame] | 45 | @addrspace3 = internal addrspace(3) global i32 undef |
| 46 | |
| 47 | ; CHECK: @no.fold.addrspace.icmp.eq.gv.null = global i1 icmp eq (i32 addrspace(3)* @addrspace3, i32 addrspace(3)* null) |
| 48 | ; CHECK: @no.fold.addrspace.icmp.eq.null.gv = global i1 icmp eq (i32 addrspace(3)* @addrspace3, i32 addrspace(3)* null) |
| 49 | ; CHECK: @no.fold.addrspace.icmp.ne.gv.null = global i1 icmp ne (i32 addrspace(3)* @addrspace3, i32 addrspace(3)* null) |
| 50 | ; CHECK: @no.fold.addrspace.icmp.ne.null.gv = global i1 icmp ne (i32 addrspace(3)* @addrspace3, i32 addrspace(3)* null) |
| 51 | @no.fold.addrspace.icmp.eq.gv.null = global i1 icmp eq (i32 addrspace(3)* @addrspace3, i32 addrspace(3)* null) |
| 52 | @no.fold.addrspace.icmp.eq.null.gv = global i1 icmp eq (i32 addrspace(3)* null, i32 addrspace(3)* @addrspace3) |
| 53 | @no.fold.addrspace.icmp.ne.gv.null = global i1 icmp ne (i32 addrspace(3)* @addrspace3, i32 addrspace(3)* null) |
| 54 | @no.fold.addrspace.icmp.ne.null.gv = global i1 icmp ne (i32 addrspace(3)* null, i32 addrspace(3)* @addrspace3) |
| 55 | |
Duncan P. N. Exon Smith | 7a5cb43 | 2014-08-16 01:54:32 +0000 | [diff] [blame] | 56 | ; Don't add an inbounds on @glob.a3, since it's not inbounds. |
David Blaikie | 21f77df | 2015-09-11 03:22:04 +0000 | [diff] [blame] | 57 | ; CHECK: @glob.a3 = alias i32, getelementptr (i32, i32* @glob.a2, i32 1) |
Duncan P. N. Exon Smith | 7a5cb43 | 2014-08-16 01:54:32 +0000 | [diff] [blame] | 58 | @glob = global i32 0 |
David Blaikie | 21f77df | 2015-09-11 03:22:04 +0000 | [diff] [blame] | 59 | @glob.a3 = alias i32, getelementptr (i32, i32* @glob.a2, i32 1) |
| 60 | @glob.a2 = alias i32, getelementptr (i32, i32* @glob.a1, i32 1) |
| 61 | @glob.a1 = alias i32, i32* @glob |