From patchwork Wed Nov 10 12:48:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1553421 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=Ivnokppx; dkim-atps=neutral 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+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hq4TY1yV8z9s0r for ; Wed, 10 Nov 2021 23:50:57 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 13F6D3857817 for ; Wed, 10 Nov 2021 12:50:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 13F6D3857817 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636548655; bh=FvM4ob9PBjVOZ6IHg2aWTTiM2ttRGiY42iE9UXKuVms=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=IvnokppxUd3HWtFh8jV7gGHd9Od1lRS2n8+rm7IXZw/gX3l7sIWq6JoJqrgW9e7FH G+CbMMJDHboiLgSAUYJGeIOUXyIoxkkAJW0NsLEfeOMM/wTTVdkM4/fs3cDHm4lfLI RQu1Qvuve6L0uEbXr9khxoieO334YjU8+l3nEJkM= 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 1E0B8385781E for ; Wed, 10 Nov 2021 12:48:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1E0B8385781E 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 BD75A101E for ; Wed, 10 Nov 2021 04:48:21 -0800 (PST) Received: from localhost (unknown [10.32.98.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 647513F5A1 for ; Wed, 10 Nov 2021 04:48:21 -0800 (PST) To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [PATCH 1/4] Canonicalize argument order for commutative functions Date: Wed, 10 Nov 2021 12:48:20 +0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 Sandiford via Gcc-patches From: Richard Sandiford Reply-To: Richard Sandiford Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch uses information about internal functions to canonicalize the argument order of calls. Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK to install? Richard gcc/ * gimple-fold.c: Include internal-fn.h. (fold_stmt_1): If a function maps to an internal one, use first_commutative_argument to canonicalize the order of commutative arguments. gcc/testsuite/ * gcc.dg/fmax-fmin-1.c: New test. --- gcc/gimple-fold.c | 25 ++++++++++++++++++++++--- gcc/testsuite/gcc.dg/fmax-fmin-1.c | 18 ++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/fmax-fmin-1.c diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index a937f130815..6a7d4507c89 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -69,6 +69,7 @@ along with GCC; see the file COPYING3. If not see #include "varasm.h" #include "memmodel.h" #include "optabs.h" +#include "internal-fn.h" enum strlen_range_kind { /* Compute the exact constant string length. */ @@ -6140,18 +6141,36 @@ fold_stmt_1 (gimple_stmt_iterator *gsi, bool inplace, tree (*valueize) (tree)) break; case GIMPLE_CALL: { - for (i = 0; i < gimple_call_num_args (stmt); ++i) + gcall *call = as_a (stmt); + for (i = 0; i < gimple_call_num_args (call); ++i) { - tree *arg = gimple_call_arg_ptr (stmt, i); + tree *arg = gimple_call_arg_ptr (call, i); if (REFERENCE_CLASS_P (*arg) && maybe_canonicalize_mem_ref_addr (arg)) changed = true; } - tree *lhs = gimple_call_lhs_ptr (stmt); + tree *lhs = gimple_call_lhs_ptr (call); if (*lhs && REFERENCE_CLASS_P (*lhs) && maybe_canonicalize_mem_ref_addr (lhs)) changed = true; + if (*lhs) + { + combined_fn cfn = gimple_call_combined_fn (call); + internal_fn ifn = associated_internal_fn (cfn, TREE_TYPE (*lhs)); + int opno = first_commutative_argument (ifn); + if (opno >= 0) + { + tree arg1 = gimple_call_arg (call, opno); + tree arg2 = gimple_call_arg (call, opno + 1); + if (tree_swap_operands_p (arg1, arg2)) + { + gimple_call_set_arg (call, opno, arg2); + gimple_call_set_arg (call, opno + 1, arg1); + changed = true; + } + } + } break; } case GIMPLE_ASM: diff --git a/gcc/testsuite/gcc.dg/fmax-fmin-1.c b/gcc/testsuite/gcc.dg/fmax-fmin-1.c new file mode 100644 index 00000000000..e7e0518d8bb --- /dev/null +++ b/gcc/testsuite/gcc.dg/fmax-fmin-1.c @@ -0,0 +1,18 @@ +/* { dg-options "-O -fdump-tree-optimized" } */ + +void +f1 (double *res, double x, double y) +{ + res[0] = __builtin_fmax (x, y); + res[1] = __builtin_fmax (y, x); +} + +void +f2 (double *res, double x, double y) +{ + res[0] = __builtin_fmin (x, y); + res[1] = __builtin_fmin (y, x); +} + +/* { dg-final { scan-tree-dump-times {__builtin_fmax} 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times {__builtin_fmin} 1 "optimized" } } */ From patchwork Wed Nov 10 12:49:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1553422 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=VuEXioPi; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hq4Vn2LzWz9s0r for ; Wed, 10 Nov 2021 23:52:00 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0A9B63857813 for ; Wed, 10 Nov 2021 12:51:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A9B63857813 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636548718; bh=VR3rH/FhTxMMiQOLJmslvfar5W+gJbSUm3T7nmZxR+o=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=VuEXioPifG+NZ387EYpgcksCD9yrkJBT7gft7rWcRNZjtzjwqRGDOGb0TVdTasZNn FNuGTA0zD4VegXMuWElh66/1gTxsn6aymbiW6/D8Y7ML8EwWJIvzF/yUp3RGVWW1Wp VLmFO/PIC2QauIxFENkhElonPPAs73czLjWJttdc= 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 F2801385781F for ; Wed, 10 Nov 2021 12:49:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F2801385781F 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 AEC1C101E for ; Wed, 10 Nov 2021 04:49:01 -0800 (PST) Received: from localhost (unknown [10.32.98.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 55EF33F5A1 for ; Wed, 10 Nov 2021 04:49:01 -0800 (PST) To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [PATCH 2/4] Mark IFN_COMPLEX_MUL as commutative Date: Wed, 10 Nov 2021 12:49:00 +0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 Sandiford via Gcc-patches From: Richard Sandiford Reply-To: Richard Sandiford Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Mark IFN_COMPLEX_MUL as commutative. Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK to install? Richard gcc/ * internal-fn.c (commutative_binary_fn_p): Handle IFN_COMPLEX_MUL. gcc/testsuite/ * gcc.target/aarch64/sve/complex_mul_1.c: New test. --- gcc/internal-fn.c | 1 + .../gcc.target/aarch64/sve/complex_mul_1.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/complex_mul_1.c diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c index 7b13db6dfe3..ff7d43f1801 100644 --- a/gcc/internal-fn.c +++ b/gcc/internal-fn.c @@ -3829,6 +3829,7 @@ commutative_binary_fn_p (internal_fn fn) case IFN_MULHRS: case IFN_FMIN: case IFN_FMAX: + case IFN_COMPLEX_MUL: return true; default: diff --git a/gcc/testsuite/gcc.target/aarch64/sve/complex_mul_1.c b/gcc/testsuite/gcc.target/aarch64/sve/complex_mul_1.c new file mode 100644 index 00000000000..d197e7d0d8e --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/complex_mul_1.c @@ -0,0 +1,16 @@ +/* { dg-options "-O2 -fgimple -fdump-tree-optimized" } */ + +void __GIMPLE +foo (__SVFloat64_t x, __SVFloat64_t y, __SVFloat64_t *res1, + __SVFloat64_t *res2) +{ + __SVFloat64_t a1; + __SVFloat64_t a2; + + a1 = .COMPLEX_MUL (x, y); + a2 = .COMPLEX_MUL (y, x); + __MEM<__SVFloat64_t> (res1) = a1; + __MEM<__SVFloat64_t> (res2) = a2; +} + +/* { dg-final { scan-tree-dump-times {\.COMPLEX_MUL} 1 "optimized" } } */ From patchwork Wed Nov 10 12:49:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1553423 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=c8/3E2ht; dkim-atps=neutral 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+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hq4Wr50xvz9s0r for ; Wed, 10 Nov 2021 23:52:56 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 36631385780A for ; Wed, 10 Nov 2021 12:52:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 36631385780A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636548774; bh=t1LDQG5h5dY6n9g46pR6IFySbKcyC0veFgAhF+oI+50=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=c8/3E2htvKxnY7LTghAiMDneNfmO/YqLsopP4Rc2GD84d2PhQAgzMq1fPyae0LvoP Z/mA7o0mALj4lQXPfMa3y5zPZ5eZCqHz/NeURmAVaHJBSBcZSrqLWyzkeOKLYYwv19 jSrTcUw/IlGAPdFdVHGjB6jbAFXZ4yCI/cnIzyV0= 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 62B34385801F for ; Wed, 10 Nov 2021 12:49:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 62B34385801F 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 1CFF4101E for ; Wed, 10 Nov 2021 04:49:38 -0800 (PST) Received: from localhost (unknown [10.32.98.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B75F33F5A1 for ; Wed, 10 Nov 2021 04:49:37 -0800 (PST) To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [PATCH 3/4] Mark IFN_UBSAN_CHECK_ADD/MUL as commutative Date: Wed, 10 Nov 2021 12:49:36 +0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 Sandiford via Gcc-patches From: Richard Sandiford Reply-To: Richard Sandiford Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Mark IFN_UBSAN_CHECK_ADD/MUL as commutative. Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK to install? Richard gcc/ * internal-fn.c (commutative_binary_fn_p): Handle IFN_UBSAN_CHECK_ADD and IFN_UBSAN_CHECK_MUL. gcc/testsuite/ * gcc.dg/ubsan/commutative-1.c: New test. --- gcc/internal-fn.c | 2 ++ gcc/testsuite/gcc.dg/ubsan/commutative-1.c | 30 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/ubsan/commutative-1.c diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c index ff7d43f1801..b64555ada36 100644 --- a/gcc/internal-fn.c +++ b/gcc/internal-fn.c @@ -3830,6 +3830,8 @@ commutative_binary_fn_p (internal_fn fn) case IFN_FMIN: case IFN_FMAX: case IFN_COMPLEX_MUL: + case IFN_UBSAN_CHECK_ADD: + case IFN_UBSAN_CHECK_MUL: return true; default: diff --git a/gcc/testsuite/gcc.dg/ubsan/commutative-1.c b/gcc/testsuite/gcc.dg/ubsan/commutative-1.c new file mode 100644 index 00000000000..128f5b14697 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ubsan/commutative-1.c @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=undefined -fdump-tree-optimized" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-flto" } { "" } } */ + +int res[2]; + +void +f1 (int x, int y) +{ + res[0] = x + y; + res[1] = y + x; +} + +void +f2 (int x, int y) +{ + res[0] = x - y; + res[1] = y - x; +} + +void +f3 (int x, int y) +{ + res[0] = x * y; + res[1] = y * x; +} + +/* { dg-final { scan-tree-dump-times {\.UBSAN_CHECK_ADD} 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times {\.UBSAN_CHECK_SUB} 2 "optimized" } } */ +/* { dg-final { scan-tree-dump-times {\.UBSAN_CHECK_MUL} 1 "optimized" } } */ From patchwork Wed Nov 10 12:50:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1553424 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=PjjTf00y; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hq4Xx5nTpz9s0r for ; Wed, 10 Nov 2021 23:53:53 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8A4CA3857C71 for ; Wed, 10 Nov 2021 12:53:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8A4CA3857C71 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636548830; bh=75f2pK/vKbR3+cl3AFKcai/cIaJ4Ak6/zkjFQk6BiRI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=PjjTf00y14RCuQ+ZXmau7v8OugBZhuc2PKPV0sNHlStgsKlWg613GQ32OHpyjWC9n ZhoYcUD+jkvQsGIaLME0a6Cwb1MlbOgHknI6TCX/EDgjZeLcyK9o1aLbqhNgfDZJ5B iLRQdE+Gu/Ndw6ydh6GtL/w4qdYUAL9ZyJX+Nom0= 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 99C663857C77 for ; Wed, 10 Nov 2021 12:50:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 99C663857C77 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 510EF101E for ; Wed, 10 Nov 2021 04:50:11 -0800 (PST) Received: from localhost (unknown [10.32.98.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EC54A3F5A1 for ; Wed, 10 Nov 2021 04:50:10 -0800 (PST) To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [PATCH 4/4] Mark IFN_ADD/MUL_OVERFLOW as commutative Date: Wed, 10 Nov 2021 12:50:09 +0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 Sandiford via Gcc-patches From: Richard Sandiford Reply-To: Richard Sandiford Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Mark IFN_ADD/MUL_OVERFLOW as commutative. Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK to install? Richard gcc/ * internal-fn.c (first_commutative_operand): Handle IFN_ADD_OVERFLOW and IFN_MUL_OVERFLOW. gcc/testsuite/ * gcc.dg/add-mul-overflow-1.c: New test. --- gcc/internal-fn.c | 2 ++ gcc/testsuite/gcc.dg/add-mul-overflow-1.c | 28 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/add-mul-overflow-1.c diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c index b64555ada36..10f08182f7e 100644 --- a/gcc/internal-fn.c +++ b/gcc/internal-fn.c @@ -3867,6 +3867,8 @@ first_commutative_argument (internal_fn fn) case IFN_FMS: case IFN_FNMA: case IFN_FNMS: + case IFN_ADD_OVERFLOW: + case IFN_MUL_OVERFLOW: return 0; case IFN_COND_ADD: diff --git a/gcc/testsuite/gcc.dg/add-mul-overflow-1.c b/gcc/testsuite/gcc.dg/add-mul-overflow-1.c new file mode 100644 index 00000000000..b23cdddbb63 --- /dev/null +++ b/gcc/testsuite/gcc.dg/add-mul-overflow-1.c @@ -0,0 +1,28 @@ +/* { dg-options "-O -fdump-tree-optimized" } */ + +int res[4]; + +void +f1 (int x, int y) +{ + res[2] = __builtin_add_overflow (x, y, res + 0); + res[3] = __builtin_add_overflow (y, x, res + 1); +} + +void +f2 (int x, int y) +{ + res[2] = __builtin_sub_overflow (x, y, res + 0); + res[3] = __builtin_sub_overflow (y, x, res + 1); +} + +void +f3 (int x, int y) +{ + res[2] = __builtin_mul_overflow (x, y, res + 0); + res[3] = __builtin_mul_overflow (y, x, res + 1); +} + +/* { dg-final { scan-tree-dump-times {\.ADD_OVERFLOW} 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times {\.SUB_OVERFLOW} 2 "optimized" } } */ +/* { dg-final { scan-tree-dump-times {\.MUL_OVERFLOW} 1 "optimized" } } */