[llvm] [msan] Handle horizontal add/subtract intrinsic by applying to shadow (PR #124159)

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 24 00:15:48 PST 2025


================
@@ -3904,6 +3904,23 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
     setOriginForNaryOp(I);
   }
 
+  void handleAVXHorizontalAddSubIntrinsic(IntrinsicInst &I) {
+    // Approximation only:
+    //    output         = horizontal_add(A, B)
+    // => shadow[output] = horizontal_add(shadow[A], shadow[B])
+    //
+    // - If we add/subtract two adjacent zero (initialized) shadow values, the
+    //   result always be zero i.e., no false positives.
+    // - If we add/subtract two shadows, one of which is uninitialized, the
+    //   result will always be non-zero i.e., no false negative.
+    // - However, we can have false negatives if we subtract two non-zero
+    //   shadows of the same value (or do an addition that wraps to zero); we
+    //   consider this an acceptable tradeoff for performance.
----------------
vitalybuka wrote:

> consider this an acceptable tradeoff for performance.

if we apply instruction to just allocated memory block completly uninitialzied
sub(Sa, Sb) can produce zero shadow?

Maybe better to apply Add(Sa, Sb) always?

https://github.com/llvm/llvm-project/pull/124159


More information about the llvm-commits mailing list