diff --git a/gcc/testsuite/gcc.dg/pr113596.c b/gcc/testsuite/gcc.dg/pr113596.c
index 19e0ab6dc4673072035c20109e494aaa028a4a79..3655ffef3f976445e6042c9904c1bbe7516727d2 100644
--- a/gcc/testsuite/gcc.dg/pr113596.c
+++ b/gcc/testsuite/gcc.dg/pr113596.c
@@ -16,9 +16,17 @@ foo (int n)
   bar (p, n);
 }
 
+#if defined __AVR__
+/* For AVR devices, AVRtest assigns 8 KiB of stack, which is not quite
+   enough for this test case.  Thus request less memory on AVR.  */
+#define ALLOC 6000
+#else
+#define ALLOC 8192
+#endif
+
 int
 main ()
 {
-  for (int i = 2; i < 8192; ++i)
+  for (int i = 2; i < ALLOC; ++i)
     foo (i);
 }