Skip to content

Commit

Permalink
[RISCV] Change heuristic used for load clustering
Browse files Browse the repository at this point in the history
Split out from #73789. Clusters if the operations are within a cache
line of each other (as AMDGPU does in shouldScheduleLoadsNear). X86 does
something similar, but does `((Offset2 - Offset1) / 8 > 64)`. I'm not
sure if that's intentionally set to 512 bytes or if the division is in
error.

Adopts the suggestion from @wangpc-pp to query the cache line size and
use it if available.
  • Loading branch information
asb committed Dec 13, 2023
1 parent 037f49e commit ef43091
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2282,9 +2282,13 @@ bool RISCVInstrInfo::shouldClusterMemOps(
return false;
}

// TODO: Use a more carefully chosen heuristic, e.g. only cluster if offsets
// indicate they likely share a cache line.
return ClusterSize <= 4;
unsigned CacheLineSize =
BaseOps1.front()->getParent()->getMF()->getSubtarget().getCacheLineSize();
// Assume a cache line size of 64 bytes if no size is set in RISCVSubtarget.
CacheLineSize = CacheLineSize ? CacheLineSize : 64;
// Cluster if the memory operations are on the same or a neighbouring cache
// line.
return std::abs(Offset1 - Offset2) < CacheLineSize;
}

// Set BaseReg (the base register operand), Offset (the byte offset being
Expand Down

0 comments on commit ef43091

Please sign in to comment.