aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp23/attr-assume-opt.C
blob: e61ba7a27e0fca04b74310183df9d571b1ae692d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// P1774R8 - Portable assumptions
// { dg-do compile { target c++11 } }
// { dg-options "-O2 -fdump-tree-vrp2" }
// Test the we can optimize based on conditions in assume.

int
f1 (unsigned x, unsigned y, unsigned z)
{
  [[assume (x == 2 && y < 3 && z < 20)]];
  unsigned q = x + y + z;
  if (q > 23)
    return 0;
  return 1;
}


int
f2 (int x, int y, int z)
{
  [[assume (x+12 == 14 && y >= 0 && y + 10 < 13 && z + 4 >= 4 && z - 2 < 18)]];
  unsigned q = x + y + z;
  if (q*2 > 46)
    return 0;
  return 1;
}

int
f3 (int x, int y, int z)
{
  [[assume (x + 12 == 14 && z / 2 > 0)]];
  [[assume (y >= 0 && z - 2 < 18)]];
  [[assume (y + 10 < 13 && z + 4 >= 2)]];
  int q = x + y + z;
  if (q * 2 > 46)
    return 0;
  if (z < 0)
    return 0;
  return 1;
}

// This is the same as f2, except there is more complicated flow and 
// required a range-op update to bitwise or.

void barn(int x);
// assume (x+12 == 14 && y >= 0 && y + 10 < 13 && z + 4 >= 4 && z - 2 < 18)
// in different order and form with function calls to cause branches.
bool assume_func (int x, int y, int z)
{
  if (z - 2 >= 18)
    return false;
  if (x+12 != 14)
    return false;
  barn (x);
  if (y < 0)
    return false;
  if (z + 4 < 4)
    return false;
  barn (y);
  if (y + 10 >= 13)
    return false;
  barn (z);
  return true;
}

int
f2b (int x, int y, int z)
{
  [[assume (assume_func (x, y, z))]];
  unsigned q = x + y + z;
  if (q*2 > 46)
    return 0;
  return 1;
}


/* { dg-final { scan-tree-dump-times "return 0" 0 "vrp2" } } */
/* { dg-final { scan-tree-dump-times "return 1" 4 "vrp2" } } */