From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id A2C6F3858D20 for ; Fri, 11 Aug 2023 09:16:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A2C6F3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=marvell.com Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37AN2YaE011353 for ; Fri, 11 Aug 2023 02:16:02 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=WnMsyqEgXbimWEXkO/mo0Nb9OsHApshnYJ/xtoGQmJM=; b=jCQUwq/s7VoEwVEmPwFgPCBlgxops05McMNaUuJHs6W3K5oRhCgUM1SUwEPO1t05LgqU 4tu8+HFF8VAkHUlfrK4eDqEjZPqXgTCUGgBkBlCB4ijouEAk7CNowg1J6GbiR7cHoQbS /DPEv48VaUf4JwzEPPuXEvkmGJZ80oAEeC9Gd2D+ihGzYaxeLswoxIX8Ti0XUeJQxNH6 SphHt29CZqeYhwYXhv11YHcVz0+ZZILh55oHxH1Y8L89HfTh6xyjfmIQVCFyumFsKrzO H9ZrXnsOBOmFrjrV4E4CKbvJbwjcWNNoXCJq+DqVXCpdCUMcholOgs7ZT03T2SRLuc+s Xg== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3sd8ya1j8y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Fri, 11 Aug 2023 02:16:01 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 11 Aug 2023 02:15:59 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Fri, 11 Aug 2023 02:15:59 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 6D3343F706B; Fri, 11 Aug 2023 02:15:59 -0700 (PDT) From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH 1/2] PHI-OPT [PR 110984]: Add support for NE_EXPR/EQ_EXPR with casts to spaceship_replacement Date: Fri, 11 Aug 2023 02:15:50 -0700 Message-ID: <20230811091551.2758227-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: PtuWAVLhbQ93PtBTupAlPnnr4X769qBW X-Proofpoint-GUID: PtuWAVLhbQ93PtBTupAlPnnr4X769qBW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-08-10_20,2023-08-10_01,2023-05-22_02 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,SCC_10_SHORT_WORD_LINES,SCC_5_SHORT_WORD_LINES,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: So with my next VRP patch, VRP causes: ``` # c$_M_value_18 = PHI <-1(3), 0(2), 1(4)> _11 = (unsigned int) c$_M_value_18; _16 = _11 <= 1; ``` To be changed to: ``` # c$_M_value_18 = PHI <-1(3), 0(2), 1(4)> _11 = (unsigned int) c$_M_value_18; _16 = _11 != 4294967295; ``` So let's add support for the above. A few changes was needed, first to change the range check of the rhs of the comparison to possibly integer_all_onesp also. The next is to add support for the cast and EQ/NE case. Note on the testcases pr110984-1.c is basically pr94589-2.c but with what the C++ code is doing with the signed char type; pr110984-2.c is pr110984-1.c with the cast added to give an explicit testcase to test against. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. Thanks, Andrew Pinski PR tree-optimization/110984 gcc/ChangeLog: * tree-ssa-phiopt.cc (spaceship_replacement): Add support for NE/EQ for the cast case. gcc/testsuite/ChangeLog: * gcc.dg/pr110984-1.c: New test. * gcc.dg/pr110984-2.c: New test. --- gcc/testsuite/gcc.dg/pr110984-1.c | 37 +++++++++++++++++++++++++++++++ gcc/testsuite/gcc.dg/pr110984-2.c | 21 ++++++++++++++++++ gcc/tree-ssa-phiopt.cc | 19 +++++++++++++--- 3 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr110984-1.c create mode 100644 gcc/testsuite/gcc.dg/pr110984-2.c diff --git a/gcc/testsuite/gcc.dg/pr110984-1.c b/gcc/testsuite/gcc.dg/pr110984-1.c new file mode 100644 index 00000000000..85b19eb8279 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr110984-1.c @@ -0,0 +1,37 @@ +/* PR tree-optimization/110984 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -g0 -ffast-math -fdump-tree-optimized" } */ +/* { dg-final { scan-tree-dump-times "\[ij]_\[0-9]+\\(D\\) (?:<|<=|==|!=|>|>=) \[ij]_\[0-9]+\\(D\\)" 14 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "i_\[0-9]+\\(D\\) (?:<|<=|==|!=|>|>=) 5\\.0" 14 "optimized" } } */ + +/* This is similar to pr94589-2.c except use signed char as the type for the [-1,2] case */ + +#define A __attribute__((noipa)) +A int f1 (double i, double j) { signed char c; if (i == j) c = 0; else if (i < j) c = -1; else if (i > j) c = 1; else c = 2; return c == 0; } +A int f2 (double i, double j) { signed char c; if (i == j) c = 0; else if (i < j) c = -1; else if (i > j) c = 1; else c = 2; return c != 0; } +A int f3 (double i, double j) { signed char c; if (i == j) c = 0; else if (i < j) c = -1; else if (i > j) c = 1; else c = 2; return c > 0; } +A int f4 (double i, double j) { signed char c; if (i == j) c = 0; else if (i < j) c = -1; else if (i > j) c = 1; else c = 2; return c < 0; } +A int f5 (double i, double j) { signed char c; if (i == j) c = 0; else if (i < j) c = -1; else if (i > j) c = 1; else c = 2; return c >= 0; } +A int f6 (double i, double j) { signed char c; if (i == j) c = 0; else if (i < j) c = -1; else if (i > j) c = 1; else c = 2; return c <= 0; } +A int f7 (double i, double j) { signed char c; if (i == j) c = 0; else if (i < j) c = -1; else if (i > j) c = 1; else c = 2; return c == -1; } +A int f8 (double i, double j) { signed char c; if (i == j) c = 0; else if (i < j) c = -1; else if (i > j) c = 1; else c = 2; return c != -1; } +A int f9 (double i, double j) { signed char c; if (i == j) c = 0; else if (i < j) c = -1; else if (i > j) c = 1; else c = 2; return c > -1; } +A int f10 (double i, double j) { signed char c; if (i == j) c = 0; else if (i < j) c = -1; else if (i > j) c = 1; else c = 2; return c <= -1; } +A int f11 (double i, double j) { signed char c; if (i == j) c = 0; else if (i < j) c = -1; else if (i > j) c = 1; else c = 2; return c == 1; } +A int f12 (double i, double j) { signed char c; if (i == j) c = 0; else if (i < j) c = -1; else if (i > j) c = 1; else c = 2; return c != 1; } +A int f13 (double i, double j) { signed char c; if (i == j) c = 0; else if (i < j) c = -1; else if (i > j) c = 1; else c = 2; return c < 1; } +A int f14 (double i, double j) { signed char c; if (i == j) c = 0; else if (i < j) c = -1; else if (i > j) c = 1; else c = 2; return c >= 1; } +A int f15 (double i) { signed char c; if (i == 5.0) c = 0; else if (i < 5.0) c = -1; else if (i > 5.0) c = 1; else c = 2; return c == 0; } +A int f16 (double i) { signed char c; if (i == 5.0) c = 0; else if (i < 5.0) c = -1; else if (i > 5.0) c = 1; else c = 2; return c != 0; } +A int f17 (double i) { signed char c; if (i == 5.0) c = 0; else if (i < 5.0) c = -1; else if (i > 5.0) c = 1; else c = 2; return c > 0; } +A int f18 (double i) { signed char c; if (i == 5.0) c = 0; else if (i < 5.0) c = -1; else if (i > 5.0) c = 1; else c = 2; return c < 0; } +A int f19 (double i) { signed char c; if (i == 5.0) c = 0; else if (i < 5.0) c = -1; else if (i > 5.0) c = 1; else c = 2; return c >= 0; } +A int f20 (double i) { signed char c; if (i == 5.0) c = 0; else if (i < 5.0) c = -1; else if (i > 5.0) c = 1; else c = 2; return c <= 0; } +A int f21 (double i) { signed char c; if (i == 5.0) c = 0; else if (i < 5.0) c = -1; else if (i > 5.0) c = 1; else c = 2; return c == -1; } +A int f22 (double i) { signed char c; if (i == 5.0) c = 0; else if (i < 5.0) c = -1; else if (i > 5.0) c = 1; else c = 2; return c != -1; } +A int f23 (double i) { signed char c; if (i == 5.0) c = 0; else if (i < 5.0) c = -1; else if (i > 5.0) c = 1; else c = 2; return c > -1; } +A int f24 (double i) { signed char c; if (i == 5.0) c = 0; else if (i < 5.0) c = -1; else if (i > 5.0) c = 1; else c = 2; return c <= -1; } +A int f25 (double i) { signed char c; if (i == 5.0) c = 0; else if (i < 5.0) c = -1; else if (i > 5.0) c = 1; else c = 2; return c == 1; } +A int f26 (double i) { signed char c; if (i == 5.0) c = 0; else if (i < 5.0) c = -1; else if (i > 5.0) c = 1; else c = 2; return c != 1; } +A int f27 (double i) { signed char c; if (i == 5.0) c = 0; else if (i < 5.0) c = -1; else if (i > 5.0) c = 1; else c = 2; return c < 1; } +A int f28 (double i) { signed char c; if (i == 5.0) c = 0; else if (i < 5.0) c = -1; else if (i > 5.0) c = 1; else c = 2; return c >= 1; } diff --git a/gcc/testsuite/gcc.dg/pr110984-2.c b/gcc/testsuite/gcc.dg/pr110984-2.c new file mode 100644 index 00000000000..cddce045745 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr110984-2.c @@ -0,0 +1,21 @@ +/* PR tree-optimization/110984 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -g0 -ffast-math -fdump-tree-optimized" } */ +/* { dg-final { scan-tree-dump-times "\[ij]_\[0-9]+\\(D\\) (?:<|<=|==|!=|>|>=) \[ij]_\[0-9]+\\(D\\)" 6 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "i_\[0-9]+\\(D\\) (?:<|<=|==|!=|>|>=) 5\\.0" 6 "optimized" } } */ + +/* This is similar to pr94589-2.c except use signed char and use unsigned types to check against the variable, which means removing the non !=/== comparisons. */ + +#define A __attribute__((noipa)) +A int f1 (double i, double j) { signed char c; if (i == j) c = 0; else if (i < j) c = -1; else if (i > j) c = 1; else c = 2; unsigned t = c; return t == 0; } +A int f2 (double i, double j) { signed char c; if (i == j) c = 0; else if (i < j) c = -1; else if (i > j) c = 1; else c = 2; unsigned t = c; return t != 0; } +A int f7 (double i, double j) { signed char c; if (i == j) c = 0; else if (i < j) c = -1; else if (i > j) c = 1; else c = 2; unsigned t = c; return t == -1; } +A int f8 (double i, double j) { signed char c; if (i == j) c = 0; else if (i < j) c = -1; else if (i > j) c = 1; else c = 2; unsigned t = c; return t != -1; } +A int f11 (double i, double j) { signed char c; if (i == j) c = 0; else if (i < j) c = -1; else if (i > j) c = 1; else c = 2; unsigned t = c; return t == 1; } +A int f12 (double i, double j) { signed char c; if (i == j) c = 0; else if (i < j) c = -1; else if (i > j) c = 1; else c = 2; unsigned t = c; return t != 1; } +A int f15 (double i) { signed char c; if (i == 5.0) c = 0; else if (i < 5.0) c = -1; else if (i > 5.0) c = 1; else c = 2; unsigned t = c; return t == 0; } +A int f16 (double i) { signed char c; if (i == 5.0) c = 0; else if (i < 5.0) c = -1; else if (i > 5.0) c = 1; else c = 2; unsigned t = c; return t != 0; } +A int f21 (double i) { signed char c; if (i == 5.0) c = 0; else if (i < 5.0) c = -1; else if (i > 5.0) c = 1; else c = 2; unsigned t = c; return t == -1; } +A int f22 (double i) { signed char c; if (i == 5.0) c = 0; else if (i < 5.0) c = -1; else if (i > 5.0) c = 1; else c = 2; unsigned t = c; return t != -1; } +A int f25 (double i) { signed char c; if (i == 5.0) c = 0; else if (i < 5.0) c = -1; else if (i > 5.0) c = 1; else c = 2; unsigned t = c; return t == 1; } +A int f26 (double i) { signed char c; if (i == 5.0) c = 0; else if (i < 5.0) c = -1; else if (i > 5.0) c = 1; else c = 2; unsigned t = c; return t != 1; } diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index 485662dfcc7..5f24d62c49a 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -2346,7 +2346,8 @@ spaceship_replacement (basic_block cond_bb, basic_block middle_bb, } if (lhs != (orig_use_lhs ? orig_use_lhs : phires) || !tree_fits_shwi_p (rhs) - || !IN_RANGE (tree_to_shwi (rhs), -1, 1)) + || !(IN_RANGE (tree_to_shwi (rhs), 0, 1) + || integer_all_onesp (rhs))) return false; if (is_cast) @@ -2356,9 +2357,20 @@ spaceship_replacement (basic_block cond_bb, basic_block middle_bb, /* As for -ffast-math we assume the 2 return to be impossible, canonicalize (unsigned) res <= 1U or (unsigned) res < 2U into res >= 0 and (unsigned) res > 1U - or (unsigned) res >= 2U as res < 0. */ + or (unsigned) res >= 2U as res < 0. + Sometimes we get (unsigned)res != N. Support those cases too. */ switch (cmp) { + case NE_EXPR: + case EQ_EXPR: + { + tree newrhs = fold_convert (TREE_TYPE (phires), rhs); + tree tmp = fold_convert (TREE_TYPE (rhs), newrhs); + if (!tree_int_cst_equal (rhs, tmp)) + return false; + rhs = newrhs; + break; + } case LE_EXPR: if (!integer_onep (rhs)) return false; @@ -2382,7 +2394,8 @@ spaceship_replacement (basic_block cond_bb, basic_block middle_bb, default: return false; } - rhs = build_zero_cst (TREE_TYPE (phires)); + if (cmp != EQ_EXPR && cmp != NE_EXPR) + rhs = build_zero_cst (TREE_TYPE (phires)); } else if (orig_use_lhs) { -- 2.31.1