Instcombine, struct w/ padding & aggregate loads/stores as scalars

I believe the faulty transform here is InstCombine converting a memcpy into an integer load/store pair: llvm-project/InstCombineCalls.cpp at d93eb3a942d83029e4cc68354e3e441db957bf1b · llvm/llvm-project · GitHub

This transform is “well known” to be incorrect, because it will propagate poison in individual bytes across the whole value. It sounds like you’re the lucky person to hit this in a real-world miscompile.

Nominally, the solution to this is simple, which is to convert the memcpy into a <8 x i8> style load/store instead, which preserves poison. The reality is that this does not optimize well in practice.

An alternative is the introduction of a byte type ([RFC] Introducing a byte type to LLVM), which solves this problem plus questions around provenance.

cc @nlopes

1 Like