Skip to content

Commit

Permalink
SPIR-V type for i8 always aliases the type for i32
Browse files Browse the repository at this point in the history
This is incrementally better than what we have now, but I suspect
we should have remapped the types earlier in the flow, and we should
never see the i8 at this point.

Fixes google#15
  • Loading branch information
dneto0 committed Aug 26, 2017
1 parent fb9a797 commit 391aeb1
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/SPIRVProducerPass.cpp
Expand Up @@ -1642,8 +1642,27 @@ void SPIRVProducerPass::GenerateSPIRVTypes(const DataLayout &DL) {
SPIRVInstList.push_back(Inst);
} else {
// i8 is added to TypeMap as i32.
// No matter what LLVM type is requested first, always alias the
// second one's SPIR-V type to be the same as the one we generated
// first.
int aliasToWidth = 0;
if (BitWidth == 8) {
aliasToWidth = 32;
BitWidth = 32;
} else if (BitWidth == 32) {
aliasToWidth = 8;
}
if (aliasToWidth) {
Type* otherType = Type::getIntNTy(Ty->getContext(), aliasToWidth);
auto where = TypeMap.find(otherType);
if (where == TypeMap.end()) {
// Go ahead and make it, but also map the other type to it.
TypeMap[otherType] = nextID;
} else {
// Alias this SPIR-V type the existing type.
TypeMap[Ty] = where->second;
break;
}
}

SPIRVOperand *Ops[2] = {
Expand Down
21 changes: 21 additions & 0 deletions test/char4_issue15_a.cl
@@ -0,0 +1,21 @@
// Test for https://github.com/google/clspv/issues/15
// Use of <4 x 18> was generating a duplicate of OpTypeInt 32 0.

// In this example, the uint is mentioned before the char4.
kernel void dup(global uint* A, global char4 *B) {}

// RUN: clspv %s -S -o %t.spvasm
// RUN: FileCheck %s < %t.spvasm
// RUN: clspv %s -o %t.spv
// RUN: spirv-dis -o %t2.spvasm %t.spv
// RUN: FileCheck %s < %t2.spvasm
// RUN: spirv-val --target-env vulkan1.0 %t.spv


// CHECK: [[uint:%[_a-zA-Z0-9]+]] = OpTypeInt 32 0
// CHECK-NOT: OpTypeInt 32 0

// Ensure both buffer types use the same underlying i32
// CHECK-DAG: OpTypeRuntimeArray [[uint]]
// CHECK-DAG: OpTypeRuntimeArray [[uint]]

21 changes: 21 additions & 0 deletions test/char4_issue15_b.cl
@@ -0,0 +1,21 @@
// Test for https://github.com/google/clspv/issues/15
// Use of <4 x 18> was generating a duplicate of OpTypeInt 32 0.

// In this example, the char4 is mentioned before the uint.
kernel void dup(global char4* A, global uint *B) {}

// RUN: clspv %s -S -o %t.spvasm
// RUN: FileCheck %s < %t.spvasm
// RUN: clspv %s -o %t.spv
// RUN: spirv-dis -o %t2.spvasm %t.spv
// RUN: FileCheck %s < %t2.spvasm
// RUN: spirv-val --target-env vulkan1.0 %t.spv


// CHECK: [[uint:%[_a-zA-Z0-9]+]] = OpTypeInt 32 0
// CHECK-NOT: OpTypeInt 32 0

// Ensure both buffer types use the same underlying i32
// CHECK-DAG: OpTypeRuntimeArray [[uint]]
// CHECK-DAG: OpTypeRuntimeArray [[uint]]

0 comments on commit 391aeb1

Please sign in to comment.