summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/minmax-1.c
blob: e279c0e20fe3d8d7b99be181c4e12057085be056 (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
78
79
80
81
82
83
/* { dg-do run } */
/* { dg-options "-fdump-tree-original" } */

/* Check that MIN-MAX and MAX-MIN combinations are folded.  */

extern void abort (void);

#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MAX(a,b) ((a) > (b) ? (a) : (b))

int f1(int a, int b)
{
   return MIN (MAX (a, b), b); /* == b */
}

int f2(int a, int b)
{
   return MAX (MIN (a, b), b); /* == b */
}

int f3(int a, int b)
{
   return MIN (MAX (b, a), b); /* == b */
}

int f4(int a, int b)
{
   return MAX (MIN (b, a), b); /* == b */
}


int g1(int a, int b)
{
   return MIN (a, MAX (a, b)); /* == a */
}

int g2(int a, int b)
{
   return MAX (a, MIN (a, b)); /* == a */
}

int g3(int a, int b)
{
   return MIN (a, MAX (b, a)); /* == a */
}

int g4(int a, int b)
{
   return MAX (a, MIN (b, a)); /* == a */
}

int main(void)
{
  if (f1 (1, 2) != 2)
    abort ();

  if (f2 (1, 2) != 2)
    abort ();

  if (f3 (1, 2) != 2)
    abort ();

  if (f4 (1, 2) != 2)
    abort ();

  if (g1 (1, 2) != 1)
    abort ();

  if (g2 (1, 2) != 1)
    abort ();

  if (g3 (1, 2) != 1)
    abort ();

  if (g4 (1, 2) != 1)
    abort ();

  return 0;
}

/* { dg-final { scan-tree-dump-times "MIN_EXPR" 0 "original"} } */
/* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "original"} } */
/* { dg-final { cleanup-tree-dump "original" } } */