diff --git a/lib/BitcastUtils.cpp b/lib/BitcastUtils.cpp index a3502539b..36a3652a1 100644 --- a/lib/BitcastUtils.cpp +++ b/lib/BitcastUtils.cpp @@ -1126,7 +1126,8 @@ void ExtractOffsetFromGEP(const DataLayout &DataLayout, IRBuilder<> &Builder, DynVal = nullptr; unsigned NbIdx = GEP->getNumOperands() - 1; - SmallerBitWidths = SizeInBits(DataLayout, GEP->getResultElementType()); + SmallerBitWidths = SizeInBits( + DataLayout, reworkUnsizedType(DataLayout, GEP->getResultElementType())); SmallVector Idxs; Type *PrevTy = GEP->getSourceElementType(); @@ -1151,7 +1152,9 @@ void ExtractOffsetFromGEP(const DataLayout &DataLayout, IRBuilder<> &Builder, CstVal += offset / SmallerBitWidths; } } else { - auto size = SizeInBits(DataLayout, NextTy) / SmallerBitWidths; + auto size = + SizeInBits(DataLayout, reworkUnsizedType(DataLayout, NextTy)) / + SmallerBitWidths; if (auto Cst = dyn_cast(Op)) { CstVal += Cst->getZExtValue() * size; } else { diff --git a/test/PointerCasts/issue-1192.ll b/test/PointerCasts/issue-1192.ll index f406977a7..1321fc3bd 100644 --- a/test/PointerCasts/issue-1192.ll +++ b/test/PointerCasts/issue-1192.ll @@ -1,4 +1,5 @@ ; RUN: clspv-opt %s -o %t.ll --passes=replace-pointer-bitcast +; RUN: FileCheck %s < %t.ll ; CHECK: [[alloca:%[^ ]+]] = alloca [65 x i32], align 4 ; CHECK: [[gep:%[^ ]+]] = getelementptr [65 x i32], ptr [[alloca]], i32 0 diff --git a/test/PointerCasts/issue-1221.ll b/test/PointerCasts/issue-1221.ll new file mode 100644 index 000000000..6984e1113 --- /dev/null +++ b/test/PointerCasts/issue-1221.ll @@ -0,0 +1,18 @@ +; RUN: clspv-opt %s -o %t.ll --passes=replace-pointer-bitcast +; RUN: FileCheck %s < %t.ll + +; CHECK: [[mul:%[^ ]+]] = mul i32 %i, 68 +; CHECK: [[gep:%[^ ]+]] = getelementptr i8, ptr addrspace(1) %source, i32 [[mul]] +; CHECK: load i8, ptr addrspace(1) [[gep]], align 1 + +target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" +target triple = "spir-unknown-unknown" + +%struct.pw = type { i32, [64 x i8] } + +define spir_kernel void @foo(ptr addrspace(1) %source, i32 %i) { +entry: + %gep = getelementptr inbounds { [0 x %struct.pw] }, ptr addrspace(1) %source, i32 %i + %load = load i8, ptr addrspace(1) %gep, align 1 + ret void +}