Skip to content

Commit bfc04bd

Browse files
committed
[msan] Handle x86_avx512_(min|max)_p[sd]_512 intrinsics
The AVX/SSE variants are already handled heuristically (maybeHandleSimpleNomemIntrinsic via handleUnknownIntrinsic), but the AVX512 variants contain an additional parameter (the rounding method) which fails to match heuristically. We generalize maybeHandleSimpleNomemIntrinsic to allow additional flags (ignored by MSan) and explicitly call it to handle AVX512 min/max ps/pd intrinsics.
1 parent b8cdc5e commit bfc04bd

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2989,17 +2989,22 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
29892989

29902990
/// Handle (SIMD arithmetic)-like intrinsics.
29912991
///
2992-
/// Instrument intrinsics with any number of arguments of the same type,
2993-
/// equal to the return type. The type should be simple (no aggregates or
2994-
/// pointers; vectors are fine).
2992+
/// Instrument intrinsics with any number of arguments of the same type [*],
2993+
/// equal to the return type, plus a specified number of trailing flags of
2994+
/// any type.
2995+
///
2996+
/// [*} The type should be simple (no aggregates or pointers; vectors are
2997+
/// fine).
2998+
///
29952999
/// Caller guarantees that this intrinsic does not access memory.
2996-
bool maybeHandleSimpleNomemIntrinsic(IntrinsicInst &I) {
3000+
bool maybeHandleSimpleNomemIntrinsic(IntrinsicInst &I, unsigned int trailingFlags) {
29973001
Type *RetTy = I.getType();
29983002
if (!(RetTy->isIntOrIntVectorTy() || RetTy->isFPOrFPVectorTy()))
29993003
return false;
30003004

30013005
unsigned NumArgOperands = I.arg_size();
3002-
for (unsigned i = 0; i < NumArgOperands; ++i) {
3006+
assert(NumArgOperands >= trailingFlags);
3007+
for (unsigned i = 0; i < NumArgOperands - trailingFlags; ++i) {
30033008
Type *Ty = I.getArgOperand(i)->getType();
30043009
if (Ty != RetTy)
30053010
return false;
@@ -3043,7 +3048,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
30433048
}
30443049

30453050
if (I.doesNotAccessMemory())
3046-
if (maybeHandleSimpleNomemIntrinsic(I))
3051+
if (maybeHandleSimpleNomemIntrinsic(I, /* trailingFlags */ 0))
30473052
return true;
30483053

30493054
// FIXME: detect and handle SSE maskstore/maskload?
@@ -4684,6 +4689,18 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
46844689
case Intrinsic::x86_avx2_maskload_d_256:
46854690
case Intrinsic::x86_avx2_maskload_q_256: {
46864691
handleAVXMaskedLoad(I);
4692+
4693+
// Packed
4694+
case Intrinsic::x86_avx512_min_ps_512:
4695+
case Intrinsic::x86_avx512_min_pd_512:
4696+
case Intrinsic::x86_avx512_max_ps_512:
4697+
case Intrinsic::x86_avx512_max_pd_512: {
4698+
// These AVX512 variants contain the rounding mode as a trailing flag.
4699+
// Earlier variants do not have a trailing flag and are already handled
4700+
// by maybeHandleSimpleNomemIntrinsic(I, 0) via handleUnknownIntrinsic.
4701+
bool success = maybeHandleSimpleNomemIntrinsic(I, /* trailingFlags */ 1);
4702+
(void)success;
4703+
assert(success);
46874704
break;
46884705
}
46894706

0 commit comments

Comments
 (0)