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 ; convert ptrtoint [ phi[ inttoptr (ptrtoint (x) ) ] ---> ptrtoint (phi[x])
9 define i64 @func(ptr %X, ptr %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:%.*]] = phi ptr [ [[X:%.*]], [[BB1]] ], [ [[Y:%.*]], [[BB2]] ]
18 ; CHECK-NEXT: [[X_P_I:%.*]] = ptrtoint ptr [[PHI_IN]] to i64
19 ; CHECK-NEXT: ret i64 [[X_P_I]]
21 br i1 %cond, label %bb1, label %bb2
24 %X.i = ptrtoint ptr %X to i64
25 %X.p = inttoptr i64 %X.i to ptr
29 %Y.i = ptrtoint ptr %Y to i64
30 %Y.p = inttoptr i64 %Y.i to ptr
34 %phi = phi ptr [%X.p, %bb1], [%Y.p, %bb2]
35 %X.p.i = ptrtoint ptr %phi to i64
39 define i64 @func_single_operand(ptr %X, ptr %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:%.*]] = phi ptr [ [[X:%.*]], [[BB1]] ], [ [[Y:%.*]], [[TMP0:%.*]] ]
46 ; CHECK-NEXT: [[X_P_I:%.*]] = ptrtoint ptr [[PHI]] to i64
47 ; CHECK-NEXT: ret i64 [[X_P_I]]
49 br i1 %cond, label %bb1, label %exit
52 %X.i = ptrtoint ptr %X to i64
53 %X.p = inttoptr i64 %X.i to ptr
57 %phi = phi ptr [%X.p, %bb1], [%Y, %0]
58 %X.p.i = ptrtoint ptr %phi to i64
62 define i64 @func_pointer_different_types(ptr %X, ptr %Y, i1 %cond) {
63 ; CHECK-LABEL: @func_pointer_different_types(
64 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[BB1:%.*]], label [[EXIT:%.*]]
66 ; CHECK-NEXT: br label [[EXIT]]
68 ; CHECK-NEXT: [[PHI:%.*]] = phi ptr [ [[X:%.*]], [[BB1]] ], [ [[Y:%.*]], [[TMP0:%.*]] ]
69 ; CHECK-NEXT: [[X_P_I:%.*]] = ptrtoint ptr [[PHI]] to i64
70 ; CHECK-NEXT: ret i64 [[X_P_I]]
72 br i1 %cond, label %bb1, label %exit
75 %X.i = ptrtoint ptr %X to i64
76 %X.p = inttoptr i64 %X.i to ptr
80 %phi = phi ptr [%X.p, %bb1], [%Y, %0]
81 %X.p.i = ptrtoint ptr %phi to i64
85 ; Negative test - Wrong Integer type
87 define i64 @func_integer_type_too_small(ptr %X, ptr %Y, i1 %cond) {
88 ; CHECK-LABEL: @func_integer_type_too_small(
89 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[BB1:%.*]], label [[EXIT:%.*]]
91 ; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[X:%.*]] to i64
92 ; CHECK-NEXT: [[TMP2:%.*]] = and i64 [[TMP1]], 4294967295
93 ; CHECK-NEXT: [[X_P:%.*]] = inttoptr i64 [[TMP2]] to ptr
94 ; CHECK-NEXT: br label [[EXIT]]
96 ; CHECK-NEXT: [[PHI:%.*]] = phi ptr [ [[X_P]], [[BB1]] ], [ [[Y:%.*]], [[TMP0:%.*]] ]
97 ; CHECK-NEXT: [[X_P_I:%.*]] = ptrtoint ptr [[PHI]] to i64
98 ; CHECK-NEXT: ret i64 [[X_P_I]]
100 br i1 %cond, label %bb1, label %exit
103 %X.i = ptrtoint ptr %X to i32
104 %X.p = inttoptr i32 %X.i to ptr
108 %phi = phi ptr [%X.p, %bb1], [%Y, %0]
109 %X.p.i = ptrtoint ptr %phi to i64
113 ; Negative test - phi not used in ptrtoint
115 define ptr @func_phi_not_use_in_ptr2int(ptr %X, ptr %Y, i1 %cond) {
116 ; CHECK-LABEL: @func_phi_not_use_in_ptr2int(
117 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[BB1:%.*]], label [[EXIT:%.*]]
119 ; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[X:%.*]] to i64
120 ; CHECK-NEXT: [[TMP2:%.*]] = and i64 [[TMP1]], 4294967295
121 ; CHECK-NEXT: [[X_P:%.*]] = inttoptr i64 [[TMP2]] to ptr
122 ; CHECK-NEXT: br label [[EXIT]]
124 ; CHECK-NEXT: [[PHI:%.*]] = phi ptr [ [[X_P]], [[BB1]] ], [ [[Y:%.*]], [[TMP0:%.*]] ]
125 ; CHECK-NEXT: ret ptr [[PHI]]
127 br i1 %cond, label %bb1, label %exit
130 %X.i = ptrtoint ptr %X to i32
131 %X.p = inttoptr i32 %X.i to ptr
135 %phi = phi ptr [%X.p, %bb1], [%Y, %0]
139 ; Negative test - Pointers in different address spaces
141 define i64 @func_ptr_different_addrspace(ptr addrspace(2) %X, ptr %Y, i1 %cond) {
142 ; CHECK-LABEL: @func_ptr_different_addrspace(
143 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[BB1:%.*]], label [[EXIT:%.*]]
145 ; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr addrspace(2) [[X:%.*]] to i32
146 ; CHECK-NEXT: [[X_I:%.*]] = zext i32 [[TMP1]] to i64
147 ; CHECK-NEXT: [[X_P:%.*]] = inttoptr i64 [[X_I]] to ptr
148 ; CHECK-NEXT: br label [[EXIT]]
150 ; CHECK-NEXT: [[PHI:%.*]] = phi ptr [ [[X_P]], [[BB1]] ], [ [[Y:%.*]], [[TMP0:%.*]] ]
151 ; CHECK-NEXT: [[X_P_I:%.*]] = ptrtoint ptr [[PHI]] to i64
152 ; CHECK-NEXT: ret i64 [[X_P_I]]
154 br i1 %cond, label %bb1, label %exit
157 %X.i = ptrtoint ptr addrspace(2) %X to i64
158 %X.p = inttoptr i64 %X.i to ptr
162 %phi = phi ptr [%X.p, %bb1], [%Y, %0]
163 %X.p.i = ptrtoint ptr %phi to i64