summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp23/attr-assume-opt.C
blob: 88d5e78dbbaedd72a1c43a34c9def163733b5e04 (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
// 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;
}

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