From patchwork Thu Oct 19 04:05:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 155279 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp148427vqb; Wed, 18 Oct 2023 21:05:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHGGhwAE9UkV1wdj3hYUyjrkWA2yOroU+RYbcvK1rV9Wk4u7HaDw2g2sHTl2Vxst7NhW2mo X-Received: by 2002:ac8:5bd0:0:b0:403:b12b:908d with SMTP id b16-20020ac85bd0000000b00403b12b908dmr1201841qtb.8.1697688350314; Wed, 18 Oct 2023 21:05:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697688350; cv=pass; d=google.com; s=arc-20160816; b=JJwh+4FfWo/wy72a6Ep6AUXkBXblZiHXhh9oJzmrJW4eZfjyVrKt0tv8GUIjhhk4Z1 XtqoN926/axnD9PJgUYb+vfGBTPRxpnNrH+GcmEXM2407+xoLBKVW21h0DcIQ+hbf2IB uf/YlDW4T818TCqZIpCP4sYMm9JIvxCn9vnfGoBn0j1kBLWISLjpv35tTllQRU9ZDbjl v1uWbgBhz16KrcZjiuz6PXrfkDC86B+yz440WwrD6+QsDp7xglNPE52yqyRuf4MYlDbC u0YU++g9ZAxN5/SfPvh+qYXgocgr1rv+xA2TB7FQlb9zrnN5t92eOTwz+WTGwtaFfH24 Xmpw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=IzGINHItfw8YH9iaJpfxkAK5E3/qQKL1TDl5qq9R9BA=; fh=6xfd3IYC8Zt5CA4TsXZHhPmGMhO9cjo3oiHaQc5bSUI=; b=0qviItQ2uP+Cv6BX5PATVj19PW7PoZzGCbXwC9j/Qc2I2MvwTmNUQoQnJIKc3Hds3y cbGGeXv6x4cEGn4wv2GfdQa8ot62O35/mcQdVCIe8QnAeHXsEa76LnMXvCCwTaqjAlBM Vp1r04Qf+i/yzS+ip0tQyf0V/E0A2KaKnTr1LfUJzwu6RzSE3FNS+qFeA/saU+ez8ekT LJslODRsx7vNnGRxB87uNvoQL0+WUFlgBZDqC6LXh5DUAkc2S90bQIsslrkgZKw2vSGY gZ8MaW1Tb+Rm4wgbvwwTg2Tobb4ei8KqzLloCGL4FyOPIVwotd7gTXSpTzM5A+tYjTAu 2XNA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=F54YIQff; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id m22-20020a05622a119600b0041b83bbd0eesi1060311qtk.43.2023.10.18.21.05.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 21:05:50 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=F54YIQff; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 084753857726 for ; Thu, 19 Oct 2023 04:05:50 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id B06693858D1E for ; Thu, 19 Oct 2023 04:05:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B06693858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B06693858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697688327; cv=none; b=I6KhImFlllJEc/tB9REUJpbJNdlaS6mIu+//Jxk/Uo8mgR2yrRwAbVibX4MLTA1HIdQ3k19+ZodayunbyTcy9nul+kxbLFFdJHtMqICw5T3Zy2ppFBgtk+5DEYy7tgbnp7omSfjoJR1LZ0bXwIilZmK/tLxFaWm4b/eC1ssFbnk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697688327; c=relaxed/simple; bh=t341Sat6980Yc4xCaiKcXqYXRCecJZEfZvMg0VSdYWw=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=ovUCNjylV4kXpJrLEzrvSD6Eg4Tcune96k9a/voEsZ3Ktm/5HfN646VxuwC6DYuf5mD1XyQU7FS8WVpHKvaEOAKkxhjuEsckr0lZcPjBXJpaiL0QeHm7gr1Q7AIz6JEQeHfvhsl4jNtnnztfMGXGq9Je7d7BXeVJWX+H4a2Ws1o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1ca215cc713so33278765ad.3 for ; Wed, 18 Oct 2023 21:05:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697688324; x=1698293124; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=IzGINHItfw8YH9iaJpfxkAK5E3/qQKL1TDl5qq9R9BA=; b=F54YIQffCaCZmQ1y0a4Eyq/O/G3OhigQMwwLG20p7L9oosYrNv7BNCdznJny7TjqjX MZ0U2N30O2MAIJrcGX8qE7oLKoB4BVnu9QaHuEL429tXnRT3WibThm1obg7Stsf1pKX6 daXE/WvfxBXM7+cFhD39d+vq5mKbrLZqC/EduVb9dXxwrxZcFItI6nJttIc6gor1dn3O sJXaI4xLuhEoiFo+E7FZeVdnswJQT/OzpJF/J5dSzlB3OOJcwWHwLue2VxjyPJtaB1O2 DsLARP7887+cvooGkwj7xBXuUNaYKHjonZNOFVvu78ccBIHLB7wZxaZk76+5Rz7B7tiw HT8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697688324; x=1698293124; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IzGINHItfw8YH9iaJpfxkAK5E3/qQKL1TDl5qq9R9BA=; b=QZEbGmuogpwlcihkX5aE4dtZHelB4IP7alAEFt8ul+XMMUOdJQcnBb2OIgTrVRQ6dn 8KfYVTXprKdL04NjaCdEuNcgsPCGFxGBhKt2uqHdy8Sp6kpmQMKBk2vRLv9Vz0bdBPM/ Ms6gEaGHbhFiGw1HunWQ3xS0Vj9b1FKv+4sSbAFYALkqojUUnvS0XoijA0VrjDFfhhzL nYHMLuFY7HG/eUQfjisMVv4BTPL4ivPfDO9AK6HgGhGDUv3CTJGakIUU4iW5cBXfRIvm SKtcFxEFyhnp3cHgjtG0eE282X8wAl5iV66GH5l05UUtbhbECtlS6boDK1KprQvifdNo l9cw== X-Gm-Message-State: AOJu0Yx44AvXN/Q46wAkSlbccF007L8oQIoIklOZ2Mz9zWLl7lkVAG1f T1Y5v3Qwmy55J4CU++sWlbcUF2oVWfTFHw== X-Received: by 2002:a17:903:138f:b0:1c6:1611:e53c with SMTP id jx15-20020a170903138f00b001c61611e53cmr1079010plb.32.1697688324255; Wed, 18 Oct 2023 21:05:24 -0700 (PDT) Received: from xeond2.wrightpinski.org ([98.97.114.173]) by smtp.gmail.com with ESMTPSA id b6-20020a170902d30600b001c9c47d6cb9sm732886plc.99.2023.10.18.21.05.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 21:05:23 -0700 (PDT) From: Andrew Pinski To: gcc-patches@gcc.gnu.org Cc: Andrew Pinski Subject: [PATCH] aarch64: [PR110986] Emit csinv again for `a ? ~b : b` Date: Wed, 18 Oct 2023 21:05:19 -0700 Message-Id: <20231019040519.2655598-1-pinskia@gmail.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780155259922218992 X-GMAIL-MSGID: 1780155259922218992 After r14-3110-g7fb65f10285, the canonical form for `a ? ~b : b` changed to be `-(a) ^ b` that means for aarch64 we need to add a few new insn patterns to be able to catch this and change it to be what is the canonical form for the aarch64 backend. A secondary pattern was needed to support a zero_extended form too; this adds a testcase for all 3 cases. Bootstrapped and tested on aarch64-linux-gnu with no regressions. PR target/110986 gcc/ChangeLog: * config/aarch64/aarch64.md (*cmov_insn_insv): New pattern. (*cmov_uxtw_insn_insv): Likewise. gcc/testsuite/ChangeLog: * gcc.target/aarch64/cond_op-1.c: New test. --- gcc/config/aarch64/aarch64.md | 46 ++++++++++++++++++++ gcc/testsuite/gcc.target/aarch64/cond_op-1.c | 20 +++++++++ 2 files changed, 66 insertions(+) create mode 100644 gcc/testsuite/gcc.target/aarch64/cond_op-1.c diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md index 32c7adc8928..59cd0415937 100644 --- a/gcc/config/aarch64/aarch64.md +++ b/gcc/config/aarch64/aarch64.md @@ -4413,6 +4413,52 @@ (define_insn "*csinv3_uxtw_insn3" [(set_attr "type" "csel")] ) +;; There are two canonical forms for `cmp ? ~a : a`. +;; This is the second form and is here to help combine. +;; Support `-(cmp) ^ a` into `cmp ? ~a : a` +;; The second pattern is to support the zero extend'ed version. + +(define_insn_and_split "*cmov_insn_insv" + [(set (match_operand:GPI 0 "register_operand" "=r") + (xor:GPI + (neg:GPI + (match_operator:GPI 1 "aarch64_comparison_operator" + [(match_operand 2 "cc_register" "") (const_int 0)])) + (match_operand:GPI 3 "general_operand" "r")))] + "can_create_pseudo_p ()" + "#" + "&& true" + [(set (match_dup 0) + (if_then_else:GPI (match_dup 1) + (not:GPI (match_dup 3)) + (match_dup 3)))] + { + operands[3] = force_reg (mode, operands[3]); + } + [(set_attr "type" "csel")] +) + +(define_insn_and_split "*cmov_uxtw_insn_insv" + [(set (match_operand:DI 0 "register_operand" "=r") + (zero_extend:DI + (xor:SI + (neg:SI + (match_operator:SI 1 "aarch64_comparison_operator" + [(match_operand 2 "cc_register" "") (const_int 0)])) + (match_operand:SI 3 "general_operand" "r"))))] + "can_create_pseudo_p ()" + "#" + "&& true" + [(set (match_dup 0) + (if_then_else:DI (match_dup 1) + (zero_extend:DI (not:SI (match_dup 3))) + (zero_extend:DI (match_dup 3))))] + { + operands[3] = force_reg (SImode, operands[3]); + } + [(set_attr "type" "csel")] +) + ;; If X can be loaded by a single CNT[BHWD] instruction, ;; ;; A = UMAX (B, X) diff --git a/gcc/testsuite/gcc.target/aarch64/cond_op-1.c b/gcc/testsuite/gcc.target/aarch64/cond_op-1.c new file mode 100644 index 00000000000..e6c7821127e --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/cond_op-1.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* PR target/110986 */ + + +long long full(unsigned a, unsigned b) +{ + return a ? ~b : b; +} +unsigned fuu(unsigned a, unsigned b) +{ + return a ? ~b : b; +} +long long fllll(unsigned long long a, unsigned long long b) +{ + return a ? ~b : b; +} + +/* { dg-final { scan-assembler-times "csinv\tw\[0-9\]*" 2 } } */ +/* { dg-final { scan-assembler-times "csinv\tx\[0-9\]*" 1 } } */