llvm.org GIT mirror llvm / dd7c5bb
[msan] Handle x86 vector pack intrinsics. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210020 91177308-0d34-0410-b5e6-96231b3b80d8 Evgeniy Stepanov 5 years ago
2 changed file(s) with 74 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
19401940 IRB.CreateBitCast(S1, V1->getType()), V2);
19411941 Shift = IRB.CreateBitCast(Shift, getShadowTy(&I));
19421942 setShadow(&I, IRB.CreateOr(Shift, S2Conv));
1943 setOriginForNaryOp(I);
1944 }
1945
1946 // \brief Instrument vector shift instrinsic.
1947 //
1948 // This function instruments intrinsics like x86_mmx_packsswb, that
1949 // packs elements of 2 input vectors into half as much bits with saturation.
1950 // Shadow is propagated with the same intrinsic applied to
1951 // sext(Sa != zeroinitializer), sext(Sb != zeroinitializer).
1952 void handleVectorPackIntrinsic(IntrinsicInst &I) {
1953 assert(I.getNumArgOperands() == 2);
1954 IRBuilder<> IRB(&I);
1955 Value *S1 = getShadow(&I, 0);
1956 Value *S2 = getShadow(&I, 1);
1957 Type *T = S1->getType();
1958 Value *S1_ext = IRB.CreateSExt(
1959 IRB.CreateICmpNE(S1, llvm::Constant::getNullValue(T)), T);
1960 Value *S2_ext = IRB.CreateSExt(
1961 IRB.CreateICmpNE(S2, llvm::Constant::getNullValue(T)), T);
1962 Value *S = IRB.CreateCall2(I.getCalledValue(), S1_ext, S2_ext,
1963 "_msprop_vector_pack");
1964 setShadow(&I, S);
19431965 setOriginForNaryOp(I);
19441966 }
19451967
20592081 // case llvm::Intrinsic::x86_sse2_psll_dq_bs:
20602082 // case llvm::Intrinsic::x86_sse2_psrl_dq_bs:
20612083
2084 case llvm::Intrinsic::x86_sse2_packsswb_128:
2085 case llvm::Intrinsic::x86_sse2_packssdw_128:
2086 case llvm::Intrinsic::x86_sse2_packuswb_128:
2087 case llvm::Intrinsic::x86_sse41_packusdw:
2088 case llvm::Intrinsic::x86_avx2_packsswb:
2089 case llvm::Intrinsic::x86_avx2_packssdw:
2090 case llvm::Intrinsic::x86_avx2_packuswb:
2091 case llvm::Intrinsic::x86_avx2_packusdw:
2092 case llvm::Intrinsic::x86_mmx_packsswb:
2093 case llvm::Intrinsic::x86_mmx_packssdw:
2094 case llvm::Intrinsic::x86_mmx_packuswb:
2095 handleVectorPackIntrinsic(I);
2096 break;
2097
20622098 default:
20632099 if (!handleUnknownIntrinsic(I))
20642100 visitInstruction(I);
0 ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s
1
2 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
3 target triple = "x86_64-unknown-linux-gnu"
4
5 declare <8 x i16> @llvm.x86.sse2.packssdw.128(<4 x i32>, <4 x i32>) nounwind readnone
6 declare <32 x i8> @llvm.x86.avx2.packuswb(<16 x i16> %a, <16 x i16> %b) nounwind readnone
7
8 define <8 x i16> @Test_packssdw_128(<4 x i32> %a, <4 x i32> %b) sanitize_memory {
9 entry:
10 %c = tail call <8 x i16> @llvm.x86.sse2.packssdw.128(<4 x i32> %a, <4 x i32> %b) nounwind
11 ret <8 x i16> %c
12 }
13
14 ; CHECK-LABEL: @Test_packssdw_128(
15 ; CHECK-DAG: icmp ne <4 x i32> {{.*}}, zeroinitializer
16 ; CHECK-DAG: sext <4 x i1> {{.*}} to <4 x i32>
17 ; CHECK-DAG: icmp ne <4 x i32> {{.*}}, zeroinitializer
18 ; CHECK-DAG: sext <4 x i1> {{.*}} to <4 x i32>
19 ; CHECK-DAG: call <8 x i16> @llvm.x86.sse2.packssdw.128(
20 ; CHECK-DAG: call <8 x i16> @llvm.x86.sse2.packssdw.128(
21 ; CHECK: ret <8 x i16>
22
23
24 define <32 x i8> @Test_avx_packuswb(<16 x i16> %a, <16 x i16> %b) sanitize_memory {
25 entry:
26 %c = tail call <32 x i8> @llvm.x86.avx2.packuswb(<16 x i16> %a, <16 x i16> %b) nounwind
27 ret <32 x i8> %c
28 }
29
30 ; CHECK-LABEL: @Test_avx_packuswb(
31 ; CHECK-DAG: icmp ne <16 x i16> {{.*}}, zeroinitializer
32 ; CHECK-DAG: sext <16 x i1> {{.*}} to <16 x i16>
33 ; CHECK-DAG: icmp ne <16 x i16> {{.*}}, zeroinitializer
34 ; CHECK-DAG: sext <16 x i1> {{.*}} to <16 x i16>
35 ; CHECK-DAG: call <32 x i8> @llvm.x86.avx2.packuswb(
36 ; CHECK-DAG: call <32 x i8> @llvm.x86.avx2.packuswb(
37 ; CHECK: ret <32 x i8>