From patchwork Wed Nov 16 08:45:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrill Tkachov X-Patchwork-Id: 695470 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 3tJdBw1C4Lz9t26 for ; Wed, 16 Nov 2016 19:45:59 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="FJgqpQca"; 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 :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=fj9UMnzANm3pCP2qR3ksstfyBHg8Pgc90zFuwdXvzxf y5x9g4SNSVORVFH/AIgGTCG0+EzHeWFL6RZwthdJXYUzAiS8RDmQ6Ms1MkNKJsIW MDq2u0TiHhd3OhCM8t+GWpIg33K+YHt+fE94F/n7TNCU0DMlA9QCtUdYwjwvxKyo = 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 :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=vGl3LzAfnArqUQYXD7324aG9Ig8=; b=FJgqpQcaIIxOKpA3o gjT40Ua+SVXGu7jm7t7dCkP6O3WvKMHBrYKM811rC1BAOr3pDaz1tmP+Tk945JjX ByPyo34UdXdqQ6uPzCx4goG/VE+tHwZzHs+RHMOu9KFdsU/It7MLQDew/SmvqgTy ECZBHS+5BqXy+vvk6oG1lPpWX0= Received: (qmail 21918 invoked by alias); 16 Nov 2016 08:45:51 -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 21905 invoked by uid 89); 16 Nov 2016 08:45:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.8 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Cc, translates, 2016-11-16, interest X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 16 Nov 2016 08:45:40 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DEA6913D5; Wed, 16 Nov 2016 00:45:37 -0800 (PST) Received: from [10.2.207.77] (e100706-lin.cambridge.arm.com [10.2.207.77]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4D6263F24D; Wed, 16 Nov 2016 00:45:37 -0800 (PST) Message-ID: <582C1CAF.4050402@foss.arm.com> Date: Wed, 16 Nov 2016 08:45:35 +0000 From: Kyrill Tkachov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: GCC Patches CC: Ramana Radhakrishnan , Richard Earnshaw Subject: [PATCH][ARM] PR target/78364: Add proper restrictions to zero and sign_extract patterns operands Hi all, This patch fixes the arm build failure due to out of range ubfx operands. Combine now more aggressively generates zero_extracts and it's up to the backend to reject invalid bit offsets and widths. And arm seems to suffer from the same problems as aarch64 and s390 did in PR 77822. My ARMv7-A and ARMv7-R Architecture Reference Manual version C.c in section A8.8.246 says that the bit offset () should be in the range 0 to 31 whereas the width should be in the range 1 to 32 - . Same for SBFX. This patch directly translates those restrictions into range checks on operands 2 and 3 of the relevant patterns. With this patch the arm build succeeds. Bootstrapped and tested on arm-none-linux-gnueabihf. Committing to trunk in the interest of fixing the build. Thanks, Kyrill 2016-11-16 Kyrylo Tkachov PR target/78364 * config/arm/arm.md (*extv_reg): Restrict operands 2 and 3 to the proper ranges for an SBFX instruction. (extzv_t2): Likewise for UBFX. commit b9ea5a6274834cbc469988040a807093156b52cf Author: Kyrylo Tkachov Date: Tue Nov 15 15:53:21 2016 +0000 [ARM] PR target/78364: Add proper restrictions to zero and sign_extract patterns operands diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md index ac3ef15..87b5ea6 100644 --- a/gcc/config/arm/arm.md +++ b/gcc/config/arm/arm.md @@ -4561,9 +4561,11 @@ (define_insn "unaligned_storehi" (define_insn "*extv_reg" [(set (match_operand:SI 0 "s_register_operand" "=r") (sign_extract:SI (match_operand:SI 1 "s_register_operand" "r") - (match_operand:SI 2 "const_int_M_operand" "M") - (match_operand:SI 3 "const_int_M_operand" "M")))] - "arm_arch_thumb2" + (match_operand:SI 2 "const_int_operand" "n") + (match_operand:SI 3 "const_int_operand" "n")))] + "arm_arch_thumb2 + && IN_RANGE (INTVAL (operands[3]), 0, 31) + && IN_RANGE (INTVAL (operands[2]), 1, 32 - INTVAL (operands[3]))" "sbfx%?\t%0, %1, %3, %2" [(set_attr "length" "4") (set_attr "predicable" "yes") @@ -4574,9 +4576,11 @@ (define_insn "*extv_reg" (define_insn "extzv_t2" [(set (match_operand:SI 0 "s_register_operand" "=r") (zero_extract:SI (match_operand:SI 1 "s_register_operand" "r") - (match_operand:SI 2 "const_int_M_operand" "M") - (match_operand:SI 3 "const_int_M_operand" "M")))] - "arm_arch_thumb2" + (match_operand:SI 2 "const_int_operand" "n") + (match_operand:SI 3 "const_int_operand" "n")))] + "arm_arch_thumb2 + && IN_RANGE (INTVAL (operands[3]), 0, 31) + && IN_RANGE (INTVAL (operands[2]), 1, 32 - INTVAL (operands[3]))" "ubfx%?\t%0, %1, %3, %2" [(set_attr "length" "4") (set_attr "predicable" "yes")