From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by sourceware.org (Postfix) with ESMTPS id 3DECA3858284 for ; Wed, 30 Aug 2023 10:14:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3DECA3858284 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2bcd7a207f7so79087471fa.3 for ; Wed, 30 Aug 2023 03:14:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1693390466; x=1693995266; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EdvjH/CPUEM+oqwsKsE4qN2wj4+iJ6OkD5HUkdlFZV0=; b=T8ZNb+qyijq2CgtMQCS7mCqpZ0lPTid7ZP5SLw3Q2F6XcrHCQNtJlhhFlmC2vs+xtM Tpnh7T2EOAr7V9rq3C8AWZTCzbSSmyy7dmXSxUgjNt4ZoeyUwdQlhi7q1+ZVBaSk5qHe b978fhBo3VRSbOENccmHt7akJfUsm8ykK9ktkUZV9aasNocpw9v+W62MBsrOhD99Fwm7 fvujXFioxOE/M395lhxJCWd3+tO2htfRC+acvP2GC1yzH2u+PDdHyRvSMshuI4VzWsFq YwJxmI482hIA65nuCitsS04J/Tg9uUhQrdCmDNnF8MCnfC4PAc16VQESq1gAwYbNmWbb dQtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693390466; x=1693995266; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EdvjH/CPUEM+oqwsKsE4qN2wj4+iJ6OkD5HUkdlFZV0=; b=HfxJLyXgXoEUftrSX1lUtM6mRNDupI5FQGC0AQDr0nfHbxZNol0hyJLyNb41i+Q6EC N9RcwvpN+i1OPDIH/6QFinuWZOYnlvR+RvtRIFanUSWfBkDgWITR6K68iqE5CIUGlrmx ocxIKqdHKSKjAIyaMQxp361x3DhKF/YRCrlwLJ0m3MScm59khT2UNVK6tDmZnIH9jtqc tzaSuoczuWnCHx9tOwAr7HALViSDLiRfq0vj85B9oHmrmIBDawFVC9g+RH2wUCQrY+T9 8qbwhuLUQHeQC1A9uqZQlpyUjg5J5v55jtf1LnYXLhpbzRBABGfLFoeT35+KA7mT6MyI xMiw== X-Gm-Message-State: AOJu0YwbFmc5s4RkT6SsKTc615OnINRiSYP9sVB483L25pFp0HWO0gEH 1XcNIT/MBpgL9kNECPcFF9jh3HlJDjt5v1Sl29l8Ow== X-Google-Smtp-Source: AGHT+IHQKossuxw+yAx+jCfeq9vjdkB5gT09J9OnLNAfBds7XPMi5LKzVKaygBBq36DP31Aix9LTfA== X-Received: by 2002:a05:6512:15a9:b0:4fd:f889:b9d2 with SMTP id bp41-20020a05651215a900b004fdf889b9d2mr1431960lfb.38.1693390465320; Wed, 30 Aug 2023 03:14:25 -0700 (PDT) Received: from helsinki-03.engr ([2a01:4f9:6b:2a47::2]) by smtp.gmail.com with ESMTPSA id w7-20020a19c507000000b004fe36e673b8sm2327579lfe.178.2023.08.30.03.14.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 03:14:24 -0700 (PDT) From: Manolis Tsamis To: gcc-patches@gcc.gnu.org Cc: Philipp Tomsich , Robin Dapp , Jakub Jelinek , Richard Sandiford , Manolis Tsamis Subject: [PATCH v3 2/4] ifcvt: Allow more operations in multiple set if conversion Date: Wed, 30 Aug 2023 12:13:58 +0200 Message-Id: <20230830101400.1539313-3-manolis.tsamis@vrull.eu> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230830101400.1539313-1-manolis.tsamis@vrull.eu> References: <20230830101400.1539313-1-manolis.tsamis@vrull.eu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,JMQ_SPF_NEUTRAL,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 List-Id: Currently the operations allowed for if conversion of a basic block with multiple sets are few, namely REG, SUBREG and CONST_INT (as controlled by bb_ok_for_noce_convert_multiple_sets). This commit allows more operations (arithmetic, compare, etc) to participate in if conversion. The target's profitability hook and ifcvt's costing is expected to reject sequences that are unprofitable. This is especially useful for targets which provide a rich selection of conditional instructions (like aarch64 which has cinc, csneg, csinv, ccmp, ...) which are currently not used in basic blocks with more than a single set. gcc/ChangeLog: * ifcvt.cc (try_emit_cmove_seq): Modify comments. (noce_convert_multiple_sets_1): Modify comments. (bb_ok_for_noce_convert_multiple_sets): Allow more operations. gcc/testsuite/ChangeLog: * gcc.target/aarch64/ifcvt_multiple_sets_arithm.c: New test. Signed-off-by: Manolis Tsamis --- Changes in v3: - Add SCALAR_INT_MODE_P check in bb_ok_for_noce_convert_multiple_sets. - Allow rewiring of multiple regs. - Refactor code with noce_multiple_sets_info. - Remove old code for subregs. gcc/ifcvt.cc | 63 ++++++++++----- .../aarch64/ifcvt_multiple_sets_arithm.c | 79 +++++++++++++++++++ 2 files changed, 123 insertions(+), 19 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/ifcvt_multiple_sets_arithm.c diff --git a/gcc/ifcvt.cc b/gcc/ifcvt.cc index 3273aeca125..efe8ab1577a 100644 --- a/gcc/ifcvt.cc +++ b/gcc/ifcvt.cc @@ -3215,13 +3215,13 @@ try_emit_cmove_seq (struct noce_if_info *if_info, rtx temp, /* We have something like: if (x > y) - { i = a; j = b; k = c; } + { i = EXPR_A; j = EXPR_B; k = EXPR_C; } Make it: - tmp_i = (x > y) ? a : i; - tmp_j = (x > y) ? b : j; - tmp_k = (x > y) ? c : k; + tmp_i = (x > y) ? EXPR_A : i; + tmp_j = (x > y) ? EXPR_B : j; + tmp_k = (x > y) ? EXPR_C : k; i = tmp_i; j = tmp_j; k = tmp_k; @@ -3637,11 +3637,10 @@ noce_convert_multiple_sets_1 (struct noce_if_info *if_info, -/* Return true iff basic block TEST_BB is comprised of only - (SET (REG) (REG)) insns suitable for conversion to a series - of conditional moves. Also check that we have more than one set - (other routines can handle a single set better than we would), and - fewer than PARAM_MAX_RTL_IF_CONVERSION_INSNS sets. While going +/* Return true iff basic block TEST_BB is suitable for conversion to a + series of conditional moves. Also check that we have more than one + set (other routines can handle a single set better than we would), + and fewer than PARAM_MAX_RTL_IF_CONVERSION_INSNS sets. While going through the insns store the sum of their potential costs in COST. */ static bool @@ -3667,20 +3666,46 @@ bb_ok_for_noce_convert_multiple_sets (basic_block test_bb, unsigned *cost) rtx dest = SET_DEST (set); rtx src = SET_SRC (set); - /* We can possibly relax this, but for now only handle REG to REG - (including subreg) moves. This avoids any issues that might come - from introducing loads/stores that might violate data-race-freedom - guarantees. */ - if (!REG_P (dest)) + /* Do not handle anything involving memory loads/stores since it might + violate data-race-freedom guarantees. */ + if (!REG_P (dest) || contains_mem_rtx_p (src)) + return false; + + if (!SCALAR_INT_MODE_P (GET_MODE (src))) return false; - if (!((REG_P (src) || CONSTANT_P (src)) - || (GET_CODE (src) == SUBREG && REG_P (SUBREG_REG (src)) - && subreg_lowpart_p (src)))) + /* Allow a wide range of operations and let the costing function decide + if the conversion is worth it later. */ + enum rtx_code code = GET_CODE (src); + if (!(CONSTANT_P (src) + || code == REG + || code == SUBREG + || code == ZERO_EXTEND + || code == SIGN_EXTEND + || code == NOT + || code == NEG + || code == PLUS + || code == MINUS + || code == AND + || code == IOR + || code == MULT + || code == ASHIFT + || code == ASHIFTRT + || code == NE + || code == EQ + || code == GE + || code == GT + || code == LE + || code == LT + || code == GEU + || code == GTU + || code == LEU + || code == LTU + || code == COMPARE)) return false; - /* Destination must be appropriate for a conditional write. */ - if (!noce_operand_ok (dest)) + /* Destination and source must be appropriate. */ + if (!noce_operand_ok (dest) || !noce_operand_ok (src)) return false; /* We must be able to conditionally move in this mode. */ diff --git a/gcc/testsuite/gcc.target/aarch64/ifcvt_multiple_sets_arithm.c b/gcc/testsuite/gcc.target/aarch64/ifcvt_multiple_sets_arithm.c new file mode 100644 index 00000000000..d977f4d62ec --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/ifcvt_multiple_sets_arithm.c @@ -0,0 +1,79 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-rtl-ce1" } */ + +void sink2(int, int); +void sink3(int, int, int); + +void cond1(int cond, int x, int y) +{ + if (cond) + { + x = x << 4; + y = 1; + } + + sink2(x, y); +} + +void cond2(int cond, int x, int y) +{ + if (cond) + { + x++; + y++; + } + + sink2(x, y); +} + +void cond3(int cond, int x1, int x2, int x3) +{ + if (cond) + { + x1++; + x2++; + x3++; + } + + sink3(x1, x2, x3); +} + +void cond4(int cond, int x, int y) +{ + if (cond) + { + x += 2; + y += 3; + } + + sink2(x, y); +} + +void cond5(int cond, int x, int y, int r1, int r2) +{ + if (cond) + { + x = r1 + 2; + y = r2 - 34; + } + + sink2(x, y); +} + +void cond6(int cond, int x, int y) +{ + if (cond) + { + x = -x; + y = ~y; + } + + sink2(x, y); +} + +/* { dg-final { scan-assembler-times "cinc\t" 5 } } */ +/* { dg-final { scan-assembler-times "csneg\t" 1 } } */ +/* { dg-final { scan-assembler-times "csinv\t" 1 } } */ +/* { dg-final { scan-assembler "csel\t" } } */ + +/* { dg-final { scan-rtl-dump-times "if-conversion succeeded through noce_convert_multiple_sets" 6 "ce1" } } */ \ No newline at end of file -- 2.34.1