Skip to content

Commit

Permalink
fix types use in several calls to CreateAdd (#1175)
Browse files Browse the repository at this point in the history
Fix #1174
  • Loading branch information
rjodinchr authored Aug 14, 2023
1 parent 15abfc8 commit 93ea850
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/BitcastUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,8 +1193,8 @@ GetIdxsForTyFromOffset(const DataLayout &DataLayout, IRBuilder<> &Builder,
CreateDiv(Builder, NewSmallerBitWidths / SmallerBitWidths, DynVal);
}
if (CstVal != 0) {
DynVal = Builder.CreateAdd(
DynVal, ConstantInt::get(Builder.getInt32Ty(), CstVal));
DynVal = Builder.CreateAdd(DynVal,
ConstantInt::get(DynVal->getType(), CstVal));
}
for (unsigned i = startIdx; i < TyBitWidths.size(); i++) {
size_t size = TyBitWidths[i] / NewSmallerBitWidths;
Expand Down
3 changes: 2 additions & 1 deletion lib/ReplacePointerBitcastPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,8 @@ clspv::ReplacePointerBitcastPass::run(Module &M, ModuleAnalysisManager &) {
if (DynVal == nullptr) {
OrgGEPIdx = Builder.getInt32(CstVal);
} else if (CstVal != 0) {
OrgGEPIdx = Builder.CreateAdd(Builder.getInt32(CstVal), DynVal);
OrgGEPIdx = Builder.CreateAdd(
ConstantInt::get(DynVal->getType(), CstVal), DynVal);
}

DstTy = GEP->getResultElementType();
Expand Down
25 changes: 25 additions & 0 deletions test/PointerCasts/issue-1174.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: clspv %s -o %t.spv -arch=spir64
// RUN: spirv-dis %t.spv -o %t.spvasm
// RUN: spirv-val %t.spv --target-env spv1.0

#define ElementCount 100

struct E {
int i;
long l;
};

struct S {
struct E e[ElementCount];
};

kernel void Kernel(global struct S *s)
{

for (int i = 0; i < ElementCount; ++i) {
global struct E *e = &s->e[i];
e->l += e->i;
}

s->e[0].i = s->e[1].i;
}

0 comments on commit 93ea850

Please sign in to comment.