blob: b47db7defcbd2e2e3b6a95269d0ac5cb796eab82 [file] [log] [blame]
Sanjay Patel69632442016-03-25 20:12:25 +00001; NOTE: Assertions have been autogenerated by update_test_checks.py
Dan Gohman9ee4bc12013-02-01 19:37:52 +00002; RUN: opt < %s -instsimplify -S | FileCheck %s
3target datalayout = "p:32:32"
4
5; Check some past-the-end subtleties.
6
7@opte_a = global i32 0
8@opte_b = global i32 0
9
10; Comparing base addresses of two distinct globals. Never equal.
11
12define zeroext i1 @no_offsets() {
Sanjay Patel69632442016-03-25 20:12:25 +000013; CHECK-LABEL: @no_offsets(
14; CHECK: ret i1 false
15;
Dan Gohman9ee4bc12013-02-01 19:37:52 +000016 %t = icmp eq i32* @opte_a, @opte_b
17 ret i1 %t
Dan Gohman9ee4bc12013-02-01 19:37:52 +000018}
19
20; Comparing past-the-end addresses of two distinct globals. Never equal.
21
22define zeroext i1 @both_past_the_end() {
Sanjay Patel69632442016-03-25 20:12:25 +000023; CHECK-LABEL: @both_past_the_end(
24; CHECK: ret i1 icmp eq (i32* getelementptr inbounds (i32, i32* @opte_a, i32 1), i32* getelementptr inbounds (i32, i32* @opte_b, i32 1))
25;
David Blaikie79e6c742015-02-27 19:29:02 +000026 %x = getelementptr i32, i32* @opte_a, i32 1
27 %y = getelementptr i32, i32* @opte_b, i32 1
Dan Gohman9ee4bc12013-02-01 19:37:52 +000028 %t = icmp eq i32* %x, %y
29 ret i1 %t
Dan Gohman9ee4bc12013-02-01 19:37:52 +000030 ; TODO: refine this
31}
32
33; Comparing past-the-end addresses of one global to the base address
34; of another. Can't fold this.
35
36define zeroext i1 @just_one_past_the_end() {
Sanjay Patel69632442016-03-25 20:12:25 +000037; CHECK-LABEL: @just_one_past_the_end(
38; CHECK: ret i1 icmp eq (i32* getelementptr inbounds (i32, i32* @opte_a, i32 1), i32* @opte_b)
39;
David Blaikie79e6c742015-02-27 19:29:02 +000040 %x = getelementptr i32, i32* @opte_a, i32 1
Dan Gohman9ee4bc12013-02-01 19:37:52 +000041 %t = icmp eq i32* %x, @opte_b
42 ret i1 %t
Dan Gohman9ee4bc12013-02-01 19:37:52 +000043}
44
45; Comparing base addresses of two distinct allocas. Never equal.
46
47define zeroext i1 @no_alloca_offsets() {
Sanjay Patel69632442016-03-25 20:12:25 +000048; CHECK-LABEL: @no_alloca_offsets(
49; CHECK: ret i1 false
50;
Dan Gohman9ee4bc12013-02-01 19:37:52 +000051 %m = alloca i32
52 %n = alloca i32
53 %t = icmp eq i32* %m, %n
54 ret i1 %t
Dan Gohman9ee4bc12013-02-01 19:37:52 +000055}
56
57; Comparing past-the-end addresses of two distinct allocas. Never equal.
58
59define zeroext i1 @both_past_the_end_alloca() {
Sanjay Patel69632442016-03-25 20:12:25 +000060; CHECK-LABEL: @both_past_the_end_alloca(
61; CHECK: [[M:%.*]] = alloca i32
62; CHECK-NEXT: [[N:%.*]] = alloca i32
63; CHECK-NEXT: [[X:%.*]] = getelementptr i32, i32* [[M]], i32 1
64; CHECK-NEXT: [[Y:%.*]] = getelementptr i32, i32* [[N]], i32 1
65; CHECK-NEXT: [[T:%.*]] = icmp eq i32* [[X]], [[Y]]
66; CHECK-NEXT: ret i1 [[T]]
67;
Dan Gohman9ee4bc12013-02-01 19:37:52 +000068 %m = alloca i32
69 %n = alloca i32
David Blaikie79e6c742015-02-27 19:29:02 +000070 %x = getelementptr i32, i32* %m, i32 1
71 %y = getelementptr i32, i32* %n, i32 1
Dan Gohman9ee4bc12013-02-01 19:37:52 +000072 %t = icmp eq i32* %x, %y
73 ret i1 %t
Dan Gohman9ee4bc12013-02-01 19:37:52 +000074 ; TODO: refine this
75}
76
77; Comparing past-the-end addresses of one alloca to the base address
78; of another. Can't fold this.
79
80define zeroext i1 @just_one_past_the_end_alloca() {
Sanjay Patel69632442016-03-25 20:12:25 +000081; CHECK-LABEL: @just_one_past_the_end_alloca(
82; CHECK: [[M:%.*]] = alloca i32
83; CHECK-NEXT: [[N:%.*]] = alloca i32
84; CHECK-NEXT: [[X:%.*]] = getelementptr i32, i32* [[M]], i32 1
85; CHECK-NEXT: [[T:%.*]] = icmp eq i32* [[X]], [[N]]
86; CHECK-NEXT: ret i1 [[T]]
87;
Dan Gohman9ee4bc12013-02-01 19:37:52 +000088 %m = alloca i32
89 %n = alloca i32
David Blaikie79e6c742015-02-27 19:29:02 +000090 %x = getelementptr i32, i32* %m, i32 1
Dan Gohman9ee4bc12013-02-01 19:37:52 +000091 %t = icmp eq i32* %x, %n
92 ret i1 %t
Dan Gohman9ee4bc12013-02-01 19:37:52 +000093}