From patchwork Wed Oct 9 20:11:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Wilson X-Patchwork-Id: 1174006 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-510569-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="P/KAc2OL"; dkim=pass (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.b="h6ON5/Rf"; 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 46pQN26yYMz9s7T for ; Thu, 10 Oct 2019 07:11:29 +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; q=dns; s=default; b=gAqrprqZ/eSz bx+ktlFKPows5XqYHo7m3l+9u1k7zRkwTN3HnZKHJ1nU4lz3aaU0xUSBlWHvS+Np cDjDOVYoqQhqdd7CcN15MpTJBtR5a7SqySn0j5+5P3oNZx6SFR+gVmZ+6MZvpVeI sabaVWL3FdE2iQ8fsBdWCT1CQcPD/6o= 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; s=default; bh=vs5mGgqBbZ3aUhCNho VUdTl57Tk=; b=P/KAc2OLEz+Mq0LYtZCTwLk1qBIe4MKAugKPi0Rdgo2eI6Dfw0 xBvfSiiOfLEwnpqDPmwH4JlL72VVUqnF9qM1t62OZM3VTLtn8j6AUSv8hZABC1tC OEDxnvLAOVxz9VvBBBC7IaAXMBYG7YPEG8IYa2ZFsznVWGsPQfdZkiJ3E= Received: (qmail 24631 invoked by alias); 9 Oct 2019 20:11:22 -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 24611 invoked by uid 89); 9 Oct 2019 20:11:21 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.5 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= X-HELO: mail-pl1-f193.google.com Received: from mail-pl1-f193.google.com (HELO mail-pl1-f193.google.com) (209.85.214.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 09 Oct 2019 20:11:20 +0000 Received: by mail-pl1-f193.google.com with SMTP id s17so1585940plp.6 for ; Wed, 09 Oct 2019 13:11:20 -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; bh=xkRR9G88+2It8eedezubynOsufJudINJzRFmiD/mF28=; b=h6ON5/RfdTzLi8ZYcLvj8eeX78RB/j5DMfvv/NQ0Aw1ERZUtF65rX6GTMpTsa1SCVk 1ZuU6jhw0wZLyhfmhmz7xkEi7SC/gIU3JvtUlSU5cJCl0Ue8TulIXnNomdrpqZjzO/4y SJXAA++XB09JC7+4zWwOBUlq3EyrWW7dU2iaX6r36wSQOvSGYaV7UT2eizw4Y5M21LpU 4t8iIZtJ+Yjfrgoh3qPr7yRbldc87Y+ooefLNl5n6KFB0s+kEb6+SYK+3l9421nH2L8w xkh20jigtCv+5/Fq01eN8pRqcjfrV7mJ7uoMrSk2dQXhPsZqBFipjap7dlXhQpyRJjdF TTww== Received: from rohan.sifive.com ([12.206.222.5]) by smtp.gmail.com with ESMTPSA id c11sm4377460pfj.114.2019.10.09.13.11.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2019 13:11:17 -0700 (PDT) From: Jim Wilson To: gcc-patches@gcc.gnu.org Cc: Jim Wilson Subject: [PATCH] Modify simplify_truncation to handle extended CONST_INT. Date: Wed, 9 Oct 2019 13:11:14 -0700 Message-Id: <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)) The place where this starts to go wrong is in simplify_truncation, where it tries to compare the size of the original mode VOIDmode with the subreg mode QI and decides that we need to sign extend the constant to convert it from VOIDmode to QImode. We actually need a truncation not a extension here. Also note that the GET_MODE_UNIT_PRECISION (VOIDmode) isn't useful. We can fix this by changing the mode to MAX_MODE_INT, as the CONST_INT should already be valid for the largest supported integer mode. There are already a number of other places in simplify-rtx.c that do the same thing. 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 * simplify-rtx.c (simplify_truncation): If origmode is VOIDmode, set it to MAX_MODE_INT. 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/simplify-rtx.c | 11 +++++++++++ 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, 81 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/simplify-rtx.c b/gcc/simplify-rtx.c index 9a70720c764..8593010acf4 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -635,6 +635,17 @@ simplify_truncation (machine_mode mode, rtx op, is larger than the origmode, we can just extend to the appropriate mode. */ machine_mode origmode = GET_MODE (XEXP (op, 0)); + + /* This can happen when called from inside combine, if we have a zero + or sign extend of a CONST_INT. We assume that all of the bits of the + constant are significant here. If we don't do this, then we try + to extend VOIDmode, which takes us to simplify_const_unary_operation + which assumes that a VOIDmode operand has the destination mode, + which can then trigger an abort in a wide_int::from call if the + constant isn't already valid for that mode. */ + if (origmode == VOIDmode) + origmode = MAX_MODE_INT; + if (mode == origmode) return XEXP (op, 0); else if (precision <= GET_MODE_UNIT_PRECISION (origmode)) 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); +}