2014-11-05 Alex Velenko <Alex.Velenko@arm.com>
[official-gcc.git] / gcc / testsuite / gcc.dg / asr_div1.c
blob61430ca6a980e57d4e49e8473068636792373a35
1 /* Test division by const int generates only one shift. */
2 /* { dg-do run } */
3 /* { dg-options "-O2 -fdump-rtl-combine-all" } */
5 extern void abort (void);
7 #define NOINLINE __attribute__((noinline))
9 static NOINLINE int
10 f1 (int n)
12 return n / 33;
15 static NOINLINE int
16 f2 (int n)
18 return n / 77;
21 int
22 main ()
24 int a = 0xaaaaaaaa;
25 int b = 0x55555555;
26 int c;
27 c = f1 (a);
28 if (c != 0xfd6a052c)
29 abort ();
30 c = f1 (b);
31 if (c != 0x295FAD4)
32 abort ();
33 c = f2 (a);
34 if (c != 0xfee44b5c)
35 abort ();
36 c = f2 (b);
37 if (c != 0x11bb4a4)
38 abort ();
39 return 0;
42 /* Following replacement pattern of intger division by constant, GCC is expected
43 to generate MULT and (x)SHIFTRT. This test checks that considering division
44 by const 33, gcc generates a single ASHIFTRT by 35, instead of two - LSHIFTRT
45 by 32 and ASHIFTRT by 3. */
47 /* { dg-final { scan-rtl-dump "\\(set \\(subreg:DI \\(reg:SI" "combine" { target aarch64*-*-* } } } */
48 /* { dg-final { scan-rtl-dump "\\(ashiftrt:DI \\(reg:DI" "combine" { target aarch64*-*-* } } } */
49 /* { dg-final { scan-rtl-dump "\\(const_int 35 " "combine" { target aarch64*-*-* } } } */
51 /* Similarly, considering division by const 77, gcc generates a single ASHIFTRT
52 by 36, instead of two - LSHIFTRT by 32 and ASHIFTRT by 4. */
54 /* { dg-final { scan-rtl-dump "\\(const_int 36 " "combine" { target aarch64*-*-* } } } */
56 /* { dg-final { cleanup-rtl-dump "combine" } } */