From patchwork Sun May 28 12:31:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Segher Boessenkool X-Patchwork-Id: 767879 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 3wbK4C0T8Dz9s2P for ; Sun, 28 May 2017 22:31:37 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="oMcsOCV1"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=R+TqrNqIruwv zQ+Fh1Lf3TjwlFZVlQshrNSvNRlb9o2f+QI9hO4zw2Mstba0XVHw8hT2DK46kRio QbiHxXKe+828C5usJK4xltEd0SNRz/CSdKo81HLT8SEcniKj4cTgBO46uJM6sWWH VrZmpBhA5tZXgqHfvuZQ2J8BcB1crbI= 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:from :to:cc:subject:date:message-id; s=default; bh=XjfdTpJ8Fltk5CzqQA H0ZoCymDI=; b=oMcsOCV1R4QdvCj3Q8T99dCZ9QaAE335Hf+zE7jqC7Tkj3l7f6 tuNgigFuyoFKjdc87hPbI+axdp5m1lupFeGXVq2cuwbJ+48SctDY+eAi/CKJBMpI BBqhNoDRn5XWkaU17Kp63QSohWP8OMK7tz6h08jasVRP1W7yUG2owDoLM= Received: (qmail 27435 invoked by alias); 28 May 2017 12:31:19 -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 27407 invoked by uid 89); 28 May 2017 12:31:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-23.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=emitting X-HELO: gcc1-power7.osuosl.org Received: from gcc1-power7.osuosl.org (HELO gcc1-power7.osuosl.org) (140.211.15.137) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 28 May 2017 12:31:15 +0000 Received: by gcc1-power7.osuosl.org (Postfix, from userid 10019) id 7C8791C0687; Sun, 28 May 2017 12:31:15 +0000 (UTC) From: Segher Boessenkool To: gcc-patches@gcc.gnu.org Cc: Segher Boessenkool Subject: [PATCH] Fix expand_builtin_atomic_fetch_op for pre-op (PR80902) Date: Sun, 28 May 2017 12:31:12 +0000 Message-Id: X-IsSubscribed: yes __atomic_add_fetch adds a value to some memory, and returns the result. If there is no direct support for this, expand_builtin_atomic_fetch_op is asked to implement this as __atomic_fetch_add (which returns the original value of the mem), followed by the addition. Now, the __atomic_add_fetch could have been a tail call, but we shouldn't perform the __atomic_fetch_add as a tail call: following code would not be executed, and in fact thrown away because there is a barrier after tail calls. This fixes it. Tested on powerpc64-linux {-m32,-m64}. Is this okay for trunk? Segher 2017-05-28 Segher Boessenkool PR middle-end/80902 * builtins.c (expand_builtin_atomic_fetch_op): If emitting code after a call, force the call to not be a tail call. --- gcc/builtins.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gcc/builtins.c b/gcc/builtins.c index 4f6c9c4..3a70693 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -6079,6 +6079,12 @@ expand_builtin_atomic_fetch_op (machine_mode mode, tree exp, rtx target, gcc_assert (TREE_OPERAND (addr, 0) == fndecl); TREE_OPERAND (addr, 0) = builtin_decl_explicit (ext_call); + /* If we will emit code after the call, the call can not be a tail call. + If it is emitted as a tail call, a barrier is emitted after it, and + then all trailing code is removed. */ + if (!ignore) + CALL_EXPR_TAILCALL (exp) = 0; + /* Expand the call here so we can emit trailing code. */ ret = expand_call (exp, target, ignore);