Dynamic indexing of private arrays
Here are two test cases that I created by minimizing real kernels I tried to process using clspv:
kernel
void kernel1(
global int* xs,
int j
) {
int ys[3] = { 1, 2, 3 }; // FAIL
// clspv: .../clspv/lib/ReplaceLLVMIntrinsicsPass.cpp:180: bool {anonymous}::ReplaceLLVMIntrinsicsPass::replaceMemcpy(llvm::Module&): Assertion `isa<BitCastInst>(CI->getArgOperand(1))' failed.
// int ys[3] = { }; // OK
// int ys[3]; // OK
// int ys[3]; for (int i = 0; i < 3; i++) ys[i] = i + 1; // OK
ys[j] = 4;
xs[0] = ys[0];
xs[1] = ys[1];
xs[2] = ys[2];
}
kernel
void kernel2(
global int* xs
) {
int ys[3] = { 1, 2, 3 }; // FAIL
// clspv: .../clspv/lib/ReplaceLLVMIntrinsicsPass.cpp:180: bool {anonymous}::ReplaceLLVMIntrinsicsPass::replaceMemcpy(llvm::Module&): Assertion `isa<BitCastInst>(CI->getArgOperand(1))' failed.
// int ys[3] = { }; // FAIL
// int ys[3]; // FAIL
// int ys[3]; for (int i = 0; i < 3; i++) ys[i] = i + 1; // FAIL
// clspv: .../clspv/lib/ReplaceLLVMIntrinsicsPass.cpp:204: bool {anonymous}::ReplaceLLVMIntrinsicsPass::replaceMemcpy(llvm::Module&): Assertion `isa<ConstantInt>(CI->getArgOperand(2))' failed.
int k = 0;
for (int i = 0; i < 3; i++) {
if (xs[i] > 0) {
ys[k] = xs[i];
k++;
}
}
for (int i = 0; i < k; i++) {
xs[i] = ys[i];
}
}
I've recently fixed a somewhat similar problem in replace-pointer-bitcasts to handle arrays vs. scalars. But I've confirmed this issue still persists.
In the first example, the unhandled case looks like this:
call void @llvm.memcpy.p0i8.p2i8.i32(i8* nonnull %1, i8 addrspace(2)* bitcast ([3 x i32] addrspace(2)* @kernel1.ys to i8 addrspace(2)*), i32 12, i32 4, i1 false)
That second pointer argument is a constant-bitcast-expression. Clspv is expecting a Bitcast instruction (executed at runtime). The code needs to be generalized for the constant-data case.
Kernel 1 succeeds now, but kernel 2 still fails.
Both of them pass