1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=instcombine -S -disable-i2p-p2i-opt < %s | FileCheck %s
4 target datalayout = "e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64"
5 target triple = "x86_64-unknown-linux-gnu"
7 ; icmp (inttoptr (ptrtoint p1)), p2 --> icmp p1, p2.
9 define i1 @func(ptr %X, ptr %Y) {
11 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[Y:%.*]], [[X:%.*]]
12 ; CHECK-NEXT: ret i1 [[CMP]]
14 %i = ptrtoint ptr %X to i64
15 %p = inttoptr i64 %i to ptr
16 %cmp = icmp eq ptr %p, %Y
20 define <2 x i1> @func_vec(<2 x ptr> %X, <2 x ptr> %Y) {
21 ; CHECK-LABEL: @func_vec(
22 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x ptr> [[Y:%.*]], [[X:%.*]]
23 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
25 %i = ptrtoint <2 x ptr> %X to <2 x i64>
26 %p = inttoptr <2 x i64> %i to <2 x ptr>
27 %cmp = icmp eq <2 x ptr> %p, %Y
31 define <vscale x 2 x i1> @func_svec(<vscale x 2 x ptr> %X, <vscale x 2 x ptr> %Y) {
32 ; CHECK-LABEL: @func_svec(
33 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <vscale x 2 x ptr> [[Y:%.*]], [[X:%.*]]
34 ; CHECK-NEXT: ret <vscale x 2 x i1> [[CMP]]
36 %i = ptrtoint <vscale x 2 x ptr> %X to <vscale x 2 x i64>
37 %p = inttoptr <vscale x 2 x i64> %i to <vscale x 2 x ptr>
38 %cmp = icmp eq <vscale x 2 x ptr> %p, %Y
39 ret <vscale x 2 x i1> %cmp
42 define i1 @func_pointer_different_types(ptr %X, ptr %Y) {
43 ; CHECK-LABEL: @func_pointer_different_types(
44 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[Y:%.*]], [[X:%.*]]
45 ; CHECK-NEXT: ret i1 [[CMP]]
47 %i = ptrtoint ptr %X to i64
48 %p = inttoptr i64 %i to ptr
49 %cmp = icmp eq ptr %p, %Y
53 declare ptr @gen8ptr()
55 define i1 @func_commutative(ptr %X) {
56 ; CHECK-LABEL: @func_commutative(
57 ; CHECK-NEXT: [[Y:%.*]] = call ptr @gen8ptr()
58 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[Y]], [[X:%.*]]
59 ; CHECK-NEXT: ret i1 [[CMP]]
61 %Y = call ptr @gen8ptr() ; thwart complexity-based canonicalization
62 %i = ptrtoint ptr %X to i64
63 %p = inttoptr i64 %i to ptr
64 %cmp = icmp eq ptr %Y, %p
68 ; Negative test - Wrong Integer type.
70 define i1 @func_integer_type_too_small(ptr %X, ptr %Y) {
71 ; CHECK-LABEL: @func_integer_type_too_small(
72 ; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[X:%.*]] to i64
73 ; CHECK-NEXT: [[TMP2:%.*]] = and i64 [[TMP1]], 4294967295
74 ; CHECK-NEXT: [[P:%.*]] = inttoptr i64 [[TMP2]] to ptr
75 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[Y:%.*]], [[P]]
76 ; CHECK-NEXT: ret i1 [[CMP]]
78 %i = ptrtoint ptr %X to i32
79 %p = inttoptr i32 %i to ptr
80 %cmp = icmp eq ptr %Y, %p
84 ; Negative test - Pointers in different address space
86 define i1 @func_ptr_different_addrspace(ptr %X, ptr addrspace(3) %Y){
87 ; CHECK-LABEL: @func_ptr_different_addrspace(
88 ; CHECK-NEXT: [[I:%.*]] = ptrtoint ptr [[X:%.*]] to i64
89 ; CHECK-NEXT: [[P:%.*]] = inttoptr i64 [[I]] to ptr addrspace(3)
90 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr addrspace(3) [[Y:%.*]], [[P]]
91 ; CHECK-NEXT: ret i1 [[CMP]]
93 %i = ptrtoint ptr %X to i64
94 %p = inttoptr i64 %i to ptr addrspace(3)
95 %cmp = icmp eq ptr addrspace(3) %Y, %p
99 ; Negative test - Pointers in different address space
101 define i1 @func_ptr_different_addrspace1(ptr addrspace(2) %X, ptr %Y){
102 ; CHECK-LABEL: @func_ptr_different_addrspace1(
103 ; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr addrspace(2) [[X:%.*]] to i32
104 ; CHECK-NEXT: [[I:%.*]] = zext i32 [[TMP1]] to i64
105 ; CHECK-NEXT: [[P:%.*]] = inttoptr i64 [[I]] to ptr
106 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[Y:%.*]], [[P]]
107 ; CHECK-NEXT: ret i1 [[CMP]]
109 %i = ptrtoint ptr addrspace(2) %X to i64
110 %p = inttoptr i64 %i to ptr
111 %cmp = icmp eq ptr %Y, %p