2008-03-21 Janne Blomqvist <jb@gcc.gnu.org>
[official-gcc.git] / gcc / testsuite / gcc.dg / globalreg-1.c
blobf54976dce1de49091ad3ee9ebc70235a7bc5d611
1 /* { dg-do run { target sparc*-*-* } } */
2 /* { dg-options "-std=gnu99 -Os" } */
4 /* This is a massively distilled test case based upon
5 mm/memory.c:unmap_vmas() in the Linux kernel when compiled
6 on sparc64 for SMP which uses a global register as the
7 base of the per-cpu variable area.
9 Because of a bug in global register handling in the dataflow
10 code, the loop-invariant pass would move 'expression(regval)'
11 outside of the loop. */
13 extern void exit(int);
14 extern void abort(void);
16 register unsigned long regval __asm__("g6");
18 extern void cond_resched(void);
20 unsigned int var;
22 static unsigned long expression(unsigned long v)
24 unsigned long ret;
26 __asm__("" : "=r" (ret) : "0" (0));
27 return ret + v;
30 void func(unsigned long *pp)
32 int i;
34 for (i = 0; i < 56; i++) {
35 cond_resched();
36 *pp = expression(regval);
40 void __attribute__((noinline)) cond_resched(void)
42 regval++;
45 int main(void)
47 unsigned long val;
49 regval = 100;
50 func(&val);
51 if (val != 156)
52 abort();
53 exit(0);