Skip to content

Commit

Permalink
fix GetIdxsForTyFromOffset with private and private like addrspace (#…
Browse files Browse the repository at this point in the history
…1199)

Private addrspace needs to have a zero as first indice.
But when SrcTy == DstTy, we are in another scenario coming from
pointer cast rework, where the first indice may not be zero.

Fix #1196
  • Loading branch information
rjodinchr authored Aug 24, 2023
1 parent 9ff7835 commit 4cd74f9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/BitcastUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,10 +1158,11 @@ GetIdxsForTyFromOffset(const DataLayout &DataLayout, IRBuilder<> &Builder,

// For private pointer, the first Idx needs to be '0'
unsigned startIdx = 0;
if (AddrSpace == clspv::AddressSpace::Private ||
AddrSpace == clspv::AddressSpace::ModuleScopePrivate ||
AddrSpace == clspv::AddressSpace::PushConstant ||
AddrSpace == clspv::AddressSpace::Input) {
if ((AddrSpace == clspv::AddressSpace::Private ||
AddrSpace == clspv::AddressSpace::ModuleScopePrivate ||
AddrSpace == clspv::AddressSpace::PushConstant ||
AddrSpace == clspv::AddressSpace::Input) &&
SrcTy != DstTy) {
Idxs.push_back(ConstantInt::get(Builder.getInt32Ty(), 0));
startIdx = 1;
}
Expand Down
14 changes: 14 additions & 0 deletions test/PointerCasts/issue-1196.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; RUN: clspv-opt %s -o %t.ll --passes=replace-pointer-bitcast
; RUN: FileCheck %s < %t.ll

; CHECK: [[alloca:%[^ ]+]] = alloca [196 x i8], align 1
; CHECK: [[gep:%[^ ]+]] = getelementptr [196 x i8], ptr [[alloca]], i32 0, i32 64
; CHECK: store i8 %val, ptr [[gep]], align 1

define dso_local spir_kernel void @kernel(i8 %val) {
entry:
%alloca = alloca { [8 x i64], [16 x i64], i32 }, align 16
%gep = getelementptr { [8 x i64], [16 x i64], i32 }, ptr %alloca, i32 0, i32 1, i32 0
store i8 %val, ptr %gep, align 1
ret void
}

0 comments on commit 4cd74f9

Please sign in to comment.