clspv icon indicating copy to clipboard operation
clspv copied to clipboard

Dynamic indexing of private arrays

Open ex-rzr opened this issue 7 years ago • 2 comments

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];
    }
}

ex-rzr avatar Jan 28 '18 08:01 ex-rzr

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.

dneto0 avatar Jun 01 '18 15:06 dneto0

Kernel 1 succeeds now, but kernel 2 still fails.

alan-baker avatar Feb 27 '19 14:02 alan-baker

Both of them pass

rjodinchr avatar Mar 29 '23 09:03 rjodinchr