From patchwork Thu Feb 4 21:29:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vladimir Makarov X-Patchwork-Id: 1436312 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=OStFgs28; dkim-atps=neutral Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DWsBv24qrz9sWw for ; Fri, 5 Feb 2021 08:29:43 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3D681386F03E; Thu, 4 Feb 2021 21:29:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D681386F03E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1612474180; bh=+d4AuFg/RteQ7309M2dCqYnXOeZS6WAPpW3iMy735O4=; h=Subject:To:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=OStFgs28IlEyQBWKMqdnk51yPLj087jyok/yA2s4dZVRHDXFG3vdiOJPjpkpU8jis KL3DRAoUTYpDvwmrEVwqmFea75qTRFDrHYTrd6ESAp14eceGZE1MBMRg9wek5CVcSd blGDC8uT1b1hT7NiFjR1Sgzm049UR3w1+hpoX0QE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id 01E333857023 for ; Thu, 4 Feb 2021 21:29:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 01E333857023 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-294-ZE8K9tdmMj-FZVXnJQQiZQ-1; Thu, 04 Feb 2021 16:29:33 -0500 X-MC-Unique: ZE8K9tdmMj-FZVXnJQQiZQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 33EB71800D50 for ; Thu, 4 Feb 2021 21:29:32 +0000 (UTC) Received: from [10.10.112.237] (ovpn-112-237.rdu2.redhat.com [10.10.112.237]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0791660C9B; Thu, 4 Feb 2021 21:29:30 +0000 (UTC) Subject: [PATCH] PR98096: inline-asm: Take inout operands into account for access to labels by names. To: "gcc-patches@gcc.gnu.org" , "Law, Jeff" Message-ID: <7fe3a966-2309-05b1-b517-a8d523821a53@redhat.com> Date: Thu, 4 Feb 2021 16:29:30 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Vladimir Makarov via Gcc-patches From: Vladimir Makarov Reply-To: Vladimir Makarov Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" The following patch solves    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98096 The patch is for a new GCC extension -- asm goto with output reloads. GCC splits inout operands (with constraint "+") into output and new matched input operands during gimplfication.  Addressing input or output operands by name or number is not a problem as the new input operands are added at the end of existing input operands. However it became a problem for labels in asm goto with output reloads.  Addressing labels should take into account the added matched input operands.  The patch solves the problem. The patch was successfully bootstrapped and tested on x86-64. Is it ok to commit into the trunk? diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 8daa1c67974..71b35252b84 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -10656,16 +10656,23 @@ should use @samp{+} constraint modifier meaning that the operand is input and output one. With this modifier you will have the correct values on all possible paths from the @code{asm goto}. -To reference a label in the assembler template, -prefix it with @samp{%l} (lowercase @samp{L}) followed -by its (zero-based) position in @var{GotoLabels} plus the number of input -operands. For example, if the @code{asm} has three inputs and references two -labels, refer to the first label as @samp{%l3} and the second as @samp{%l4}). - -Alternately, you can reference labels using the actual C label name enclosed -in brackets. For example, to reference a label named @code{carry}, you can -use @samp{%l[carry]}. The label must still be listed in the @var{GotoLabels} -section when using this approach. +To reference a label in the assembler template, prefix it with +@samp{%l} (lowercase @samp{L}) followed by its (zero-based) position +in @var{GotoLabels} plus the number of input and output operands. +Output operand with constraint modifier @samp{+} is counted as two +operands because it is considered as one output and one input operand. +For example, if the @code{asm} has three inputs, one output operand +with constraint modifier @samp{+} and one output operand with +constraint modifier @samp{=} and references two labels, refer to the +first label as @samp{%l6} and the second as @samp{%l7}). + +Alternately, you can reference labels using the actual C label name +enclosed in brackets. For example, to reference a label named +@code{carry}, you can use @samp{%l[carry]}. The label must still be +listed in the @var{GotoLabels} section when using this approach. It +is better to use the named references for labels as in this case you +can avoid counting input and output operands and special treatment of +output operands with constraint modifier @samp{+}. Here is an example of @code{asm goto} for i386: diff --git a/gcc/stmt.c b/gcc/stmt.c index bd836d8f65f..f52ffaf8e75 100644 --- a/gcc/stmt.c +++ b/gcc/stmt.c @@ -611,7 +611,7 @@ static char * resolve_operand_name_1 (char *p, tree outputs, tree inputs, tree labels) { char *q; - int op; + int op, op_inout; tree t; /* Collect the operand name. */ @@ -624,11 +624,14 @@ resolve_operand_name_1 (char *p, tree outputs, tree inputs, tree labels) *q = '\0'; /* Resolve the name to a number. */ - for (op = 0, t = outputs; t ; t = TREE_CHAIN (t), op++) + for (op_inout = op = 0, t = outputs; t ; t = TREE_CHAIN (t), op++) { tree name = TREE_PURPOSE (TREE_PURPOSE (t)); if (name && strcmp (TREE_STRING_POINTER (name), p) == 0) goto found; + tree constraint = TREE_VALUE (TREE_PURPOSE (t)); + if (constraint && strchr (TREE_STRING_POINTER (constraint), '+') != NULL) + op_inout++; } for (t = inputs; t ; t = TREE_CHAIN (t), op++) { @@ -636,6 +639,7 @@ resolve_operand_name_1 (char *p, tree outputs, tree inputs, tree labels) if (name && strcmp (TREE_STRING_POINTER (name), p) == 0) goto found; } + op += op_inout; for (t = labels; t ; t = TREE_CHAIN (t), op++) { tree name = TREE_PURPOSE (t); diff --git a/gcc/testsuite/gcc.c-torture/compile/pr98096.c b/gcc/testsuite/gcc.c-torture/compile/pr98096.c new file mode 100644 index 00000000000..95ad55c81aa --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr98096.c @@ -0,0 +1,10 @@ +/* Test for correct naming of label operands in asm goto in case of presence of + input/output operands. */ +/* { dg-do compile } */ +int i, j; +int f(void) { + asm goto ("# %0 %2" : "+r" (i) ::: jmp); + i += 2; + asm goto ("# %0 %1 %l[jmp]" : "+r" (i), "+r" (j) ::: jmp); + jmp: return i; +}