From patchwork Tue Jul 9 06:36:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 168722 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp8139874ilk; Mon, 8 Jul 2019 23:37:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWpNF43fsadWEjpqMwMvtCgLg1fzyVoseMUPlV5RN8AyNktXBJRWrq3xq9qVQc854kM4OH X-Received: by 2002:a17:90a:2305:: with SMTP id f5mr32242678pje.128.1562654256179; Mon, 08 Jul 2019 23:37:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562654256; cv=none; d=google.com; s=arc-20160816; b=rkWoLqC9D5PsmTiHnOyJgAK3wvxlH8766WykS46Xw2e36X2Iv8xf36C+qGCcvLWQTO I4E9wOHmnl2JJrLDY3Y3H4q+VvwxTN6OxqnA2Kk2NikvQQHxKUiPF0cJ/IyKmfmQKMxS JweTeSaHaBC7Uu/R3/GUsgwdssIlZnhxoBZVFsv/W9HR740ON/R0PvnH6V0zh/mZucBN AzpnJ/kHkPX0kekjJvWUG0yfaRtekd4nEikjHzVojsx9LpPFGS6BXRsxLg36Zk4uzDii J3/eojVV/2volNfA1qu39xkthi0dVa4+ceJvxEMYsb3gbzBsPo0DGLBBkf7G0i7GfWVz 2C2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:mime-version:dkim-signature :delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature; bh=4Ovlmbl25PD5va0428xSxjNxUs+/NYOUNzAG4qqNKeg=; b=BkAWMeKcwlUPgzP3eF5mpRuSPDeoO9zBrDfiHU2ckrip9rKqSKJELchzEImh5kXeTY 7/O06S1BGZW+LLSv+CrR+j3a1z/cLPRcj1yd/d+fvLmRDfO4e8wxCgB5m6Bdtcailw1o ZX4ECh6IC+FGlxYHZ2gjM+tUcYZVJgUnOiv//1lNn/NZt5XlbgyYotT+kZ8lMy8sYqJF Kiyyvxfl738UTqg8yFVGQPYKSt488DAb2RzKYafGlx7t4lEsT94US1YAGwjGROttlxic suDqYYyRob6JXGc7ayejuirEYyxKyAIt6+Vy6M0YZcOEjLeFtFFQA4vHylOf0ULxo9V3 UcHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Y3Fe2YrA; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=VxXsVxGo; spf=pass (google.com: domain of gcc-patches-return-504667-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-504667-patch=linaro.org@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id v64si8534700pgv.476.2019.07.08.23.37.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jul 2019 23:37:36 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-504667-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Y3Fe2YrA; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=VxXsVxGo; spf=pass (google.com: domain of gcc-patches-return-504667-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-504667-patch=linaro.org@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=eq2igL1ylPaFa+DdUVZv7v4FznLqaYuJQQd7yr3K6H3yBJ mtedynIVoR1qj89yDnmQeZejKN3DsxUN7xwenZTQ3RtHIWDwG+k4fjqQN7mDYVTq Sf2WPzQiDTSMK8W9ZUgeQ4oXsWF+z/yqp1WvylYidQA831dKnv3zLGoEQcUXU= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=zKaN/LLECPxWYSIKjEXYCOwEHBc=; b=Y3Fe2YrACNvYA1gS/Aea HZWr4yBylMVqE0PpvGNgc40COltVLZxh/MpOQZkvrGoPFEkNVEXOgowPEizVmV4E pGXAj0S7mI6z7aecnbiNv44uvXYTy3RZA9AS1yaMkf4w/C320IFPqh9i3KvYJtEj wfX3JzNI4h+cFu+bqzq+uyo= Received: (qmail 97297 invoked by alias); 9 Jul 2019 06:37:24 -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 97288 invoked by uid 89); 9 Jul 2019 06:37:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=HX-HELO:sk:mail-lj, HX-Received:864d, HX-Received:sk:i13mr12 X-HELO: mail-lj1-f173.google.com Received: from mail-lj1-f173.google.com (HELO mail-lj1-f173.google.com) (209.85.208.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 09 Jul 2019 06:37:22 +0000 Received: by mail-lj1-f173.google.com with SMTP id r9so18381081ljg.5 for ; Mon, 08 Jul 2019 23:37:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:from:date:message-id:subject:to; bh=rJ7Z18j48bJfyLbjqtG5zhlvHQpdNRI54kyeikD9u4g=; b=VxXsVxGoRFW++qHpkncAiscnGo2iAcT6aQP19EJ4TSk3LWoiiQTZ6hQrpDJyWn8o+n SeXPhtgagqM0Lkn+9PVxPvCCMi/nJQWlW4v0t+pXHf0o3hFvyjDdaYnTO/XuyuouFnkH 8ofIbCY974eNVPxDCV1mZQDfmfN2B3VyZLt7jse91GjTLv5D6Pp4wbEbSUUT2kH+kgVz hj0r7BhDsJXsxXJaBNIlApmAVJc6gYE8EgnChetOt75ohjd+TTZdOXYZIBNsX5SEUZSC mJ0QFFQ1t/yfExB5GelHJZLpmgb/zp1pi1gFR8/DMtw55YblPL33a2PHq7BGfJrGKGjS xGIw== MIME-Version: 1.0 From: Prathamesh Kulkarni Date: Tue, 9 Jul 2019 12:06:44 +0530 Message-ID: Subject: PR90723 To: Richard Sandiford , gcc Patches X-IsSubscribed: yes Hi, For following test-case: typedef double v4df __attribute__ ((vector_size (32))); void foo(v4df); int main () { volatile v4df x1; x1 = (v4df) { 10.0, 20.0, 30.0, 40.0 }; foo (x1); return 0; } Compiling with -msve-vector-bits=256, the compiler goes into infinite recursion and eventually segfaults due to stack overflow. This happens during expansion of: x1.0_1 ={v} x1; aarch64_expand_sve_mem_move calls aarch64_emit_sve_pred_move with dest = (reg:VNx2DF 93) and src = (mem/u/c:VNx2DF (plus:DI (reg/f:DI 94) (const_int 32 [0x20])) [0 S32 A128]) aarch64_emit_sve_pred_move calls expand_insn with above ops. Eventually we hit EXPAND_INPUT case in maybe_legitimize_operand for src (opno == 2) Since the operand is marked with volatile, and volatile_ok is set to false, insn_operand_matches return false and we call: op->value = copy_to_mode_reg (mode, op->value); break; copy_to_mode_reg however, creates a fresh register and calls emit_move_insn: rtx temp = gen_reg_rtx (mode); if (x != temp) emit_move_insn (temp, x); and we again end up in aarch64_emit_sve_pred_move, with dest assigned the new register and src remaining unchanged, and thus the cycle continues. As suggested by Richard, the attached patch temporarily sets volatile_ok to true using RAII class volatile_ok_temp in aarch64_emit_sve_pred_move which avoids the recursion. Bootstrap + tested on x86_64-unknown-linux-gnu, aarch64-linux-gnu. Cross-testing with SVE in progress. OK to commit ? Thanks, Prathamesh 2019-07-09 Prathamesh Kulkarni PR target/90723 * recog.h (volatile_ok_temp): New class. * config/aarch64/aarch64.c (aarch64_emit_sve_pred_move): Set volatile_ok temporarily to true using volatile_ok_temp. * expr.c (emit_block_move_via_cpymem): Likewise. * optabs.c (maybe_legitimize_operand): Likewise. diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 5a923ca006b..50afba1a2b6 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -3457,6 +3457,7 @@ aarch64_emit_sve_pred_move (rtx dest, rtx pred, rtx src) create_output_operand (&ops[0], dest, mode); create_input_operand (&ops[1], pred, GET_MODE(pred)); create_input_operand (&ops[2], src, mode); + volatile_ok_temp v(true); expand_insn (code_for_aarch64_pred_mov (mode), 3, ops); } diff --git a/gcc/expr.c b/gcc/expr.c index 4acf250dd3c..87720875864 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -1732,8 +1732,6 @@ emit_block_move_via_cpymem (rtx x, rtx y, rtx size, unsigned int align, unsigned HOST_WIDE_INT max_size, unsigned HOST_WIDE_INT probable_max_size) { - int save_volatile_ok = volatile_ok; - if (expected_align < align) expected_align = align; if (expected_size != -1) @@ -1745,7 +1743,7 @@ emit_block_move_via_cpymem (rtx x, rtx y, rtx size, unsigned int align, } /* Since this is a move insn, we don't care about volatility. */ - volatile_ok = 1; + volatile_ok_temp v(true); /* Try the most limited insn first, because there's no point including more than one in the machine description unless @@ -1809,14 +1807,10 @@ emit_block_move_via_cpymem (rtx x, rtx y, rtx size, unsigned int align, create_fixed_operand (&ops[8], NULL); } if (maybe_expand_insn (code, nops, ops)) - { - volatile_ok = save_volatile_ok; - return true; - } + return true; } } - volatile_ok = save_volatile_ok; return false; } diff --git a/gcc/optabs.c b/gcc/optabs.c index 18ca7370917..1959087b7b3 100644 --- a/gcc/optabs.c +++ b/gcc/optabs.c @@ -7202,17 +7202,15 @@ maybe_legitimize_operand (enum insn_code icode, unsigned int opno, struct expand_operand *op) { machine_mode mode, imode; - bool old_volatile_ok, result; mode = op->mode; switch (op->type) { case EXPAND_FIXED: - old_volatile_ok = volatile_ok; - volatile_ok = true; - result = maybe_legitimize_operand_same_code (icode, opno, op); - volatile_ok = old_volatile_ok; - return result; + { + volatile_ok_temp v(true); + return maybe_legitimize_operand_same_code (icode, opno, op); + } case EXPAND_OUTPUT: gcc_assert (mode != VOIDmode); diff --git a/gcc/recog.h b/gcc/recog.h index 75cbbdc10ad..8a8eaf7e0c3 100644 --- a/gcc/recog.h +++ b/gcc/recog.h @@ -186,6 +186,22 @@ skip_alternative (const char *p) /* Nonzero means volatile operands are recognized. */ extern int volatile_ok; +/* RAII class for temporarily setting volatile_ok. */ + +class volatile_ok_temp +{ +public: + volatile_ok_temp(int value): save_volatile_ok (volatile_ok) + { + volatile_ok = value; + } + + ~volatile_ok_temp() { volatile_ok = save_volatile_ok; } + +private: + int save_volatile_ok; +}; + /* Set by constrain_operands to the number of the alternative that matched. */ extern int which_alternative;