[SDAG] fix miscompile from merging stores of different sizes
authorSanjay Patel <spatel@rotateright.com>
Wed, 9 Jun 2021 13:44:58 +0000 (09:44 -0400)
committerSanjay Patel <spatel@rotateright.com>
Wed, 9 Jun 2021 13:51:39 +0000 (09:51 -0400)
commitdd763ac79196b3d3bc0370b9dbd35e0c083e52a4
treecaaa06ab366b5390d9f126f59e0481cde80db48f
parent206a66de5902b2b6dc0c62c4a25526d7e7f24186
[SDAG] fix miscompile from merging stores of different sizes

As shown in:
https://llvm.org/PR50623
...and the similar tests here, we were not accounting for
store merging of different sizes that do not cover the
entire range of the wide value to be stored.

This is the easy fix: just make sure that all of the
original stores are the same size, so when we calculate
the wide width, it's a simple N * M check.

This still allows all of the motivating optimizations from:
D86420 / 54a5dd485c4d
D87112 / 7a06b166b1af

We could enhance this code to track individual bytes and
allow merging multiple sizes.
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/X86/stores-merging.ll