From patchwork Fri May 1 16:42:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Love X-Patchwork-Id: 1281393 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: 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=S5ckj2ij; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 49DJ204R0Xz9sTF for ; Sat, 2 May 2020 02:42:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E8E6F38930DA; Fri, 1 May 2020 16:42:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8E6F38930DA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1588351331; bh=BOlJj7neicaiFwxNCYmKHvFvOtBUAOH1ev8i4FJ6hUA=; h=Subject:To:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=S5ckj2ijGppmegzDG6zCrGZVWfydnWydj5fbrZJ/xsPVnBid7eovigB5/hrG4wpYr RgBXcEMiFg3uOCwD24F3HxJy3y5SoZZbLhB92paxeeFd5RIyEIS/ifran1z4TOEca/ yAHgE8roACTyY9SP+DW8FfbIBkJT64kZK26+Q6jU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 5143D3851C31 for ; Fri, 1 May 2020 16:42:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5143D3851C31 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 041GXD71150065 for ; Fri, 1 May 2020 12:42:07 -0400 Received: from ppma03wdc.us.ibm.com (ba.79.3fa9.ip4.static.sl-reverse.com [169.63.121.186]) by mx0b-001b2d01.pphosted.com with ESMTP id 30r825xd0n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 01 May 2020 12:42:07 -0400 Received: from pps.filterd (ppma03wdc.us.ibm.com [127.0.0.1]) by ppma03wdc.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 041GeVhH001514 for ; Fri, 1 May 2020 16:42:07 GMT Received: from b01cxnp23033.gho.pok.ibm.com (b01cxnp23033.gho.pok.ibm.com [9.57.198.28]) by ppma03wdc.us.ibm.com with ESMTP id 30mcu76m4u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 01 May 2020 16:42:07 +0000 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp23033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 041Gg6mV52101590 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 1 May 2020 16:42:06 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9669C28059; Fri, 1 May 2020 16:42:06 +0000 (GMT) Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E144F28058; Fri, 1 May 2020 16:42:05 +0000 (GMT) Received: from oc3304648336.ibm.com (unknown [9.160.124.63]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP; Fri, 1 May 2020 16:42:05 +0000 (GMT) Message-ID: Subject: [PATCH] rs6000, fix vec_first_match_index for nulls To: Segher Boessenkool , David Edelsohn Date: Fri, 01 May 2020 09:42:04 -0700 X-Mailer: Evolution 3.28.5 (3.28.5-5.el7) Mime-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.676 definitions=2020-05-01_10:2020-05-01, 2020-05-01 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 spamscore=0 impostorscore=0 clxscore=1015 phishscore=0 lowpriorityscore=0 priorityscore=1501 malwarescore=0 suspectscore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2005010126 X-Spam-Status: No, score=-25.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Carl Love via Gcc-patches From: Carl Love Reply-To: Carl Love Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" GCC maintainers: The following patch fixes PR94833, vec_first_match_index does not function as described in its description. The builtin does not handle vector elements which are zero correctly. The following patch fixes the issue and adds additional test cases to verify the vec_first_match_index builtin and related builtins work correctly with zero elements. The patch has been compiled and tested on powerpc64le-unknown-linux-gnu (Power 9 LE) with no regression errors. Please let me know if the patch is acceptable for mainline and for backporting as needed. Thanks. Carl Love -------------------------------------------------------------- gcc/ChangeLog 2020-04-30 Carl Love PR target/94833 * config/rs6000/vsx.md (define_expand): Fix instruction generation for first_match_index_. * testsuite/gcc.target/powerpc/builtins-8-p9-runnable.c (main): Add additional test cases with zero vector elements. --- gcc/config/rs6000/vsx.md | 4 +- .../powerpc/builtins-8-p9-runnable.c | 118 ++++++++++++++++++ 2 files changed, 120 insertions(+), 2 deletions(-) diff --git a/gcc/config/rs6000/vsx.md b/gcc/config/rs6000/vsx.md index 1fcc1b03096..12a0d5e668c 100644 --- a/gcc/config/rs6000/vsx.md +++ b/gcc/config/rs6000/vsx.md @@ -4803,8 +4803,8 @@ rtx cmp_result = gen_reg_rtx (mode); rtx not_result = gen_reg_rtx (mode); - emit_insn (gen_vcmpnez (cmp_result, operands[1], - operands[2])); + emit_insn (gen_vcmpne (cmp_result, operands[1], + operands[2])); emit_insn (gen_one_cmpl2 (not_result, cmp_result)); sh = GET_MODE_SIZE (GET_MODE_INNER (mode)) / 2; diff --git a/gcc/testsuite/gcc.target/powerpc/builtins-8-p9-runnable.c b/gcc/testsuite/gcc.target/powerpc/builtins-8-p9-runnable.c index b2f7dc855e8..19457eebfc4 100644 --- a/gcc/testsuite/gcc.target/powerpc/builtins-8-p9-runnable.c +++ b/gcc/testsuite/gcc.target/powerpc/builtins-8-p9-runnable.c @@ -103,6 +103,31 @@ int main() { The element index in natural element order is returned for the first match or the number of elements if there is no match. */ /* char */ + char_src1 = (vector signed char) { 0x40, 0, 0x40, 0x40, + 0x40, 0x40, 0x40, 0x40, + 0x40, 0x40, 0x40, 0x40, + 0x40, 0x40, 0x40, 0x40 }; + + char_src2 = (vector signed char) {0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0}; + expected_result = 1; + + result = vec_first_match_index (char_src1, char_src2); + +#ifdef DEBUG2 + print_signed_char("src1", char_src1); + print_signed_char("src2", char_src2); + printf(" vec_first_match_index = %d\n\n", result); +#endif + + if (result != expected_result) +#ifdef DEBUG + printf("Error: char first match result (%d) does not match expected result (%d)\n", + result, expected_result); +#else + abort(); +#endif + char_src1 = (vector signed char) {-1, 2, 3, 4, -5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; char_src2 = (vector signed char) {-1, 2, 3, 20, -5, 6, 7, 8, @@ -367,6 +392,50 @@ int main() { The element index in BE order is returned for the first mismatch or the number of elements if there is no match. */ /* char */ + char_src1 = (vector signed char) {1, 2, 0, 4, -5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16}; + char_src2 = (vector signed char) {1, 2, 0, 20, -5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16}; + expected_result = 3; + + result = vec_first_mismatch_index (char_src1, char_src2); + +#ifdef DEBUG2 + print_signed_char("src1", char_src1); + print_signed_char("src2", char_src2); + printf("vec_first_mismatch_index = %d\n\n", result); +#endif + + if (result != expected_result) +#ifdef DEBUG + printf("Error: char first mismatch result (%d) does not match expected result (%d)\n", + result, expected_result); +#else + abort(); +#endif + + char_src1 = (vector signed char) {0, 2, 3, 4, -5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16}; + char_src2 = (vector signed char) {0, 2, 3, 20, -5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16}; + expected_result = 3; + + result = vec_first_mismatch_index (char_src1, char_src2); + +#ifdef DEBUG2 + print_signed_char("src1", char_src1); + print_signed_char("src2", char_src2); + printf("vec_first_mismatch_index = %d\n\n", result); +#endif + + if (result != expected_result) +#ifdef DEBUG + printf("Error: char first mismatch result (%d) does not match expected result (%d)\n", + result, expected_result); +#else + abort(); +#endif + char_src1 = (vector signed char) {-1, 2, 3, 4, -5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; char_src2 = (vector signed char) {-1, 2, 3, 20, -5, 6, 7, 8, @@ -673,6 +742,33 @@ int main() { The element index in BE order is returned for the first match or the number of elements if there is no match. */ /* char */ + char_src1 = (vector signed char) { 0x40, 0, 0x40, 0x40, + 0x40, 0x40, 0x40, 0x40, + 0x40, 0x40, 0x40, 0x40, + 0x40, 0x40, 0x40, 0x40 }; + + char_src2 = (vector signed char) { 0x41, 0, 0x43, 0x44, + 0x45, 0x46, 0x47, 0x40, + 0x40, 0x40, 0x40, 0x40, + 0x40, 0x40, 0x40, 0x40 }; + expected_result = 1; + + result = vec_first_match_or_eos_index (char_src1, char_src2); + +#ifdef DEBUG2 + print_signed_char("src1", char_src1); + print_signed_char("src2", char_src2); + printf("vec_first_match_or_eos_index = %d\n\n", result); +#endif + + if (result != expected_result) +#ifdef DEBUG + printf("Error: char first match result (%d) does not match expected result (%d)\n", + result, expected_result); +#else + abort(); +#endif + char_src1 = (vector signed char) {-1, 2, 3, 4, -5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; char_src2 = (vector signed char) {-1, 2, 3, 20, -5, 6, 7, 8, @@ -1065,6 +1161,28 @@ int main() { The element index in BE order is returned for the first mismatch or the number of elements if there is no match. */ /* char */ + char_src1 = (vector signed char) {1, 2, 0, 4, -5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16}; + char_src2 = (vector signed char) {1, 2, 0, 20, -5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16}; + expected_result = 2; + + result = vec_first_mismatch_or_eos_index (char_src1, char_src2); + +#ifdef DEBUG2 + print_signed_char("src1", char_src1); + print_signed_char("src2", char_src2); + printf("vec_first_mismatch_or_eos_index = %d\n\n", result); +#endif + + if (result != expected_result) +#ifdef DEBUG + printf("Error: char first mismatch or EOS result (%d) does not match expected result (%d)\n", + result, expected_result); +#else + abort(); +#endif + char_src1 = (vector signed char) {-1, 2, 3, 4, -5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; char_src2 = (vector signed char) {-1, 2, 3, 20, -5, 6, 7, 8,