From patchwork Fri Feb 20 14:45:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 441994 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3226E1401AB for ; Sat, 21 Feb 2015 01:46:14 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=nSAIjZjHClthqyDb5X81kkVgY4o8w LaEmkpjF7o67Z8yDqe7SbXjZAJvz++mDABhNxwTvQL0y76cMaMYjtZ5kxfRq1Wnz ehefw2emDrSSvhUH/miW4e5DVbJmxD6AfBMJFt1F4tzGWcOA1uAakn7mjTil/om7 FUOn4OSkM2AykI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=R/1wAHazOHNRRNfedG4zSKJ0egA=; b=eGS mxVrA1/KR6OYxVVzZaWQBkj6SoSiQni5nLgeqaKKzFklLBaKgN9/CjHAIZsuD1M/ 8UkYBggfo3ppbzUNIyKGKU6qCgeaT7zipqGePGgJuf9K0LR2tsYMu2dahjzqYiIR 9einp5vZhf52NGgzEawXtcqe3dRxIWuM9tkinGmE= Received: (qmail 1077 invoked by alias); 20 Feb 2015 14:46:07 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 1067 invoked by uid 89); 20 Feb 2015 14:46:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 20 Feb 2015 14:46:05 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t1KEk0P8030531 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 20 Feb 2015 09:46:00 -0500 Received: from tucnak.zalov.cz (ovpn-116-28.ams2.redhat.com [10.36.116.28]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t1KEjwaV025765 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Fri, 20 Feb 2015 09:45:59 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.9/8.14.9) with ESMTP id t1KEjumr010118; Fri, 20 Feb 2015 15:45:57 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.9/8.14.9/Submit) id t1KEjtIv010117; Fri, 20 Feb 2015 15:45:55 +0100 Date: Fri, 20 Feb 2015 15:45:55 +0100 From: Jakub Jelinek To: Rainer Orth , Mike Stump Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Add sibcall-{9,10}.c testcases Message-ID: <20150220144555.GC1746@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes Hi! As mentioned in PR63892, with the addition of ICF the sibcall-{3,4}.c tests no longer test what they meant to test. This patch duplicates the tests and adds a volatile var bump in just one of the functions so that ICF can't be performed and the tests really test sibcalls rather than say tail recursion. Regtested on x86_64-linux and i686-linux, ok for trunk? 2015-02-20 Jakub Jelinek * gcc.dg/sibcall-9.c: New test. * gcc.dg/sibcall-10.c: New test. Jakub --- gcc/testsuite/gcc.dg/sibcall-9.c.jj 2015-02-20 13:18:23.235665924 +0100 +++ gcc/testsuite/gcc.dg/sibcall-9.c 2015-02-20 13:19:44.830335968 +0100 @@ -0,0 +1,82 @@ +/* Simple check that sibling calls are performed from a + void non-leaf-function taking one int argument calling a function which + is about the same as itself. + + Copyright (C) 2002 Free Software Foundation Inc. + Contributed by Hans-Peter Nilsson */ + +/* { dg-do run { xfail { { cris-*-* crisv32-*-* h8300-*-* hppa*64*-*-* m32r-*-* mcore-*-* mn10300-*-* msp430*-*-* nds32*-*-* xstormy16-*-* v850*-*-* vax-*-* xtensa*-*-* } || { arm*-*-* && { ! arm32 } } } } } */ +/* -mlongcall disables sibcall patterns. */ +/* { dg-skip-if "" { powerpc*-*-* } { "-mlongcall" } { "" } } */ +/* { dg-options "-O2 -foptimize-sibling-calls" } */ + +/* The option -foptimize-sibling-calls is the default, but serves as + marker. This test is xfailed on targets without sibcall patterns + (except targets where the test does not work due to the return address + not saved on the regular stack). */ + +extern void abort (void); +extern void exit (int); + +/* Sibcalls are not supported in MIPS16 mode, which has direct calls but + not direct jumps. */ +#ifdef __mips +#define ATTR __attribute__((nomips16)) +#else +#define ATTR +#endif + +static ATTR void recurser_void1 (int); +static ATTR void recurser_void2 (int); +extern void track (int); +volatile int v; + +int main () +{ + recurser_void1 (0); + if (v != 5) + abort (); + exit (0); +} + +/* The functions should get the same stack-frame, and best way to make it + reasonably sure is to make them have the same contents (regarding the + n tests). */ + +static void __attribute__((noinline)) ATTR +recurser_void1 (int n) +{ + if (n == 0 || n == 7 || n == 8) + track (n); + + if (n == 10) + return; + + recurser_void2 (n + 1); +} + +static void __attribute__((noinline)) ATTR +recurser_void2 (int n) +{ + if (n == 0 || n == 7 || n == 8) + track (n); + + if (n == 10) + return; + + v++; + recurser_void1 (n + 1); +} + +void *trackpoint; + +void __attribute__ ((noinline)) +track (int n) +{ + char stackpos[1]; + + if (n == 0) + trackpoint = stackpos; + else if ((n != 7 && n != 8) || trackpoint != stackpos) + abort (); +} --- gcc/testsuite/gcc.dg/sibcall-10.c.jj 2015-02-20 13:19:51.170232631 +0100 +++ gcc/testsuite/gcc.dg/sibcall-10.c 2015-02-20 13:20:50.570264437 +0100 @@ -0,0 +1,83 @@ +/* Simple check that sibling calls are performed from a + void non-leaf-function taking no arguments calling a function which + is about the same as itself. + + Copyright (C) 2002 Free Software Foundation Inc. + Contributed by Hans-Peter Nilsson */ + +/* { dg-do run { xfail { { cris-*-* crisv32-*-* h8300-*-* hppa*64*-*-* m32r-*-* mcore-*-* mn10300-*-* msp430*-*-* nds32*-*-* xstormy16-*-* v850*-*-* vax-*-* xtensa*-*-* } || { arm*-*-* && { ! arm32 } } } } } */ +/* -mlongcall disables sibcall patterns. */ +/* { dg-skip-if "" { powerpc*-*-* } { "-mlongcall" } { "" } } */ +/* { dg-options "-O2 -foptimize-sibling-calls" } */ + +/* The option -foptimize-sibling-calls is the default, but serves as + marker. This test is xfailed on targets without sibcall patterns + (except targets where the test does not work due to the return address + not saved on the regular stack). */ + +extern void abort (void); +extern void exit (int); + +/* Sibcalls are not supported in MIPS16 mode, which has direct calls but + not direct jumps. */ +#ifdef __mips +#define ATTR __attribute__((nomips16)) +#else +#define ATTR +#endif + +static ATTR void recurser_void1 (void); +static ATTR void recurser_void2 (void); +extern void track (void); +volatile int v; + +int n = 0; +int main () +{ + recurser_void1 (); + if (v != 5) + abort (); + exit (0); +} + +/* The functions should get the same stack-frame, and best way to make it + reasonably sure is to make them have the same contents (regarding the + n tests). */ + +static void __attribute__((noinline)) ATTR +recurser_void1 (void) +{ + if (n == 0 || n == 7 || n == 8) + track (); + + if (n == 10) + return; + n++; + recurser_void2 (); +} + +static void __attribute__((noinline)) ATTR +recurser_void2 (void) +{ + if (n == 0 || n == 7 || n == 8) + track (); + + if (n == 10) + return; + n++; + v++; + recurser_void1 (); +} + +void *trackpoint; + +void __attribute__ ((noinline)) +track () +{ + char stackpos[1]; + + if (n == 0) + trackpoint = stackpos; + else if ((n != 7 && n != 8) || trackpoint != stackpos) + abort (); +}