From patchwork Wed Jan 17 09:50:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Monk Chiang X-Patchwork-Id: 188750 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp799198dye; Wed, 17 Jan 2024 01:52:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IEvBDSZ47QRdzp+d2KXy3Lmy6D7b8n8KSFB5vn320UKUh7BgwGZS5R3kkHPtHRC3RJMzTop X-Received: by 2002:a05:620a:55b6:b0:781:428b:78be with SMTP id vr22-20020a05620a55b600b00781428b78bemr9225381qkn.134.1705485121627; Wed, 17 Jan 2024 01:52:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705485121; cv=pass; d=google.com; s=arc-20160816; b=qQNQ/NZxFhOCofnzhgXnfdnEiDo7mMHqvCA5KVEetna3Lz7JvdoG8VVXYoicFcXU2W fgFkPI3WraHIuf6hajaIrY1clqP7m3umqU8gb9Zn6mdhNKit/sERKcLWgtuS8di7cAN6 BfHsQL9pJyjvzbYmCxa2op2i6DNFZX6sdhgSzm2MpKdJ56ItTGTkloZ/tSQak9HgiTrR SPl6PAwTV2FrD33HMso/SoTiQ4QLZqeDV1n+R7+VtKrhghnE3QEGp07gZxTs3/WjwzWr H50EyqoxgB7JoMwDo+tWUpvc662WpdC99o37gbCEqvyV/aqo+QeXRtn9N6JmxuC9huq0 xzzA== 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=vU64AMLl+p6fYvYbuU1Sq8o+KCgg0UTefF2+eiCYU/I=; fh=yWLQD4bLJa+r9JDyfuyVp+QUfOZCsXNtmQTaPaEL7jQ=; b=dtZl/TSQdvIu3mMJeLvUOs+/mcsSjcAWjZIrdyoz/KozmcYKgFG/zQlw7jwzha3uD1 b5yVWkG9LBCDrhmCHKC6jB46dP7Tev6vzTiyIAbY2NwaDzimse/SuiYrh+MABVuEk4yR gvoI61p9lGet3mylSgCojW8S6fwR4COGYpuVDtx9IYjZhtAfS7AWay1M2rQQLBKM3rh/ mbvLFMSnFY1YrLn4xVHVomR/ntf+Yb+M1e/WJoFN0lfR198/vi5BhiGgI8C2VyS7UaEk atnUDq0LgP6+67J5KGLFEDlqJMQqs5LLml3w5hc1lxPWc574g1dknrJkQ4ot+egFaPkF Uumg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b="Mr0/4jOs"; 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=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d1-20020a05620a166100b007833c5d6b6csi11196441qko.713.2024.01.17.01.52.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 01:52:01 -0800 (PST) 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=@sifive.com header.s=google header.b="Mr0/4jOs"; 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=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3400B3858C2F for ; Wed, 17 Jan 2024 09:52:01 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by sourceware.org (Postfix) with ESMTPS id 9C6F53858410 for ; Wed, 17 Jan 2024 09:51:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9C6F53858410 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9C6F53858410 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::229 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705485070; cv=none; b=TfIAI+puZbKiAghFpJJqOeQdlrJB3whuT13hdq8G6A4wrSFsoZ0u2pko0VHXoobgSnf9o6rIVqHVZHCM+wga+FH0vH5RIcr+P6qQuPeJeudrQgS0Wj+edBG8OsQTjgjdV5Co5irR3d4mMWB83kt9j+5iJWmpYJ+9pPmpvYIe8C8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705485070; c=relaxed/simple; bh=r4Vaq8JklDQKb9JcU9PUg/X1YP8r0+yPVsnW24rU6C0=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Rw66iS0wg92DyppVNmkW6A+C49Y7nfJUcA4c3wwsy+oIRLir7/+lleQlL0VkxBfa2a/Q+GThc6EhSX2wGVcs4gjuEbCINZT8r0fiTpxlZXOIFodQYg3w40S/FLVJfALMb3PLFxNauVT0S4wT03t9UFtsK08b1jPFN2lS2CEpaeE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-3bd9448da62so264362b6e.2 for ; Wed, 17 Jan 2024 01:51:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1705485068; x=1706089868; 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=vU64AMLl+p6fYvYbuU1Sq8o+KCgg0UTefF2+eiCYU/I=; b=Mr0/4jOsCFnDnCNLESZRuGV7dNep9bdSDSJIUhz97RV/KmKC6WsmFoh4j756Kf2dZP sMgJVDxCmcEiL1WfvH5AgzVTPjBlkOpqhEdGJNBmIUDE55YAY3iqB84UVRNoy96N2ygc iVNgsia0YQUdjGXNejMN5aeTFy03Lv4wfav+OzmKXdBSkoELQrj0/g+CilO5WZ0ITMQd ne7N+X1s/GrJIHqYnh4Y8l1zJIrtXMe0F/ShZyzLnveXYRe1cuefDDNN0krcPG5eBttw oiNXuOAt8qleZ0gjX3UohEhluieZma2eUvTyn0B8BTcYIpt9AUUPI57W667kXWqn9BLE A/iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705485068; x=1706089868; 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=vU64AMLl+p6fYvYbuU1Sq8o+KCgg0UTefF2+eiCYU/I=; b=IS1LGOkQhpCmo5a8GteqtjkiQy21uzjzBA09sjb6xFuGUwmk9FkmjZY1yIfc2JEox5 O+tAda3vXeYdsbxGBQk1mJ2CAjTTldZRNBuGqNKEquSyTM3IJYBuotMS7oPCPLXVySgW HRWqnRRY38CHzYZ6VGuiUjC0pEcJX8q/yHNWVx8CYgDWyTSHE84qNVnWr7Q+NSn1yKA8 PwVvrZolULwVrMK2vUZH7uugn5NSIiQvj5U/EFb2Jt4Z034S0ZDVJS8wiFC506qEnSKN kWm9NFM5R8sId3K8syQSefVgucUwnYejrZZILqqn6jvD6PHO0y2/FNH3qAec9jRjfRsY CKdQ== X-Gm-Message-State: AOJu0Yx+qHsiFlDRrPYzDs99iCxHs2OUOGSs01OS+Vn+7No9fDMuMhcL 6Dt3YOxLIGezOsFh3wZBAALdILMnw6NlfBkCcoE4wsHEBkM+gkZqdwGjue3MsCtr3k8oHg4P8Zz 8gFI6GmqXo5d0FSkMiG8GOqA3K/dyXL+l5uV94k7dkPtAWNlSMjs3SansRW3aQKWJEM0KZ3fyj9 /dQJFb3wtWIgrPOVE= X-Received: by 2002:a05:6808:221a:b0:3bc:2a41:953 with SMTP id bd26-20020a056808221a00b003bc2a410953mr11234629oib.83.1705485067712; Wed, 17 Jan 2024 01:51:07 -0800 (PST) Received: from hsinchu02.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id y27-20020aa79e1b000000b006d9ac481eccsm1008142pfq.220.2024.01.17.01.51.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 01:51:07 -0800 (PST) From: Monk Chiang To: gcc-patches@gcc.gnu.org, rguenther@suse.de, apinski@marvell.com, jeffreyalaw@gmail.com Cc: Monk Chiang Subject: [PATCH] match: Do not select to branchless expression when target has movcc pattern [PR113095] Date: Wed, 17 Jan 2024 17:50:55 +0800 Message-Id: <20240117095055.119853-1-monk.chiang@sifive.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: 1788330766929616160 X-GMAIL-MSGID: 1788330766929616160 This allows the backend to generate movcc instructions, if target machine has movcc pattern. branchless-cond.c needs to be updated since some target machines have conditional move instructions, and the experssion will not change to branchless expression. gcc/ChangeLog: PR target/113095 * match.pd (`(zero_one == 0) ? y : z y`, `(zero_one != 0) ? z y : y`): Do not match to branchless expression, if target machine has conditional move pattern. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/branchless-cond.c: Update testcase. --- gcc/match.pd | 30 +++++++++++++++++-- .../gcc.dg/tree-ssa/branchless-cond.c | 6 ++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index e42ecaf9ec7..a1f90b1cd41 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -4231,7 +4231,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (INTEGRAL_TYPE_P (type) && TYPE_PRECISION (type) > 1 && (INTEGRAL_TYPE_P (TREE_TYPE (@0)))) - (op (mult (convert:type @0) @2) @1)))) + (with { + bool can_movecc_p = false; + if (can_conditionally_move_p (TYPE_MODE (type))) + can_movecc_p = true; + + /* Some target only support word_mode for movcc pattern, if type can + extend to word_mode then use conditional move. Even if there is a + extend instruction, the cost is lower than branchless. */ + if (can_extend_p (word_mode, TYPE_MODE (type), TYPE_UNSIGNED (type)) + && can_conditionally_move_p (word_mode)) + can_movecc_p = true; + } + (if (!can_movecc_p) + (op (mult (convert:type @0) @2) @1)))))) /* (zero_one != 0) ? z y : y -> ((typeof(y))zero_one * z) y */ (for op (bit_xor bit_ior plus) @@ -4243,7 +4256,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (INTEGRAL_TYPE_P (type) && TYPE_PRECISION (type) > 1 && (INTEGRAL_TYPE_P (TREE_TYPE (@0)))) - (op (mult (convert:type @0) @2) @1)))) + (with { + bool can_movecc_p = false; + if (can_conditionally_move_p (TYPE_MODE (type))) + can_movecc_p = true; + + /* Some target only support word_mode for movcc pattern, if type can + extend to word_mode then use conditional move. Even if there is a + extend instruction, the cost is lower than branchless. */ + if (can_extend_p (word_mode, TYPE_MODE (type), TYPE_UNSIGNED (type)) + && can_conditionally_move_p (word_mode)) + can_movecc_p = true; + } + (if (!can_movecc_p) + (op (mult (convert:type @0) @2) @1)))))) /* ?: Value replacement. */ /* a == 0 ? b : b + a -> b + a */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond.c b/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond.c index e063dc4bb5f..c002ed97364 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond.c @@ -21,6 +21,6 @@ int f4(unsigned int x, unsigned int y, unsigned int z) return ((x & 1) != 0) ? z | y : y; } -/* { dg-final { scan-tree-dump-times " \\\*" 4 "optimized" } } */ -/* { dg-final { scan-tree-dump-times " & " 4 "optimized" } } */ -/* { dg-final { scan-tree-dump-not "if " "optimized" } } */ +/* { dg-final { scan-tree-dump-times " \\\*" 4 "optimized" { xfail { "aarch64*-*-* alpha*-*-* bfin*-*-* epiphany-*-* i?86-*-* x86_64-*-* nds32*-*-*" } } } } */ +/* { dg-final { scan-tree-dump-times " & " 4 "optimized" { xfail { "aarch64*-*-* alpha*-*-* bfin*-*-* epiphany-*-* i?86-*-* x86_64-*-* nds32*-*-*" } } } } */ +/* { dg-final { scan-tree-dump-not "if " "optimized" { xfail { "aarch64*-*-* alpha*-*-* bfin*-*-* epiphany-*-* i?86-*-* x86_64-*-* nds32*-*-*" } } } } */