[llvm] Provide intrinsics for speculative loads (PR #179642)
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 4 11:56:02 PST 2026
================
@@ -30174,6 +30174,55 @@ Value *AArch64TargetLowering::emitStoreConditional(IRBuilderBase &Builder,
return CI;
}
+Value *AArch64TargetLowering::emitCanLoadSpeculatively(IRBuilderBase &Builder,
+ Value *Ptr,
+ Value *Size) const {
+ // For power-of-2 sizes <= 16, emit alignment check: (ptr & (size - 1)) == 0.
+ // If the pointer is aligned to at least 'size' bytes, loading 'size' bytes
+ // cannot cross a page boundary, so it's safe to speculate.
+ // The 16-byte limit ensures correctness with MTE (memory tagging), since
+ // MTE uses 16-byte tag granules.
+ //
+ // The alignment check only works for power-of-2 sizes. For non-power-of-2
+ // sizes, we conservatively return false.
----------------
efriedma-quic wrote:
I think we may need some sort of "userspace" check. Doing this sort of speculation is dangerous when you could potentially read MMIO registers.
https://github.com/llvm/llvm-project/pull/179642
More information about the llvm-commits
mailing list