From patchwork Thu Oct 10 22:16:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Wilson X-Patchwork-Id: 1174817 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-510704-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="oUhzANqs"; dkim=pass (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.b="E2jAxU42"; 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 46q58Y3fDMz9sDB for ; Fri, 11 Oct 2019 09:18:51 +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:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=mmh9WdEq26ol3YtV6j66d8PTkbYfMV64F3lUjBnnCWbb1/uGbImD8 2sjI7njvOTh/vomT8D3Mv9rkY/1/0dt3h738QzaXJlz9MIuamZurZ+G/HUtpIxxA wgm4vBFJsWWtP04ymdr9mL0DXiWh/yJa9omfswAY7tYcyFX5q6+k/k= 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:in-reply-to:references; s= default; bh=CjSVq+QMe40CxdrusVk40+tCF14=; b=oUhzANqs6LcJdHZyjmm0 r9Uzm+G1rLX7b5B6ctNnsUxLDqHQAZsqx/4ELt+5q1gc+r+KZEy8oLVtolBoh7iw D7KVxdUxfn8L8J5/4xyy0m8asdXe6mYxa2n2/HacD0eHoW18KgQ65+RDKt+pIU2H 55F7cN2sbgsH9STkWKZRAgg= Received: (qmail 93919 invoked by alias); 10 Oct 2019 22:18:44 -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 93911 invoked by uid 89); 10 Oct 2019 22:18:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=H*r:sk:mail-pg X-HELO: mail-pg1-f171.google.com Received: from mail-pg1-f171.google.com (HELO mail-pg1-f171.google.com) (209.85.215.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 10 Oct 2019 22:18:42 +0000 Received: by mail-pg1-f171.google.com with SMTP id p1so4547457pgi.4 for ; Thu, 10 Oct 2019 15:18:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lb3zTHcpiuZpdhVF/biG0bmGxTOnNWgA623DYaCTdIs=; b=E2jAxU42yLbxcAzHB5C1dCeDyRYHKX63+mvNJkAIIln6JQ34CnX0Cijf4orjoqTi+D V+iECPVkt1EXURJdmSL+NC7fFzt1hWzgW9ZO03r2Wls3RoqbLlvi1ysW+T0gkE748qRs Lc7h7k5yNnw0knNf9FqnoAXNxr1tG/UHTWjJdI800xyi2EecinbG0tk3yCJ6ap01Ifb0 r/bgO/S10VMsOx1c3lKozyT704r0mfLxSeIHUOM36xx22I0cZ1X15Xmt/HLOSK9gyxFI nY2Q9vzMJgYs2yxYzsBMW+apAGhUAMQkPdRK3RiztIMV2w6cbCN0fORi8VxvrBw2KdKA JT7A== Received: from rohan.sifive.com ([12.206.222.5]) by smtp.gmail.com with ESMTPSA id o64sm11934160pjb.24.2019.10.10.15.18.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 15:18:40 -0700 (PDT) From: Jim Wilson To: gcc-patches@gcc.gnu.org Cc: Jim Wilson Subject: [PATCH, v2] Extend subst to simplify CONST_INT inside SIGN_EXTEND. Date: Thu, 10 Oct 2019 15:16:36 -0700 Message-Id: <20191010221636.22199-1-jimw@sifive.com> In-Reply-To: <20191009201114.22083-1-jimw@sifive.com> References: <20191009201114.22083-1-jimw@sifive.com> X-IsSubscribed: yes This addresses PR 91860 which has four testcases triggering internal errors. The problem here is that in combine when handling debug insns, we are trying to substitute (sign_extend:DI (const_int 8160 [0x1fe0])) as the value for (reg:DI 78 [ _9 ]) in the debug insn (debug_insn 29 28 30 2 (var_location:QI d (subreg:QI (reg:DI 78 [ _9 ]) 0)) "tmp4.c":11:5 -1 (nil)) This eventually triggers an abort because 8160 is not a sign-extended QImode value. We should avoid creating the invalid RTL in the first place. In subst there is already code to avoid putting a CONST_INT inside a ZERO_EXTEND. This needs to be extended to also handle a SIGN_EXTEND the same way. This was tested with rv32/newlib and rv64/linux cross builds and make checks. There were no regressions. The new tests all fail for rv64 without the patch, and work with the patch. OK? Jim gcc/ PR rtl-optimization/91860 * combine.c (subst): If new_rtx is a constant, also check for SIGN_EXTEND when deciding whether to call simplify_unary_operation. gcc/testsuite/ PR rtl-optimization/91860 * gcc.dg/pr91860-1.c: New testcase. * gcc.dg/pr91860-2.c: New testcase. * gcc.dg/pr91860-3.c: New testcase. * gcc.dg/pr91860-4.c: New testcase. --- gcc/combine.c | 1 + gcc/testsuite/gcc.dg/pr91860-1.c | 18 ++++++++++++++++++ gcc/testsuite/gcc.dg/pr91860-2.c | 13 +++++++++++++ gcc/testsuite/gcc.dg/pr91860-3.c | 15 +++++++++++++++ gcc/testsuite/gcc.dg/pr91860-4.c | 24 ++++++++++++++++++++++++ 5 files changed, 71 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr91860-1.c create mode 100644 gcc/testsuite/gcc.dg/pr91860-2.c create mode 100644 gcc/testsuite/gcc.dg/pr91860-3.c create mode 100644 gcc/testsuite/gcc.dg/pr91860-4.c diff --git a/gcc/combine.c b/gcc/combine.c index d295a81abf9..92e4e5e6898 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -5680,6 +5680,7 @@ subst (rtx x, rtx from, rtx to, int in_dest, int in_cond, int unique_copy) } else if (CONST_SCALAR_INT_P (new_rtx) && (GET_CODE (x) == ZERO_EXTEND + || GET_CODE (x) == SIGN_EXTEND || GET_CODE (x) == FLOAT || GET_CODE (x) == UNSIGNED_FLOAT)) { diff --git a/gcc/testsuite/gcc.dg/pr91860-1.c b/gcc/testsuite/gcc.dg/pr91860-1.c new file mode 100644 index 00000000000..e715040e33d --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr91860-1.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-Og -fipa-cp -g --param=max-combine-insns=3" } */ + +char a; +int b; + +static void +bar (short d) +{ + d <<= __builtin_sub_overflow (0, d, &a); + b = __builtin_bswap16 (~d); +} + +void +foo (void) +{ + bar (21043); +} diff --git a/gcc/testsuite/gcc.dg/pr91860-2.c b/gcc/testsuite/gcc.dg/pr91860-2.c new file mode 100644 index 00000000000..7b44e648ca6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr91860-2.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-Og -fexpensive-optimizations -fno-tree-fre -g --param=max-combine-insns=4" } */ + +unsigned a, b, c; +void +foo (void) +{ + unsigned short e; + __builtin_mul_overflow (0, b, &a); + __builtin_sub_overflow (59347, 9, &e); + e <<= a & 5; + c = e; +} diff --git a/gcc/testsuite/gcc.dg/pr91860-3.c b/gcc/testsuite/gcc.dg/pr91860-3.c new file mode 100644 index 00000000000..2b488cc9048 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr91860-3.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-Og -g2 --param=max-combine-insns=3" } */ + +int a, b; + +void +foo (void) +{ + unsigned short d = 46067; + int e = e; + d <<= __builtin_mul_overflow (~0, e, &a); + d |= -68719476735; + b = d; +} + diff --git a/gcc/testsuite/gcc.dg/pr91860-4.c b/gcc/testsuite/gcc.dg/pr91860-4.c new file mode 100644 index 00000000000..36f2bd55c64 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr91860-4.c @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target int128 } */ +/* { dg-options "-O2 -g" } */ + +typedef unsigned char u8; +typedef unsigned int u32; +typedef unsigned __int128 u128; + +u32 b, c; + +static inline +u128 bar (u8 d, u128 e) +{ + __builtin_memset (11 + (char *) &e, b, 1); + d <<= e & 7; + d = d | d > 0; + return d + e; +} + +void +foo (void) +{ + c = bar (~0, 5); +}