This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner] Discard pointer info when combining extract_vector_elt of a vector load when the index isn't constant
ClosedPublic

Authored by craig.topper on Feb 1 2019, 1:41 PM.

Details

Summary

If the index isn't constant, this transform inserts a multiply and an add on the index to calculating the base pointer for a scalar load. But we still create a memory operand with an offset of 0 and the size of the scalar access. But the access is really to an unknown offset within the original access size.

This can cause the machine scheduler to incorrectly calculate dependencies between this load and other accesses. In the case we saw, there was a 32 byte vector store that was split into two 16 byte stores, one with offset 0 and one with offset 16. The size of the memory operand for both was 16. The scheduler correctly detected the alias with the offset 0 store, but not the offset 16 store.

This patch discards the pointer info so we don't incorrectly detect aliasing. I wasn't sure if we could keep using the original offset and size without risking some other transform on the load changing the size.

I tried to reduce a test case, but there's still a lot of memory operations needed to get the scheduler to do the bad reordering. So it looked pretty fragile to maintain.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Feb 1 2019, 1:41 PM

Actually include the change and not just the comments I wrote after making the change.

This is a little unfortunate, but looks correct.

lib/CodeGen/SelectionDAG/DAGCombiner.cpp
15645 ↗(On Diff #184841)

MachinePointerInfo has a constructor which takes an address-space (see https://reviews.llvm.org/rL319622 ).

Preserve address space

Herald added a project: Restricted Project. · View Herald TranscriptFeb 1 2019, 10:09 PM

In terms of a testcase, can you check the memory operand in MIR?

Add test cases with MIR output to show that the pointer info except for addr space is discarded on the variable index case, but not the constant index case.

efriedma accepted this revision.Feb 4 2019, 3:37 PM

LGTM

This revision is now accepted and ready to land.Feb 4 2019, 3:37 PM
This revision was automatically updated to reflect the committed changes.