* gcc.dg/predict-12.c: New testcase.
[official-gcc.git] / gcc / testsuite / gcc.dg / asr_div1.c
blobbf374b82c3fc0d3a6ee1748b4e9a2bee2b71d7d9
1 /* Test division by const int generates only one shift. */
2 /* { dg-do run } */
3 /* { dg-options "-O2 -fdump-rtl-combine-all" } */
4 /* { dg-require-effective-target int32plus } */
6 extern void abort (void);
8 #define NOINLINE __attribute__((noinline))
10 static NOINLINE int
11 f1 (int n)
13 return n / 33;
16 static NOINLINE int
17 f2 (int n)
19 return n / 77;
22 int
23 main ()
25 int a = 0xaaaaaaaa;
26 int b = 0x55555555;
27 int c;
28 c = f1 (a);
29 if (c != 0xfd6a052c)
30 abort ();
31 c = f1 (b);
32 if (c != 0x295FAD4)
33 abort ();
34 c = f2 (a);
35 if (c != 0xfee44b5c)
36 abort ();
37 c = f2 (b);
38 if (c != 0x11bb4a4)
39 abort ();
40 return 0;
43 /* Following replacement pattern of intger division by constant, GCC is expected
44 to generate MULT and (x)SHIFTRT. This test checks that considering division
45 by const 33, gcc generates a single ASHIFTRT by 35, instead of two - LSHIFTRT
46 by 32 and ASHIFTRT by 3. */
48 /* { dg-final { scan-rtl-dump "\\(set \\(subreg:DI \\(reg:SI" "combine" { target aarch64*-*-* } } } */
49 /* { dg-final { scan-rtl-dump "\\(ashiftrt:DI \\(reg:DI" "combine" { target aarch64*-*-* } } } */
50 /* { dg-final { scan-rtl-dump "\\(const_int 35 " "combine" { target aarch64*-*-* } } } */
52 /* Similarly, considering division by const 77, gcc generates a single ASHIFTRT
53 by 36, instead of two - LSHIFTRT by 32 and ASHIFTRT by 4. */
55 /* { dg-final { scan-rtl-dump "\\(const_int 36 " "combine" { target aarch64*-*-* } } } */