[PATCH] D47739: DAG: Stop dropping invariant/dereferencable

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 4 12:45:11 PDT 2018


arsenm created this revision.
arsenm added reviewers: bogner, jlebar.
Herald added subscribers: tpr, nhaehnle, wdng.

When legalizing illegal FP load results, this was
for some reason dropping the invariant and dereferencable
memory flags. There doesn't seem to be any reason for this,
and the equivalent isn't done for integer loads.

     

Fixes an issue in a future AMDGPU commit where some identical
loads fail to merge because one of the loads ends up
dropping the flags.


https://reviews.llvm.org/D47739

Files:
  lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
  test/CodeGen/AMDGPU/legalize-fp-load-invariant.ll


Index: test/CodeGen/AMDGPU/legalize-fp-load-invariant.ll
===================================================================
--- /dev/null
+++ test/CodeGen/AMDGPU/legalize-fp-load-invariant.ll
@@ -0,0 +1,13 @@
+; RUN: llc -march=amdgcn -mcpu=tahiti -verify-machineinstrs -stop-after=isel -o - %s | FileCheck -check-prefix=GCN %s
+
+; Type legalization for illegal FP type results was dropping invariant
+; and dereferenceable flags.
+
+; GCN: BUFFER_LOAD_USHORT_OFFSET killed %{{[0-9]+}}, 0, 0, 0, 0, 0, implicit $exec :: (dereferenceable invariant load 2 from %ir.ptr, addrspace 4)
+define half @legalize_f16_load(half addrspace(4)* dereferenceable(4) %ptr) {
+  %load = load half, half addrspace(4)* %ptr, !invariant.load !0
+  %add = fadd half %load, 1.0
+  ret half %add
+}
+
+!0 = !{}
Index: lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
+++ lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
@@ -2102,13 +2102,12 @@
 
   // Load the value as an integer value with the same number of bits.
   EVT IVT = EVT::getIntegerVT(*DAG.getContext(), VT.getSizeInBits());
-  auto MMOFlags =
-      L->getMemOperand()->getFlags() &
-      ~(MachineMemOperand::MOInvariant | MachineMemOperand::MODereferenceable);
   SDValue newL = DAG.getLoad(L->getAddressingMode(), L->getExtensionType(), IVT,
                              SDLoc(N), L->getChain(), L->getBasePtr(),
                              L->getOffset(), L->getPointerInfo(), IVT,
-                             L->getAlignment(), MMOFlags, L->getAAInfo());
+                             L->getAlignment(),
+                             L->getMemOperand()->getFlags(),
+                             L->getAAInfo());
   // Legalize the chain result by replacing uses of the old value chain with the
   // new one
   ReplaceValueWith(SDValue(N, 1), newL.getValue(1));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47739.149837.patch
Type: text/x-patch
Size: 1935 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180604/fe39ffea/attachment.bin>


More information about the llvm-commits mailing list