Debian Codegraph @

gcc/testsuite/gcc.dg/vect/vect-early-break_137-pr121190.c

raw
1 /* PR tree-optimization/121190 */
2 /* { dg-options "-O3" } */
3 /* { dg-additional-options "-march=znver2" { target x86_64-*-* i?86-*-* } } */
4 /* { dg-require-effective-target mmap } */
5 /* { dg-require-effective-target vect_early_break } */
6
7 #include <stdint.h>
8 #include <string.h>
9 #include <stdio.h>
10 #include <sys/mman.h>
11 #include <unistd.h>
12 #include "tree-vect.h"
13
14 #define MAX_COMPARE 5000
15
16 __attribute__((noipa))
17 int diff (uint64_t *restrict p, uint64_t *restrict q)
18 {
19 int i = 0;
20 while (i < MAX_COMPARE) {
21 if (*(p + i) != *(q + i))
22 return i;
23 i++;
24 }
25 return -1;
26 }
27
28 int main ()
29 {
30 check_vect ();
31
32 long pgsz = sysconf (_SC_PAGESIZE);
33 if (pgsz == -1) {
34 fprintf (stderr, "sysconf failed\n");
35 return 0;
36 }
37
38 /* Allocate 2 consecutive pages of memory and let p1 and p2 point to the
39 beginning of each. */
40 void *mem = mmap (NULL, pgsz * 2, PROT_READ | PROT_WRITE,
41 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
42 if (mem == MAP_FAILED) {
43 fprintf (stderr, "mmap failed\n");
44 return 0;
45 }
46 uint64_t *p1 = (uint64_t *) mem;
47 uint64_t *p2 = (uint64_t *) mem + pgsz / sizeof (uint64_t);
48
49 /* Fill the first page with zeros, except for its last 64 bits. */
50 memset (p1, 0, pgsz);
51 *(p2 - 1) = -1;
52
53 /* Make the 2nd page not accessable. */
54 mprotect (p2, pgsz, PROT_NONE);
55
56 /* Calls to diff should not read the 2nd page. */
57 for (int i = 1; i <= 20; i++) {
58 if (diff (p2 - i, p1) != i - 1)
59 __builtin_abort ();
60 }
61 }
62