Merging r257940:
[oota-llvm.git] / test / Transforms / InstSimplify / past-the-end.ll
1 ; RUN: opt < %s -instsimplify -S | FileCheck %s
2 target datalayout = "p:32:32"
3
4 ; Check some past-the-end subtleties.
5
6 @opte_a = global i32 0
7 @opte_b = global i32 0
8
9 ; Comparing base addresses of two distinct globals. Never equal.
10
11 define zeroext i1 @no_offsets() {
12   %t = icmp eq i32* @opte_a, @opte_b
13   ret i1 %t
14   ; CHECK: no_offsets(
15   ; CHECK: ret i1 false
16 }
17
18 ; Comparing past-the-end addresses of two distinct globals. Never equal.
19
20 define zeroext i1 @both_past_the_end() {
21   %x = getelementptr i32, i32* @opte_a, i32 1
22   %y = getelementptr i32, i32* @opte_b, i32 1
23   %t = icmp eq i32* %x, %y
24   ret i1 %t
25   ; CHECK: both_past_the_end(
26   ; CHECK-NOT: ret i1 true
27   ; TODO: refine this
28 }
29
30 ; Comparing past-the-end addresses of one global to the base address
31 ; of another. Can't fold this.
32
33 define zeroext i1 @just_one_past_the_end() {
34   %x = getelementptr i32, i32* @opte_a, i32 1
35   %t = icmp eq i32* %x, @opte_b
36   ret i1 %t
37   ; CHECK: just_one_past_the_end(
38   ; CHECK: ret i1 icmp eq (i32* getelementptr inbounds (i32, i32* @opte_a, i32 1), i32* @opte_b)
39 }
40
41 ; Comparing base addresses of two distinct allocas. Never equal.
42
43 define zeroext i1 @no_alloca_offsets() {
44   %m = alloca i32
45   %n = alloca i32
46   %t = icmp eq i32* %m, %n
47   ret i1 %t
48   ; CHECK: no_alloca_offsets(
49   ; CHECK: ret i1 false
50 }
51
52 ; Comparing past-the-end addresses of two distinct allocas. Never equal.
53
54 define zeroext i1 @both_past_the_end_alloca() {
55   %m = alloca i32
56   %n = alloca i32
57   %x = getelementptr i32, i32* %m, i32 1
58   %y = getelementptr i32, i32* %n, i32 1
59   %t = icmp eq i32* %x, %y
60   ret i1 %t
61   ; CHECK: both_past_the_end_alloca(
62   ; CHECK-NOT: ret i1 true
63   ; TODO: refine this
64 }
65
66 ; Comparing past-the-end addresses of one alloca to the base address
67 ; of another. Can't fold this.
68
69 define zeroext i1 @just_one_past_the_end_alloca() {
70   %m = alloca i32
71   %n = alloca i32
72   %x = getelementptr i32, i32* %m, i32 1
73   %t = icmp eq i32* %x, %n
74   ret i1 %t
75   ; CHECK: just_one_past_the_end_alloca(
76   ; CHECK: ret i1 %t
77 }