[llvm] [AArch64][MachineCombiner] Combine sequences of gather patterns (PR #152979)
Jonathan Cohen via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 17 04:56:42 PDT 2025
================
@@ -7412,11 +7413,347 @@ static bool getMiscPatterns(MachineInstr &Root,
return false;
}
+/// Check if there are any stores or calls between two instructions in the same
+/// basic block.
+static bool hasInterveningStoreOrCall(const MachineInstr *First,
+ const MachineInstr *Last) {
+ if (!First || !Last || First == Last)
+ return false;
+
+ // Both instructions must be in the same basic block.
+ if (First->getParent() != Last->getParent())
+ return false;
+
+ // Sanity check that First comes before Last.
+ const MachineBasicBlock *MBB = First->getParent();
+ auto InstrIt = First->getIterator();
+ auto LastIt = Last->getIterator();
+
+ for (; InstrIt != MBB->end(); ++InstrIt) {
+ if (InstrIt == LastIt)
+ break;
+
+ // Check for stores or calls that could interfere
+ if (InstrIt->mayStore() || InstrIt->isCall())
+ return true;
+ }
+
+ // If we reached the end of the basic block, our instructions must have not
+ // been ordered correctly and the analysis is invalid.
+ assert(InstrIt != MBB->end() &&
+ "Got bad machine instructions, First should come before Last!");
+ return false;
+}
+
+/// Check if the given instruction forms a gather load pattern that can be
+/// optimized for better Memory-Level Parallelism (MLP). This function
+/// identifies chains of NEON lane load instructions that load data from
+/// different memory addresses into individual lanes of a 128-bit vector
+/// register, then attempts to split the pattern into parallel loads to break
+/// the serial dependency between instructions.
+///
+/// Pattern Matched:
+/// Initial scalar load -> SUBREG_TO_REG (lane 0) -> LD1i* (lane 1) ->
+/// LD1i* (lane 2) -> ... -> LD1i* (lane N-1, Root)
+///
+/// Transformed Into:
+/// Two parallel vector loads using fewer lanes each, followed by ZIP1v2i64
+/// to combine the results, enabling better memory-level parallelism.
+///
+/// Supported Element Types:
+/// - 32-bit elements (LD1i32, 4 lanes total)
+/// - 16-bit elements (LD1i16, 8 lanes total)
+/// - 8-bit elements (LD1i8, 16 lanes total)
+static bool getGatherPattern(MachineInstr &Root,
----------------
jcohen-apple wrote:
Done
https://github.com/llvm/llvm-project/pull/152979
More information about the llvm-commits
mailing list