Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit 470fe80

Browse files
committed
Compiler-rt part of D26230: Add (constant) masked load/store support (Try #2)
Summary: Unfortunately, there is no way to emit an llvm masked load/store in clang without optimizations, and AVX enabled. Unsure how we should go about making sure this test only runs if it's possible to execute AVX code. Reviewers: kcc, RKSimon, pgousseau Subscribers: kubabrecka, dberris, llvm-commits Differential Revision: https://reviews.llvm.org/D26506 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@288504 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 451b2c1 commit 470fe80

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

test/asan/TestCases/masked-ops.cpp

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// We need optimization to convert target-specific masked loads/stores to llvm
2+
// generic loads/stores
3+
// RUN: %clangxx_asan -o %t %s -mavx -O1
4+
// RUN: not %run %t l1 2>&1 | FileCheck -check-prefix=CHECK-L1 %s
5+
// RUN: %run %t l6 2>&1 | FileCheck -check-prefix=CHECK-L6 %s
6+
// RUN: %run %t la 2>&1 | FileCheck -check-prefix=CHECK-LA %s
7+
// RUN: not %run %t s1 2>&1 | FileCheck -check-prefix=CHECK-S1 %s
8+
// RUN: %run %t s6 2>&1 | FileCheck -check-prefix=CHECK-S6 %s
9+
// RUN: %run %t sa 2>&1 | FileCheck -check-prefix=CHECK-SA %s
10+
// REQUIRES: x86-target-arch
11+
#include <assert.h>
12+
#include <stdio.h>
13+
#include <x86intrin.h>
14+
15+
float g_vec3[3] = {1802398064.0, 1881171305.0, 25961.0};
16+
17+
void maskedstore_ps_0110(__m128 a) {
18+
_mm_maskstore_ps(g_vec3, (__v4si){0, -1, -1, 0}, a);
19+
}
20+
21+
void maskedstore_ps_0001(__m128 a) {
22+
_mm_maskstore_ps(g_vec3, (__v4si){0, 0, 0, -1}, a);
23+
}
24+
25+
void maskedstore_ps_1010(__m128 a) {
26+
_mm_maskstore_ps(g_vec3, (__v4si){-1, 0, -1, 0}, a);
27+
}
28+
29+
__m128i maskedload_ps_0110() {
30+
return _mm_maskload_ps(g_vec3, (__v4si){0, -1, -1, 0});
31+
}
32+
33+
__m128i maskedload_ps_0001() {
34+
return _mm_maskload_ps(g_vec3, (__v4si){0, 0, 0, -1});
35+
}
36+
37+
__m128i maskedload_ps_1010() {
38+
return _mm_maskload_ps(g_vec3, (__v4si){-1, 0, -1, 0});
39+
}
40+
41+
__m128 a = (__v4sf){1.0, 2.0, 3.0, 4.0};
42+
43+
void print_vector(__v4sf v) {
44+
printf("%d,%d,%d,%d\n", (int)v[0], (int)v[1], (int)v[2], (int)v[3]);
45+
}
46+
void print_vector3(float * v) {
47+
printf("%d,%d,%d\n", (int)v[0], (int)v[1], (int)v[2]);
48+
}
49+
50+
int main(int argc, char **argv) {
51+
assert(argc > 1);
52+
bool isLoad = argv[1][0] == 'l';
53+
assert(isLoad || argv[1][0] == 's');
54+
if (isLoad) {
55+
switch (argv[1][1]) {
56+
case '1': {
57+
// CHECK-L1: ERROR: AddressSanitizer
58+
__v4sf v = maskedload_ps_0001();
59+
print_vector(v);
60+
// Should have blown up
61+
break;
62+
}
63+
case '6': {
64+
// Safe
65+
__v4sf v = maskedload_ps_0110();
66+
// CHECK-L6: 0,1881171328,25961,0
67+
print_vector(v);
68+
return 0;
69+
}
70+
case 'a': {
71+
// TODO: Poison middle element
72+
// Safe
73+
__v4sf v = maskedload_ps_1010();
74+
// CHECK-LA: 1802398080,0,25961,0
75+
print_vector(v);
76+
return 0;
77+
}
78+
}
79+
} else {
80+
switch (argv[1][1]) {
81+
case '1':
82+
// CHECK-S1: ERROR: AddressSanitizer
83+
maskedstore_ps_0001(a);
84+
// Should have blown up
85+
break;
86+
case '6':
87+
// Safe
88+
maskedstore_ps_0110(a);
89+
// CHECK-S6: 1802398080,2,3
90+
print_vector3(g_vec3);
91+
return 0;
92+
case 'a':
93+
// TODO: Poison middle element
94+
// Safe
95+
maskedstore_ps_1010(a);
96+
// CHECK-SA: 1,1881171328,3
97+
print_vector3(g_vec3);
98+
return 0;
99+
}
100+
}
101+
assert(0);
102+
}

0 commit comments

Comments
 (0)