ispc/ispc — Issue #121: prefetch crashes compiler in AVX mode
Author: rundbep
Created: 2011-11-21 14:29:59+00:00
State: open

Adding a prefetch statement to the code crashes ISPC when compiling to AVX target.

To reproduce modify the "simple.ispc" in the "simple" example as below.

export void simple(uniform float vin[], uniform float vout[],
uniform int count) {
// Compute the result for 'programCount' values in parallel
for (uniform int i = 0; i < count; i += programCount) {
int index = i + programIndex;
// Load the appropriate input value for this program instance.
float v = vin[index];

// Do an arbitrary little computation, but at least make the
// computation dependent on the value being processed
if (v < 3.)
v = v * v;
else
v = sqrt(v);

// And write the result to the output array.
vout[index] = v;

__// Add some prefetches__
__prefetch_l1(vin[i + 32]);__
__prefetch_l1(vout[i + 32]);__
}
}

Compiling to a AVX target will result in the following error:

LLVM ERROR: Cannot select: 0x7fa3240ab010: ch = Prefetch 0x7fa3240ac610, 0x7fa3240ac410, 0x7fa3240abc10, 0x7fa3240b1b10, 0x7fa3240ac310 [ID=42]
0x7fa3240ac410: i64 = add 0x7fa3240ace10, 0x7fa3240acc10 [ORD=32] [ID=39]
0x7fa3240ace10: i64,ch = CopyFromReg 0x7fa324b0f6a8, 0x7fa3240b1910 [ORD=23] [ID=21]
0x7fa3240b1910: i64 = Register %vreg27 [ORD=23] [ID=3]
0x7fa3240acc10: i64 = shl 0x7fa3240b1210, 0x7fa3240b5f10 [ORD=30] [ID=37]
0x7fa3240b1210: i64 = sign_extend 0x7fa3240b1e10 [ORD=29] [ID=34]
0x7fa3240b1e10: i32 = add 0x7fa3240ac810, 0x7fa3240acb10 [ORD=28] [ID=29]
0x7fa3240ac810: i32,ch = CopyFromReg 0x7fa324b0f6a8, 0x7fa3240b1610 [ORD=28] [ID=23]
0x7fa3240b1610: i32 = Register %vreg2 [ORD=28] [ID=6]
0x7fa3240acb10: i32 = Constant<32> [ORD=28] [ID=7]
0x7fa3240b5f10: i8 = Constant<2> [ID=19]
0x7fa3240abc10: i32 = Constant<0> [ID=9]
0x7fa3240b1b10: i32 = Constant<3> [ID=10]
0x7fa3240ac310: i32 = Constant<1> [ID=11]

Additional comment:
A related minor gripe is that the __prefetch_XX__ functions does not accept unsigned integer types. This is not a bug per se, but it would be convenient to allow prefetching of data from unsigned int arrays.