aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/tree-ssa/mulexactdiv-6.c
blob: 927cb95b82b17a2d3268ba9e724f17641e2fdeff (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
/* { dg-options "-O2 -fwrapv -fdump-tree-optimized-raw" } */

#define TEST_CMP(FN, DIV, ADD, MUL)		\
  int						\
  FN (int x)   					\
  {						\
    if (x & 7)					\
      __builtin_unreachable ();			\
    x /= DIV;					\
    x += (int) (ADD);				\
    return x * MUL;				\
  }

TEST_CMP (f1, 2, ~0U >> 1, 6)
TEST_CMP (f2, 2, ~(~0U >> 2), 10)

void
cmp1 (int x)
{
  if (x & 3)
    __builtin_unreachable ();

  int y = x / 4;
  y += (int) (~0U / 3U);
  y *= 8;

  unsigned z = x;
  z *= 2U;
  z += ~0U / 3U * 8U;

  if (y != (int) z)
    __builtin_abort ();
}


void
cmp2 (int x)
{
  if (x & 63)
    __builtin_unreachable ();

  unsigned y = x / 64;
  y += 100U;
  int y2 = (int) y * 256;

  unsigned z = x;
  z *= 4U;
  z += 25600U;

  if (y2 != (int) z)
    __builtin_abort ();
}

/* { dg-final { scan-tree-dump-not {<[a-z]*_div_expr,} "optimized" } } */
/* { dg-final { scan-tree-dump-not {<rshift_expr,} "optimized" } } */
/* { dg-final { scan-tree-dump-not {gimple_call <} "optimized" } } */
/* { dg-final { scan-tree-dump-times {<nop_expr,} 4 "optimized" } } */
/* { dg-final { scan-tree-dump-times {<mult_expr,} 2 "optimized" } } */
/* { dg-final { scan-tree-dump-times {<plus_expr,} 2 "optimized" } } */