ispc/ispc — Issue #186: memory coalescing not working with soa data layout
Author: mmp
Created: 2012-03-05 22:27:46+00:00
State: open
Labels: performance

If this program:

```
struct Point { float x, y, z; };

float x(soa<8> Point pts[]) {
return pts[programIndex+4].x;
}
```

is compiled with "--opt=disable-handle-pseudo-memory-ops", the output still has a gather:

```
%newgather132 = tail call <8 x i32> @__pseudo_gather_base_offsets64_32(i8* %base2void131, <8 x i64> , i32 1, <8 x i64> zeroinitializer, <8 x i32> %__mask), !filename !0, !first_line !1, !first_column !2, !last_line !1, !last_column !3
```

whereas it would be nice for this to be two 4-wide loads. What seems to be happening is that the constant offsets are landing in the variable offset field of pseudo_gather, such that the coalescing optimizations don't kick in.

If this line in opt.cpp:
```
optPM.add(CreateDetectGSBaseOffsetsPass());
```

is moved a bit further down, after other optimizations have been applied, coalescing works, but some of the short circuit tests fail. (For no obvious reason.) Another alternative would be to figure out what's going wrong in the creation of the pseudo_gather call, though just running existing optimizations and thus getting cleaner input to the gather/scatter base+offsets pass seems like it's in principle preferable.