From patchwork Tue Nov 24 16:38:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Richard Earnshaw (lists)" X-Patchwork-Id: 1405666 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=GOVKNgVS; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CgV8J45TKz9sRR for ; Wed, 25 Nov 2020 03:38:40 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B33CC385041D; Tue, 24 Nov 2020 16:38:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B33CC385041D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1606235917; bh=90jmhfSD0UoLJxvrjXPrVm38xeqiAwoRd4MPH52+Ilc=; h=Subject:To:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=GOVKNgVS3SPja0cYzRxV7QgUIXV468GR9NM+J5dkUMJF5rSLEzl+Zhf3n7g/jeaJI b4Ss4HUQosMUz0wSQshwNPKFyRwIjujYXKikn+rXs1Pq8/NhwrTax3Y/O/4ICnPf1S ffiqVqobxl6xzNUJRl+rrQiqgJGj+woXQlz7mkM4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 0606F385700F for ; Tue, 24 Nov 2020 16:38:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0606F385700F Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8A4D01FB for ; Tue, 24 Nov 2020 08:38:27 -0800 (PST) Received: from e120077-lin.cambridge.arm.com (e120077-lin.cambridge.arm.com [10.2.78.81]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5042C3F71F for ; Tue, 24 Nov 2020 08:38:27 -0800 (PST) Subject: [PATCH] arm: correctly handle negating INT_MIN in arm_split_atomic_op [PR97534] To: "gcc-patches@gcc.gnu.org" Message-ID: <86cb06d4-3209-9ff6-a383-c15bc92f2b22@arm.com> Date: Tue, 24 Nov 2020 16:38:25 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-3041.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "Richard Earnshaw \(lists\) via Gcc-patches" From: "Richard Earnshaw (lists)" Reply-To: "Richard Earnshaw \(lists\)" Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" arm_split_atomic_op handles subtracting a constant by converting it into addition of the negated constant. But if the type of the operand is int and the constant is -1 we currently end up generating invalid RTL which can lead to an abort later on. The problem is that in a HOST_WIDE_INT, INT_MIN is represented as 0xffffffff80000000 and the negation of this is 0x0000000080000000, but that's not a valid constant for use in SImode operations. The fix is straight-forward which is to use gen_int_mode rather than simply GEN_INT. This knows how to correctly sign-extend the negated constant when this is needed. gcc/ PR target/97534 * config/arm/arm.c (arm_split_atomic_op): Use gen_int_mode when negating a const_int. gcc/testsuite/ * gcc.dg/pr97534.c: New test. --- gcc/config/arm/arm.c | 2 +- gcc/testsuite/gcc.dg/pr97534.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr97534.c diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 568e1530f24..56ed556b098 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -30824,7 +30824,7 @@ arm_split_atomic_op (enum rtx_code code, rtx old_out, rtx new_out, rtx mem, case MINUS: if (CONST_INT_P (value)) { - value = GEN_INT (-INTVAL (value)); + value = gen_int_mode (-INTVAL (value), wmode); code = PLUS; } /* FALLTHRU */ diff --git a/gcc/testsuite/gcc.dg/pr97534.c b/gcc/testsuite/gcc.dg/pr97534.c new file mode 100644 index 00000000000..b363a322aa5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr97534.c @@ -0,0 +1,9 @@ +/* PR target/97534 - ICE in decompose on arm*-*-*. */ +/* { dg-do compile } */ +/* { dg-options "-std=c11 -O2 -g" } */ + +int f (int a) +{ + int b; + __atomic_fetch_sub(&b, (int)(-__INT_MAX__ - 1), (int)0); +}