[llvm] r316243 - [Packetizer] Add function to check for aliasing between instructions
Krzysztof Parzyszek via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 20 15:08:40 PDT 2017
Author: kparzysz
Date: Fri Oct 20 15:08:40 2017
New Revision: 316243
URL: http://llvm.org/viewvc/llvm-project?rev=316243&view=rev
Log:
[Packetizer] Add function to check for aliasing between instructions
Added:
llvm/trunk/test/CodeGen/Hexagon/packetize-load-store-aliasing.mir
Modified:
llvm/trunk/include/llvm/CodeGen/DFAPacketizer.h
llvm/trunk/lib/CodeGen/DFAPacketizer.cpp
llvm/trunk/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp
Modified: llvm/trunk/include/llvm/CodeGen/DFAPacketizer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/DFAPacketizer.h?rev=316243&r1=316242&r2=316243&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/DFAPacketizer.h (original)
+++ llvm/trunk/include/llvm/CodeGen/DFAPacketizer.h Fri Oct 20 15:08:40 2017
@@ -208,6 +208,13 @@ public:
// Add a DAG mutation to be done before the packetization begins.
void addMutation(std::unique_ptr<ScheduleDAGMutation> Mutation);
+
+ bool alias(const MachineInstr &MI1, const MachineInstr &MI2,
+ bool UseTBAA = true) const;
+
+private:
+ bool alias(const MachineMemOperand &Op1, const MachineMemOperand &Op2,
+ bool UseTBAA = true) const;
};
} // end namespace llvm
Modified: llvm/trunk/lib/CodeGen/DFAPacketizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/DFAPacketizer.cpp?rev=316243&r1=316242&r2=316243&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/DFAPacketizer.cpp (original)
+++ llvm/trunk/lib/CodeGen/DFAPacketizer.cpp Fri Oct 20 15:08:40 2017
@@ -336,6 +336,38 @@ void VLIWPacketizerList::PacketizeMIs(Ma
VLIWScheduler->finishBlock();
}
+bool VLIWPacketizerList::alias(const MachineMemOperand &Op1,
+ const MachineMemOperand &Op2,
+ bool UseTBAA) const {
+ if (!Op1.getValue() || !Op2.getValue())
+ return true;
+
+ int64_t MinOffset = std::min(Op1.getOffset(), Op2.getOffset());
+ int64_t Overlapa = Op1.getSize() + Op1.getOffset() - MinOffset;
+ int64_t Overlapb = Op2.getSize() + Op2.getOffset() - MinOffset;
+
+ AliasResult AAResult =
+ AA->alias(MemoryLocation(Op1.getValue(), Overlapa,
+ UseTBAA ? Op1.getAAInfo() : AAMDNodes()),
+ MemoryLocation(Op2.getValue(), Overlapb,
+ UseTBAA ? Op2.getAAInfo() : AAMDNodes()));
+
+ return AAResult != NoAlias;
+}
+
+bool VLIWPacketizerList::alias(const MachineInstr &MI1,
+ const MachineInstr &MI2,
+ bool UseTBAA) const {
+ if (MI1.memoperands_empty() || MI2.memoperands_empty())
+ return true;
+
+ for (const MachineMemOperand *Op1 : MI1.memoperands())
+ for (const MachineMemOperand *Op2 : MI2.memoperands())
+ if (alias(*Op1, *Op2, UseTBAA))
+ return true;
+ return false;
+}
+
// Add a DAG mutation object to the ordered list.
void VLIWPacketizerList::addMutation(
std::unique_ptr<ScheduleDAGMutation> Mutation) {
Modified: llvm/trunk/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp?rev=316243&r1=316242&r2=316243&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp (original)
+++ llvm/trunk/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp Fri Oct 20 15:08:40 2017
@@ -1499,7 +1499,7 @@ bool HexagonPacketizerList::isLegalToPac
if (StoreJ) {
// Two stores are only allowed on V4+. Load following store is never
// allowed.
- if (LoadI) {
+ if (LoadI && alias(J, I)) {
FoundSequentialDependence = true;
break;
}
Added: llvm/trunk/test/CodeGen/Hexagon/packetize-load-store-aliasing.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Hexagon/packetize-load-store-aliasing.mir?rev=316243&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/Hexagon/packetize-load-store-aliasing.mir (added)
+++ llvm/trunk/test/CodeGen/Hexagon/packetize-load-store-aliasing.mir Fri Oct 20 15:08:40 2017
@@ -0,0 +1,41 @@
+# RUN: llc -march=hexagon -mcpu=hexagonv60 -run-pass hexagon-packetizer %s -o - | FileCheck %s
+
+# Check that a store can be packetized with a load that happens later
+# if these instructions are not aliased (the load will actually execute
+# first).
+# CHECK-LABEL: name: danny
+# CHECK: BUNDLE
+
+---
+name: danny
+tracksRegLiveness: true
+stack:
+ - { id: 0, type: default, size: 4, alignment: 4 }
+ - { id: 1, type: default, size: 4, alignment: 4 }
+body: |
+ bb.0:
+ liveins: %r0
+ S2_storeri_io %r29, 0, %r0 :: (store 4 into %stack.0)
+ %r1 = L2_loadri_io %r29, 4 :: (load 4 from %stack.1)
+...
+
+
+# Check that a store cannot be packetized with a load that happens later
+# if these instructions are aliased.
+# CHECK-LABEL: name: sammy
+# CHECK-NOT: BUNDLE
+# CHECK: S2_storeri_io %r29, 0, %r0
+# CHECK: %r1 = L2_loadri_io %r29, 0
+
+---
+name: sammy
+tracksRegLiveness: true
+stack:
+ - { id: 0, type: default, size: 4, alignment: 4 }
+body: |
+ bb.0:
+ liveins: %r0
+ S2_storeri_io %r29, 0, %r0 :: (store 4 into %stack.0)
+ %r1 = L2_loadri_io %r29, 0 :: (load 4 from %stack.0)
+...
+
More information about the llvm-commits
mailing list