Skip to content

Commit fdadef9

Browse files
authored
[msan] Handle x86_avx512_(min|max)_p[sd]_512 intrinsics (#124421)
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. This patch generalizes maybeHandleSimpleNomemIntrinsic to allow additional flags (ignored by MSan) and explicitly call it to handle AVX512 min/max ps/pd intrinsics. It also updates the test added in #123980
1 parent ff271d0 commit fdadef9

File tree

3 files changed

+120
-308
lines changed

3 files changed

+120
-308
lines changed

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2989,17 +2989,24 @@ 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+
[[maybe_unused]] bool
3001+
maybeHandleSimpleNomemIntrinsic(IntrinsicInst &I,
3002+
unsigned int trailingFlags) {
29973003
Type *RetTy = I.getType();
29983004
if (!(RetTy->isIntOrIntVectorTy() || RetTy->isFPOrFPVectorTy()))
29993005
return false;
30003006

30013007
unsigned NumArgOperands = I.arg_size();
3002-
for (unsigned i = 0; i < NumArgOperands; ++i) {
3008+
assert(NumArgOperands >= trailingFlags);
3009+
for (unsigned i = 0; i < NumArgOperands - trailingFlags; ++i) {
30033010
Type *Ty = I.getArgOperand(i)->getType();
30043011
if (Ty != RetTy)
30053012
return false;
@@ -3043,7 +3050,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
30433050
}
30443051

30453052
if (I.doesNotAccessMemory())
3046-
if (maybeHandleSimpleNomemIntrinsic(I))
3053+
if (maybeHandleSimpleNomemIntrinsic(I, /*trailingFlags=*/0))
30473054
return true;
30483055

30493056
// FIXME: detect and handle SSE maskstore/maskload?
@@ -4687,6 +4694,19 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
46874694
break;
46884695
}
46894696

4697+
// Packed
4698+
case Intrinsic::x86_avx512_min_ps_512:
4699+
case Intrinsic::x86_avx512_min_pd_512:
4700+
case Intrinsic::x86_avx512_max_ps_512:
4701+
case Intrinsic::x86_avx512_max_pd_512: {
4702+
// These AVX512 variants contain the rounding mode as a trailing flag.
4703+
// Earlier variants do not have a trailing flag and are already handled
4704+
// by maybeHandleSimpleNomemIntrinsic(I, 0) via handleUnknownIntrinsic.
4705+
bool Success = maybeHandleSimpleNomemIntrinsic(I, /*trailingFlags=*/1);
4706+
assert(Success);
4707+
break;
4708+
}
4709+
46904710
case Intrinsic::fshl:
46914711
case Intrinsic::fshr:
46924712
handleFunnelShift(I);

0 commit comments

Comments
 (0)