This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner] Fix for big endian in ForwardStoreValueToDirectLoad
ClosedPublic

Authored by bjope on Oct 26 2018, 1:23 PM.

Details

Summary

Normalize the offset for endianess before checking
if the store cover the load in ForwardStoreValueToDirectLoad.

Without this we missed out on some optimizations for big
endian targets. If for example having a 4 bytes store followed
by a 1 byte load, loading the least significant byte from the
store, the STCoversLD check would fail (see @test4 in
test/CodeGen/AArch64/load-store-forwarding.ll).

This patch also fixes a problem seen in an out-of-tree target.
The target has i40 as a legal type, it is big endian,
and the StoreSize for i40 is 48 bits. So when normalizing
the offset for endianess we need to take the StoreSize into
account (assuming that padding added when storing into
a larger StoreSize always is added at the most significant
end).

Diff Detail

Repository
rL LLVM

Event Timeline

bjope created this revision.Oct 26 2018, 1:23 PM
bjope added a comment.Oct 26 2018, 1:25 PM

This should fix the problem discussed here: http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20181022/596459.html
But as shown by @test4 in the added test case (for CHECK-BE) we also get forwarding in that test now.

bjope added inline comments.Oct 26 2018, 1:36 PM
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
12870 ↗(On Diff #171342)

@niravd do you remember why we have the check (Offset * 8 <= LDMemType.getSizeInBits()) here?

From my point of view it looks wrong. Maybe it is supposed to be (Offset * 8 <= STMemType.getSizeInBits()), i.e. checking that the load starts before the last bit written by the store. But then I guess it is enough to check
(Offset >= 0) && (Offset * 8 + LDMemType.getSizeInBits() <= STMemType.getSizeInBits()) or are we trying to catch some special case when we get overflow in the int64_t?

niravd accepted this revision.Oct 30 2018, 12:19 PM

Modulo removing the unnecessary condition you commented on, this looks good to me. Thanks.

lib/CodeGen/SelectionDAG/DAGCombiner.cpp
12870 ↗(On Diff #171342)

Huh. I have no idea how that got there. We should only need the other 2 checks.

Can you take it out?

This revision is now accepted and ready to land.Oct 30 2018, 12:19 PM
bjope added inline comments.Oct 30 2018, 12:32 PM
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
12870 ↗(On Diff #171342)

Thanks! I'll take it out before commit.

This revision was automatically updated to reflect the committed changes.