1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -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 ; convert ptrtoint [ phi[ inttoptr (ptrtoint (x) ) ] ---> ptrtoint (phi[x])
9 define i64 @func(i32** %X, i32** %Y, i1 %cond) {
11 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
13 ; CHECK-NEXT: br label [[EXIT:%.*]]
15 ; CHECK-NEXT: br label [[EXIT]]
17 ; CHECK-NEXT: [[PHI_IN_IN:%.*]] = phi i32** [ [[X:%.*]], [[BB1]] ], [ [[Y:%.*]], [[BB2]] ]
18 ; CHECK-NEXT: [[PHI_IN:%.*]] = ptrtoint i32** [[PHI_IN_IN]] to i64
19 ; CHECK-NEXT: ret i64 [[PHI_IN]]
21 br i1 %cond, label %bb1, label %bb2
24 %X.i = ptrtoint i32** %X to i64
25 %X.p = inttoptr i64 %X.i to i32*
29 %Y.i = ptrtoint i32** %Y to i64
30 %Y.p = inttoptr i64 %Y.i to i32*
34 %phi = phi i32* [%X.p, %bb1], [%Y.p, %bb2]
35 %X.p.i = ptrtoint i32* %phi to i64
39 define i64 @func_single_operand(i32** %X, i32** %Y, i1 %cond) {
40 ; CHECK-LABEL: @func_single_operand(
41 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[BB1:%.*]], label [[EXIT:%.*]]
43 ; CHECK-NEXT: br label [[EXIT]]
45 ; CHECK-NEXT: [[PHI_IN:%.*]] = phi i32** [ [[X:%.*]], [[BB1]] ], [ [[Y:%.*]], [[TMP0:%.*]] ]
46 ; CHECK-NEXT: [[X_P_I:%.*]] = ptrtoint i32** [[PHI_IN]] to i64
47 ; CHECK-NEXT: ret i64 [[X_P_I]]
49 %Y.p = bitcast i32** %Y to i32*
50 br i1 %cond, label %bb1, label %exit
53 %X.i = ptrtoint i32** %X to i64
54 %X.p = inttoptr i64 %X.i to i32*
58 %phi = phi i32* [%X.p, %bb1], [%Y.p, %0]
59 %X.p.i = ptrtoint i32* %phi to i64
63 define i64 @func_pointer_different_types(i16** %X, i32** %Y, i1 %cond) {
64 ; CHECK-LABEL: @func_pointer_different_types(
65 ; CHECK-NEXT: [[Y_P:%.*]] = bitcast i32** [[Y:%.*]] to i32*
66 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[BB1:%.*]], label [[EXIT:%.*]]
68 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast i16** [[X:%.*]] to i32*
69 ; CHECK-NEXT: br label [[EXIT]]
71 ; CHECK-NEXT: [[PHI:%.*]] = phi i32* [ [[TMP1]], [[BB1]] ], [ [[Y_P]], [[TMP0:%.*]] ]
72 ; CHECK-NEXT: [[X_P_I:%.*]] = ptrtoint i32* [[PHI]] to i64
73 ; CHECK-NEXT: ret i64 [[X_P_I]]
75 %Y.p = bitcast i32** %Y to i32*
76 br i1 %cond, label %bb1, label %exit
79 %X.i = ptrtoint i16** %X to i64
80 %X.p = inttoptr i64 %X.i to i32*
84 %phi = phi i32* [%X.p, %bb1], [%Y.p, %0]
85 %X.p.i = ptrtoint i32* %phi to i64
89 ; Negative test - Wrong Integer type
91 define i64 @func_integer_type_too_small(i32** %X, i32** %Y, i1 %cond) {
92 ; CHECK-LABEL: @func_integer_type_too_small(
93 ; CHECK-NEXT: [[Y_P:%.*]] = bitcast i32** [[Y:%.*]] to i32*
94 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[BB1:%.*]], label [[EXIT:%.*]]
96 ; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint i32** [[X:%.*]] to i64
97 ; CHECK-NEXT: [[TMP2:%.*]] = and i64 [[TMP1]], 4294967295
98 ; CHECK-NEXT: [[X_P:%.*]] = inttoptr i64 [[TMP2]] to i32*
99 ; CHECK-NEXT: br label [[EXIT]]
101 ; CHECK-NEXT: [[PHI:%.*]] = phi i32* [ [[X_P]], [[BB1]] ], [ [[Y_P]], [[TMP0:%.*]] ]
102 ; CHECK-NEXT: [[X_P_I:%.*]] = ptrtoint i32* [[PHI]] to i64
103 ; CHECK-NEXT: ret i64 [[X_P_I]]
105 %Y.p = bitcast i32** %Y to i32*
106 br i1 %cond, label %bb1, label %exit
109 %X.i = ptrtoint i32** %X to i32
110 %X.p = inttoptr i32 %X.i to i32*
114 %phi = phi i32* [%X.p, %bb1], [%Y.p, %0]
115 %X.p.i = ptrtoint i32* %phi to i64
119 ; Negative test - phi not used in ptrtoint
121 define i32* @func_phi_not_use_in_ptr2int(i32** %X, i32** %Y, i1 %cond) {
122 ; CHECK-LABEL: @func_phi_not_use_in_ptr2int(
123 ; CHECK-NEXT: [[Y_P:%.*]] = bitcast i32** [[Y:%.*]] to i32*
124 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[BB1:%.*]], label [[EXIT:%.*]]
126 ; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint i32** [[X:%.*]] to i64
127 ; CHECK-NEXT: [[TMP2:%.*]] = and i64 [[TMP1]], 4294967295
128 ; CHECK-NEXT: [[X_P:%.*]] = inttoptr i64 [[TMP2]] to i32*
129 ; CHECK-NEXT: br label [[EXIT]]
131 ; CHECK-NEXT: [[PHI:%.*]] = phi i32* [ [[X_P]], [[BB1]] ], [ [[Y_P]], [[TMP0:%.*]] ]
132 ; CHECK-NEXT: ret i32* [[PHI]]
134 %Y.p = bitcast i32** %Y to i32*
135 br i1 %cond, label %bb1, label %exit
138 %X.i = ptrtoint i32** %X to i32
139 %X.p = inttoptr i32 %X.i to i32*
143 %phi = phi i32* [%X.p, %bb1], [%Y.p, %0]
147 ; Negative test - Pointers in different address spaces
149 define i64 @func_ptr_different_addrspace(i16 addrspace(2)* %X, i32** %Y, i1 %cond) {
150 ; CHECK-LABEL: @func_ptr_different_addrspace(
151 ; CHECK-NEXT: [[Y_P:%.*]] = bitcast i32** [[Y:%.*]] to i32*
152 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[BB1:%.*]], label [[EXIT:%.*]]
154 ; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint i16 addrspace(2)* [[X:%.*]] to i32
155 ; CHECK-NEXT: [[X_I:%.*]] = zext i32 [[TMP1]] to i64
156 ; CHECK-NEXT: [[X_P:%.*]] = inttoptr i64 [[X_I]] to i32*
157 ; CHECK-NEXT: br label [[EXIT]]
159 ; CHECK-NEXT: [[PHI:%.*]] = phi i32* [ [[X_P]], [[BB1]] ], [ [[Y_P]], [[TMP0:%.*]] ]
160 ; CHECK-NEXT: [[X_P_I:%.*]] = ptrtoint i32* [[PHI]] to i64
161 ; CHECK-NEXT: ret i64 [[X_P_I]]
163 %Y.p = bitcast i32** %Y to i32*
164 br i1 %cond, label %bb1, label %exit
167 %X.i = ptrtoint i16 addrspace(2)* %X to i64
168 %X.p = inttoptr i64 %X.i to i32*
172 %phi = phi i32* [%X.p, %bb1], [%Y.p, %0]
173 %X.p.i = ptrtoint i32* %phi to i64