From patchwork Thu Feb 21 03:19:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Bergner X-Patchwork-Id: 1045717 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-496787-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="CggY4WcU"; dkim-atps=neutral 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 444fqP2cTrz9s2R for ; Thu, 21 Feb 2019 14:20:15 +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:to:cc :from:subject:date:mime-version:content-type :content-transfer-encoding:message-id; q=dns; s=default; b=FlTg+ I1/dhOKy1JQSoqGR+N3jbWcpMxlimXyO+2A6K8qO8/nCi41njZhdoQUB0JnrHVNg UOq2BxirNq2dukZM8lGaScHuZHFjEQ5QwROu1SmYS9dKAKzu3BzlEoXuV+uZduDQ 5FvqEPX2fZD9NtV5+C1f4U0XW5OgH1yhofCyII= 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:to:cc :from:subject:date:mime-version:content-type :content-transfer-encoding:message-id; s=default; bh=wDuAjDp52XK LpI6S+e3EVRpdcmc=; b=CggY4WcUTF8Egfd176JlIrvSIkupSEjjkQ/ZtTv1Pz5 VpQHlAxBhUWlyLYU2H3kp1MkB8d82q+XNOTU3AEju6dMCG2vjp5mkhbSiSLKAgCp 83QqJh61jY/cWofwS5WrU8EC6FCK39WQM6EhYC+BUg/tq1XnAtIfsDNXj0t6z17A = Received: (qmail 41179 invoked by alias); 21 Feb 2019 03:20: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 41133 invoked by uid 89); 21 Feb 2019 03:20:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.3 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_NUMSUBJECT, KHOP_DYNAMIC, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=65289, exposes X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 21 Feb 2019 03:20:04 +0000 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x1L3JUCC043645 for ; Wed, 20 Feb 2019 22:20:03 -0500 Received: from e15.ny.us.ibm.com (e15.ny.us.ibm.com [129.33.205.205]) by mx0b-001b2d01.pphosted.com with ESMTP id 2qsg4080vy-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 20 Feb 2019 22:20:02 -0500 Received: from localhost by e15.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 21 Feb 2019 03:20:02 -0000 Received: from b01cxnp23034.gho.pok.ibm.com (9.57.198.29) by e15.ny.us.ibm.com (146.89.104.202) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 21 Feb 2019 03:20:00 -0000 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x1L3JxCC21496018 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 21 Feb 2019 03:19:59 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8EF63AE05F; Thu, 21 Feb 2019 03:19:59 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 204AAAE062; Thu, 21 Feb 2019 03:19:59 +0000 (GMT) Received: from otta.local (unknown [9.85.128.199]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP; Thu, 21 Feb 2019 03:19:58 +0000 (GMT) To: GCC Patches Cc: Segher Boessenkool , Alan Modra From: Peter Bergner Subject: [PATCH, asmcons] Fix PR rtl-optimization/89313: ICE in process_alt_operands, at lra-constraints.c:2962 Date: Wed, 20 Feb 2019 21:19:58 -0600 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 x-cbid: 19022103-0068-0000-0000-00000397239B X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010635; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000281; SDB=6.01164064; UDB=6.00607854; IPR=6.00944650; MB=3.00025673; MTD=3.00000008; XFM=3.00000015; UTC=2019-02-21 03:20:01 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19022103-0069-0000-0000-00004793A6A2 Message-Id: <9875286e-cc51-abed-626a-4b36717e52e3@linux.ibm.com> X-IsSubscribed: yes PR89313 exposes a bug in the asmcons pass where it replaces input operands with matching constraints with their associated output operands, as well as all other uses of its pseudo registers. This is normally fine. However, if the matched output operand is marked as early clobber, then we cannot replace the uses of 'input' that do not have matching constraints, since they by definition conflict with the early clobber output operand and could be clobbered if assigned to the same register as the output operand. The patch below fixes the bug by only doing the input pseudo replacement if the output operand is not early clobber or the input operand is known to be a matching constraint. This passed bootstrap and regression testing with no regressions on both x86_64-linux and powerpc64le-linux. Ok for mainline? Peter gcc/ PR rtl-optimization/89313 * function.c (matching_constraint_num): New static function. (match_asm_constraints_1): Use it. Fixup white space and comment. Don't replace inputs with non-matching constraints which conflict with early clobber outputs. gcc/testsuite/ PR rtl-optimization/89313 * gcc.dg/pr89313.c: New test. Index: gcc/function.c =================================================================== --- gcc/function.c (revision 268883) +++ gcc/function.c (working copy) @@ -6395,6 +6395,36 @@ make_pass_thread_prologue_and_epilogue ( } +/* If CONSTRAINT is a matching constraint, then return its number. + Otherwise, return -1. */ + +static int +matching_constraint_num (const char *constraint) +{ + int match; + + if (*constraint == '%') + constraint++; + + switch (*constraint) + { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + { + char *end; + match = strtoul (constraint, &end, 10); + if (end == constraint) + match = -1; + break; + } + + default: + match = -1; + break; + } + return match; +} + /* This mini-pass fixes fall-out from SSA in asm statements that have in-out constraints. Say you start with @@ -6453,14 +6483,10 @@ match_asm_constraints_1 (rtx_insn *insn, rtx input, output; rtx_insn *insns; const char *constraint = ASM_OPERANDS_INPUT_CONSTRAINT (op, i); - char *end; int match, j; - if (*constraint == '%') - constraint++; - - match = strtoul (constraint, &end, 10); - if (end == constraint) + match = matching_constraint_num (constraint); + if (match < 0) continue; gcc_assert (match < noutputs); @@ -6477,14 +6503,14 @@ match_asm_constraints_1 (rtx_insn *insn, /* We can't do anything if the output is also used as input, as we're going to overwrite it. */ for (j = 0; j < ninputs; j++) - if (reg_overlap_mentioned_p (output, RTVEC_ELT (inputs, j))) + if (reg_overlap_mentioned_p (output, RTVEC_ELT (inputs, j))) break; if (j != ninputs) continue; /* Avoid changing the same input several times. For asm ("" : "=mr" (out1), "=mr" (out2) : "0" (in), "1" (in)); - only change in once (to out1), rather than changing it + only change it once (to out1), rather than changing it first to out1 and afterwards to out2. */ if (i > 0) { @@ -6502,6 +6528,9 @@ match_asm_constraints_1 (rtx_insn *insn, end_sequence (); emit_insn_before (insns, insn); + constraint = ASM_OPERANDS_OUTPUT_CONSTRAINT(SET_SRC(p_sets[match])); + bool early_clobber_p = strchr (constraint, '&') != NULL; + /* Now replace all mentions of the input with output. We can't just replace the occurrence in inputs[i], as the register might also be used in some other input (or even in an address of an @@ -6523,7 +6552,14 @@ match_asm_constraints_1 (rtx_insn *insn, value, but different pseudos) where we formerly had only one. With more complicated asms this might lead to reload failures which wouldn't have happen without this pass. So, iterate over - all operands and replace all occurrences of the register used. */ + all operands and replace all occurrences of the register used. + + However, if one or more of the 'input' uses have a non-matching + constraint and the matched output operand is an early clobber + operand, then do not replace the input operand, since by definition + it conflicts with the output operand and cannot share the same + register. See PR89313 for details. */ + for (j = 0; j < noutputs; j++) if (!rtx_equal_p (SET_DEST (p_sets[j]), input) && reg_overlap_mentioned_p (input, SET_DEST (p_sets[j]))) @@ -6531,8 +6567,13 @@ match_asm_constraints_1 (rtx_insn *insn, input, output); for (j = 0; j < ninputs; j++) if (reg_overlap_mentioned_p (input, RTVEC_ELT (inputs, j))) - RTVEC_ELT (inputs, j) = replace_rtx (RTVEC_ELT (inputs, j), - input, output); + { + if (!early_clobber_p + || match == matching_constraint_num + (ASM_OPERANDS_INPUT_CONSTRAINT (op, j))) + RTVEC_ELT (inputs, j) = replace_rtx (RTVEC_ELT (inputs, j), + input, output); + } changed = true; } Index: gcc/testsuite/gcc.dg/pr89313.c =================================================================== --- gcc/testsuite/gcc.dg/pr89313.c (nonexistent) +++ gcc/testsuite/gcc.dg/pr89313.c (working copy) @@ -0,0 +1,26 @@ +/* PR rtl-optimization/89313 */ +/* { dg-do compile { target aarch64*-*-* arm*-*-* i?86-*-* powerpc*-*-* s390*-*-* x86_64-*-* } } */ +/* { dg-options "-O2" } */ + +#if defined (__aarch64__) +# define REG "x0" +#elif defined (__arm__) +# define REG "r0" +#elif defined (__i386__) +# define REG "%eax" +#elif defined (__powerpc__) +# define REG "r3" +#elif defined (__s390__) +# define REG "0" +#elif defined (__x86_64__) +# define REG "rax" +#endif + +long +bug (long arg) +{ + register long output asm (REG); + long input = arg; + asm ("blah %0, %1, %2" : "=&r" (output) : "r" (input), "0" (input)); + return output; +}