Skip to content

Commit 2fca446

Browse files
authored
[msan] Handle AVX512 pack with saturation intrinsics (#157984)
Approximately handle avx512_{packssdw/packsswb/packusdw/packuswb} with the existing handleVectorPackIntrinsic(), instead of relying on the default (strict) handler.
1 parent 8c0f3b6 commit 2fca446

File tree

3 files changed

+453
-736
lines changed

3 files changed

+453
-736
lines changed

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3684,6 +3684,15 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
36843684

36853685
case Intrinsic::x86_mmx_packssdw:
36863686
return Intrinsic::x86_mmx_packssdw;
3687+
3688+
case Intrinsic::x86_avx512_packssdw_512:
3689+
case Intrinsic::x86_avx512_packusdw_512:
3690+
return Intrinsic::x86_avx512_packssdw_512;
3691+
3692+
case Intrinsic::x86_avx512_packsswb_512:
3693+
case Intrinsic::x86_avx512_packuswb_512:
3694+
return Intrinsic::x86_avx512_packsswb_512;
3695+
36873696
default:
36883697
llvm_unreachable("unexpected intrinsic id");
36893698
}
@@ -3696,6 +3705,8 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
36963705
// Shadow is propagated with the signed variant of the same intrinsic applied
36973706
// to sext(Sa != zeroinitializer), sext(Sb != zeroinitializer).
36983707
// MMXEltSizeInBits is used only for x86mmx arguments.
3708+
//
3709+
// TODO: consider using GetMinMaxUnsigned() to handle saturation precisely
36993710
void handleVectorPackIntrinsic(IntrinsicInst &I,
37003711
unsigned MMXEltSizeInBits = 0) {
37013712
assert(I.arg_size() == 2);
@@ -5554,6 +5565,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
55545565
handleVectorShiftIntrinsic(I, /* Variable */ true);
55555566
break;
55565567

5568+
// Pack with Signed/Unsigned Saturation
55575569
case Intrinsic::x86_sse2_packsswb_128:
55585570
case Intrinsic::x86_sse2_packssdw_128:
55595571
case Intrinsic::x86_sse2_packuswb_128:
@@ -5562,6 +5574,15 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
55625574
case Intrinsic::x86_avx2_packssdw:
55635575
case Intrinsic::x86_avx2_packuswb:
55645576
case Intrinsic::x86_avx2_packusdw:
5577+
// e.g., <64 x i8> @llvm.x86.avx512.packsswb.512
5578+
// (<32 x i16> %a, <32 x i16> %b)
5579+
// <32 x i16> @llvm.x86.avx512.packssdw.512
5580+
// (<16 x i32> %a, <16 x i32> %b)
5581+
// Note: AVX512 masked variants are auto-upgraded by LLVM.
5582+
case Intrinsic::x86_avx512_packsswb_512:
5583+
case Intrinsic::x86_avx512_packssdw_512:
5584+
case Intrinsic::x86_avx512_packuswb_512:
5585+
case Intrinsic::x86_avx512_packusdw_512:
55655586
handleVectorPackIntrinsic(I);
55665587
break;
55675588

0 commit comments

Comments
 (0)