Skip to content

Commit eed7940

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 a6044a0 commit eed7940

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?
@@ -4615,6 +4620,18 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
46154620
case Intrinsic::x86_avx2_maskload_d_256:
46164621
case Intrinsic::x86_avx2_maskload_q_256: {
46174622
handleAVXMaskedLoad(I);
4623+
4624+
// Packed
4625+
case Intrinsic::x86_avx512_min_ps_512:
4626+
case Intrinsic::x86_avx512_min_pd_512:
4627+
case Intrinsic::x86_avx512_max_ps_512:
4628+
case Intrinsic::x86_avx512_max_pd_512: {
4629+
// These AVX512 variants contain the rounding mode as a trailing flag.
4630+
// Earlier variants do not have a trailing flag and are already handled
4631+
// by maybeHandleSimpleNomemIntrinsic(I, 0) via handleUnknownIntrinsic.
4632+
bool success = maybeHandleSimpleNomemIntrinsic(I, /* trailingFlags */ 1);
4633+
(void)success;
4634+
assert(success);
46184635
break;
46194636
}
46204637

0 commit comments

Comments
 (0)