xref: /llvm-project/llvm/test/Transforms/InstSimplify/past-the-end.ll (revision 10f315dc9c96ec2413881ab55a285e35d80def88)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -passes=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() {
13; CHECK-LABEL: @no_offsets(
14; CHECK-NEXT:    ret i1 false
15;
16  %t = icmp eq ptr @opte_a, @opte_b
17  ret i1 %t
18}
19
20; Comparing past-the-end addresses of two distinct globals. Never equal.
21
22define zeroext i1 @both_past_the_end() {
23; CHECK-LABEL: @both_past_the_end(
24; CHECK-NEXT:    [[T:%.*]] = icmp eq ptr getelementptr inbounds nuw (i8, ptr @opte_a, i32 4), getelementptr inbounds nuw (i8, ptr @opte_b, i32 4)
25; CHECK-NEXT:    ret i1 [[T]]
26;
27  %x = getelementptr i32, ptr @opte_a, i32 1
28  %y = getelementptr i32, ptr @opte_b, i32 1
29  %t = icmp eq ptr %x, %y
30  ret i1 %t
31  ; TODO: refine this
32}
33
34; Comparing past-the-end addresses of one global to the base address
35; of another. Can't fold this.
36
37define zeroext i1 @just_one_past_the_end() {
38; CHECK-LABEL: @just_one_past_the_end(
39; CHECK-NEXT:    [[T:%.*]] = icmp eq ptr getelementptr inbounds nuw (i8, ptr @opte_a, i32 4), @opte_b
40; CHECK-NEXT:    ret i1 [[T]]
41;
42  %x = getelementptr i32, ptr @opte_a, i32 1
43  %t = icmp eq ptr %x, @opte_b
44  ret i1 %t
45}
46
47; Comparing base addresses of two distinct allocas. Never equal.
48
49define zeroext i1 @no_alloca_offsets() {
50; CHECK-LABEL: @no_alloca_offsets(
51; CHECK-NEXT:    ret i1 false
52;
53  %m = alloca i32
54  %n = alloca i32
55  %t = icmp eq ptr %m, %n
56  ret i1 %t
57}
58
59; Comparing past-the-end addresses of two distinct allocas. Never equal.
60
61define zeroext i1 @both_past_the_end_alloca() {
62; CHECK-LABEL: @both_past_the_end_alloca(
63; CHECK-NEXT:    ret i1 false
64;
65  %m = alloca i32
66  %n = alloca i32
67  %x = getelementptr i32, ptr %m, i32 1
68  %y = getelementptr i32, ptr %n, i32 1
69  %t = icmp eq ptr %x, %y
70  ret i1 %t
71}
72
73; Comparing past-the-end addresses of one alloca to the base address
74; of another. Can't fold this.
75
76define zeroext i1 @just_one_past_the_end_alloca() {
77; CHECK-LABEL: @just_one_past_the_end_alloca(
78; CHECK-NEXT:    [[M:%.*]] = alloca i32, align 4
79; CHECK-NEXT:    [[N:%.*]] = alloca i32, align 4
80; CHECK-NEXT:    [[X:%.*]] = getelementptr i32, ptr [[M]], i32 1
81; CHECK-NEXT:    [[T:%.*]] = icmp eq ptr [[X]], [[N]]
82; CHECK-NEXT:    ret i1 [[T]]
83;
84  %m = alloca i32
85  %n = alloca i32
86  %x = getelementptr i32, ptr %m, i32 1
87  %t = icmp eq ptr %x, %n
88  ret i1 %t
89}
90