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

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 1 13:41:56 PST 2019


craig.topper created this revision.
craig.topper added a reviewer: efriedma.
Herald added a subscriber: arphaman.

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.


https://reviews.llvm.org/D57616

Files:
  lib/CodeGen/SelectionDAG/DAGCombiner.cpp


Index: lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -15640,10 +15640,16 @@
     Offset = DAG.getConstant(PtrOff, DL, PtrType);
     MPI = OriginalLoad->getPointerInfo().getWithOffset(PtrOff);
   } else {
+    // We can't preserve pointer info, so don't do this transform if the the
+    // access isn't in the default address space.
+    if (OriginalLoad->getPointerInfo().getAddrSpace() != 0)
+      return SDValue();
     Offset = DAG.getZExtOrTrunc(EltNo, DL, PtrType);
     Offset = DAG.getNode(
         ISD::MUL, DL, PtrType, Offset,
         DAG.getConstant(VecEltVT.getStoreSize(), DL, PtrType));
+    // Discard the pointer info because the memory operand can't represent this
+    // new access since the offset is variable.
     MPI = MachinePointerInfo();
   }
   NewPtr = DAG.getNode(ISD::ADD, DL, PtrType, NewPtr, Offset);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57616.184833.patch
Type: text/x-patch
Size: 994 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190201/433d56c5/attachment.bin>


More information about the llvm-commits mailing list