[llvm] [DAGCombine] Fix multi-use miscompile in load combine (PR #81492)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 13 01:10:51 PST 2024
================
@@ -9245,6 +9252,14 @@ SDValue DAGCombiner::MatchLoadCombine(SDNode *N) {
if (!Allowed || !Fast)
return SDValue();
+ // calculatebyteProvider() allows multi-use for vector loads. Ensure that
+ // all uses are in vector element extracts that are part of the pattern.
+ for (LoadSDNode *L : Loads)
+ if (L->getMemoryVT().isVector())
+ for (auto It = L->use_begin(); It != L->use_end(); ++It)
+ if (It.getUse().getResNo() == 0 && !ExtractElements.contains(*It))
+ return SDValue();
+
----------------
nikic wrote:
Gah, I've been looking everywhere for a function that does this, and couldn't find it. After looking at a few other uses of that function, it seems like we actually have quite a few folds that are happy to introduce extra loads to avoid other instructions, so it seems like strictly avoiding multi-use loads in this fold may not be desirable. I've opened https://github.com/llvm/llvm-project/pull/81586 to *only* use makeEquivalentMemoryOrdering() instead.
https://github.com/llvm/llvm-project/pull/81492
More information about the llvm-commits
mailing list