|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
| 2 | +; RUN: opt -instcombine -S -disable-i2p-p2i-opt < %s | FileCheck %s |
| 3 | + |
| 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" |
| 6 | + |
| 7 | +; convert ptrtoint [ phi[ inttoptr (ptrtoint (x) ) ] ---> ptrtoint (phi[x]) |
| 8 | + |
| 9 | +define i64 @func(i32** %X, i32** %Y, i1 %cond) { |
| 10 | +; CHECK-LABEL: @func( |
| 11 | +; CHECK-NEXT: br i1 [[COND:%.*]], label [[BB1:%.*]], label [[BB2:%.*]] |
| 12 | +; CHECK: bb1: |
| 13 | +; CHECK-NEXT: br label [[EXIT:%.*]] |
| 14 | +; CHECK: bb2: |
| 15 | +; CHECK-NEXT: br label [[EXIT]] |
| 16 | +; CHECK: 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]] |
| 20 | +; |
| 21 | + br i1 %cond, label %bb1, label %bb2 |
| 22 | + |
| 23 | +bb1: |
| 24 | + %X.i = ptrtoint i32** %X to i64 |
| 25 | + %X.p = inttoptr i64 %X.i to i32* |
| 26 | + br label %exit |
| 27 | + |
| 28 | +bb2: |
| 29 | + %Y.i = ptrtoint i32** %Y to i64 |
| 30 | + %Y.p = inttoptr i64 %Y.i to i32* |
| 31 | + br label %exit |
| 32 | + |
| 33 | +exit: |
| 34 | + %phi = phi i32* [%X.p, %bb1], [%Y.p, %bb2] |
| 35 | + %X.p.i = ptrtoint i32* %phi to i64 |
| 36 | + ret i64 %X.p.i |
| 37 | +} |
| 38 | + |
| 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:%.*]] |
| 42 | +; CHECK: bb1: |
| 43 | +; CHECK-NEXT: br label [[EXIT]] |
| 44 | +; CHECK: 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]] |
| 48 | +; |
| 49 | + %Y.p = bitcast i32** %Y to i32* |
| 50 | + br i1 %cond, label %bb1, label %exit |
| 51 | + |
| 52 | +bb1: |
| 53 | + %X.i = ptrtoint i32** %X to i64 |
| 54 | + %X.p = inttoptr i64 %X.i to i32* |
| 55 | + br label %exit |
| 56 | + |
| 57 | +exit: |
| 58 | + %phi = phi i32* [%X.p, %bb1], [%Y.p, %0] |
| 59 | + %X.p.i = ptrtoint i32* %phi to i64 |
| 60 | + ret i64 %X.p.i |
| 61 | +} |
| 62 | + |
| 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:%.*]] |
| 67 | +; CHECK: bb1: |
| 68 | +; CHECK-NEXT: [[TMP1:%.*]] = bitcast i16** [[X:%.*]] to i32* |
| 69 | +; CHECK-NEXT: br label [[EXIT]] |
| 70 | +; CHECK: 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]] |
| 74 | +; |
| 75 | + %Y.p = bitcast i32** %Y to i32* |
| 76 | + br i1 %cond, label %bb1, label %exit |
| 77 | + |
| 78 | +bb1: |
| 79 | + %X.i = ptrtoint i16** %X to i64 |
| 80 | + %X.p = inttoptr i64 %X.i to i32* |
| 81 | + br label %exit |
| 82 | + |
| 83 | +exit: |
| 84 | + %phi = phi i32* [%X.p, %bb1], [%Y.p, %0] |
| 85 | + %X.p.i = ptrtoint i32* %phi to i64 |
| 86 | + ret i64 %X.p.i |
| 87 | +} |
| 88 | + |
| 89 | +; Negative test - Wrong Integer type |
| 90 | + |
| 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:%.*]] |
| 95 | +; CHECK: bb1: |
| 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]] |
| 100 | +; CHECK: 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]] |
| 104 | +; |
| 105 | + %Y.p = bitcast i32** %Y to i32* |
| 106 | + br i1 %cond, label %bb1, label %exit |
| 107 | + |
| 108 | +bb1: |
| 109 | + %X.i = ptrtoint i32** %X to i32 |
| 110 | + %X.p = inttoptr i32 %X.i to i32* |
| 111 | + br label %exit |
| 112 | + |
| 113 | +exit: |
| 114 | + %phi = phi i32* [%X.p, %bb1], [%Y.p, %0] |
| 115 | + %X.p.i = ptrtoint i32* %phi to i64 |
| 116 | + ret i64 %X.p.i |
| 117 | +} |
| 118 | + |
| 119 | +; Negative test - phi not used in ptrtoint |
| 120 | + |
| 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:%.*]] |
| 125 | +; CHECK: bb1: |
| 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]] |
| 130 | +; CHECK: exit: |
| 131 | +; CHECK-NEXT: [[PHI:%.*]] = phi i32* [ [[X_P]], [[BB1]] ], [ [[Y_P]], [[TMP0:%.*]] ] |
| 132 | +; CHECK-NEXT: ret i32* [[PHI]] |
| 133 | +; |
| 134 | + %Y.p = bitcast i32** %Y to i32* |
| 135 | + br i1 %cond, label %bb1, label %exit |
| 136 | + |
| 137 | +bb1: |
| 138 | + %X.i = ptrtoint i32** %X to i32 |
| 139 | + %X.p = inttoptr i32 %X.i to i32* |
| 140 | + br label %exit |
| 141 | + |
| 142 | +exit: |
| 143 | + %phi = phi i32* [%X.p, %bb1], [%Y.p, %0] |
| 144 | + ret i32* %phi |
| 145 | +} |
| 146 | + |
| 147 | +; Negative test - Pointers in different address spaces |
| 148 | + |
| 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:%.*]] |
| 153 | +; CHECK: bb1: |
| 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]] |
| 158 | +; CHECK: 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]] |
| 162 | +; |
| 163 | + %Y.p = bitcast i32** %Y to i32* |
| 164 | + br i1 %cond, label %bb1, label %exit |
| 165 | + |
| 166 | +bb1: |
| 167 | + %X.i = ptrtoint i16 addrspace(2)* %X to i64 |
| 168 | + %X.p = inttoptr i64 %X.i to i32* |
| 169 | + br label %exit |
| 170 | + |
| 171 | +exit: |
| 172 | + %phi = phi i32* [%X.p, %bb1], [%Y.p, %0] |
| 173 | + %X.p.i = ptrtoint i32* %phi to i64 |
| 174 | + ret i64 %X.p.i |
| 175 | +} |
0 commit comments