From patchwork Tue Feb 19 09:38:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Li Jia He X-Patchwork-Id: 1044572 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-496621-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="dcvuThFY"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 443bKf2BNzz9s3l for ; Tue, 19 Feb 2019 20:39:16 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:mime-version:content-type :content-transfer-encoding:message-id; q=dns; s=default; b=E0neO vAXuexL94ZyrwCt95e1d9Lzssb4VoVWyDF2f8irrmONTcrkQ+GwvAfFwEFroanyA MAnMIdDC0+CM4aeDthYEJh0pD8vdDJVtSyuOisAJEy+GTm3wDcgu60+RP65i6Q0r 5yRl0xg0zEo2NbvFxFHw2h8vnCdQkbwPzJQ1b4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:mime-version:content-type :content-transfer-encoding:message-id; s=default; bh=tWkqvfGGKcW 9ecCIZdEPDaeJ0m8=; b=dcvuThFY4FobUSLUpext0xr7Tvl35ebEE5l1RqxDyQi 9NTQwjqCVjaq4FyIcYJCA6IOYcX/qzHvFm+k0tr0WjTfvElI3rsToNMPY9ySVPbt Pg/5zHUkQNp8zdrDoUxukQxFCj+0uX6CN0wDAF9fJPd/TJ5AGiwLss8VuKEBpIds = Received: (qmail 120018 invoked by alias); 19 Feb 2019 09:39:09 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 119584 invoked by uid 89); 19 Feb 2019 09:39:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-27.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=Jia, jia, sk:gimple_ X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 19 Feb 2019 09:39:07 +0000 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x1J9ceX8103016 for ; Tue, 19 Feb 2019 04:39:05 -0500 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0b-001b2d01.pphosted.com with ESMTP id 2qres1synr-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 19 Feb 2019 04:39:05 -0500 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 19 Feb 2019 09:39:03 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 19 Feb 2019 09:39:01 -0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x1J9cx4a20447266 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Feb 2019 09:39:00 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DBC86A405B; Tue, 19 Feb 2019 09:38:59 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 204D2A4054; Tue, 19 Feb 2019 09:38:59 +0000 (GMT) Received: from genoa.aus.stglabs.ibm.com (unknown [9.40.192.157]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 19 Feb 2019 09:38:58 +0000 (GMT) From: Li Jia He To: gcc-patches@gcc.gnu.org Cc: helijia@linux.ibm.com, segher@kernel.crashing.org, wschmidt@linux.ibm.com Subject: [PATCH] rs6000: Fix PR 88100, range check for vec_splat_{su}{8, 16, 32} Date: Tue, 19 Feb 2019 03:38:56 -0600 MIME-Version: 1.0 x-cbid: 19021909-0012-0000-0000-000002F772BA X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19021909-0013-0000-0000-0000212EFECF Message-Id: <1550569136-751-1-git-send-email-helijia@linux.ibm.com> X-IsSubscribed: yes Hi, GCC revision 259524 implemented range check for the vec_splat_{su}{8,16,32} builtins. However, as a consequence of the implementation, the range check is not done correctly for the expected vspltis[bhw] instructions.  The result is that we may not get a valid error message if the valid range of the data is exceeded. Although the input of the function prototype of vec_splat_{su}{8,16,32} is const int, the actual data usage range is limited to the data range of 5 bits signed. We should limit the int_cst.val[0] data to the 5 bit signed data range without any modification in the input arg0 parameter. However, the sext_hwi function intercepts the data of TREE_INT_CST_LOW (arg0) as size bits in the sext_hwi (TREE_INT_CST_LOW (arg0), size) statement. This will cause some of the excess data to fall within the range of 5 bits signed, so that the correct diagnostic information cannot be generated, we need to remove the sext_hwi to ensure that the input data has not been modified. This patch fix range check for the vec_splat_s[8,16,32] builtins. The argument must be a 5-bit const int as specified for the vspltis[bhw] instructions. The regression testing for the patch was done on GCC mainline on powerpc64le-unknown-linux-gnu (Power 8 LE) with no regressions. Is it OK for trunk? Thanks, Lijia --- gcc/ChangeLog 2019-02-15 Li Jia He PR target/88100 * gcc/config/rs6000/rs6000.c (rs6000_gimple_fold_builtin): Remove sext_hwi in IN_RANGE (sext_hwi (TREE_INT_CST_LOW (arg0), size), -16, 15). gcc/testsuite/ChangeLog 2019-02-15 Li Jia He PR target/88100 * gcc/testsuite/gcc.target/powerpc/pr88100.c: New testcase. --- gcc/config/rs6000/rs6000.c | 11 +------- gcc/testsuite/gcc.target/powerpc/pr88100.c | 44 ++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/gcc.target/powerpc/pr88100.c diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index aea7925..b1249bc 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -16105,22 +16105,13 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi) case ALTIVEC_BUILTIN_VSPLTISH: case ALTIVEC_BUILTIN_VSPLTISW: { - int size; - if (fn_code == ALTIVEC_BUILTIN_VSPLTISB) - size = 8; - else if (fn_code == ALTIVEC_BUILTIN_VSPLTISH) - size = 16; - else - size = 32; - arg0 = gimple_call_arg (stmt, 0); lhs = gimple_call_lhs (stmt); /* Only fold the vec_splat_*() if the lower bits of arg 0 is a 5-bit signed constant in range -16 to +15. */ if (TREE_CODE (arg0) != INTEGER_CST - || !IN_RANGE (sext_hwi (TREE_INT_CST_LOW (arg0), size), - -16, 15)) + || !IN_RANGE (TREE_INT_CST_LOW (arg0), -16, 15)) return false; gimple_seq stmts = NULL; location_t loc = gimple_location (stmt); diff --git a/gcc/testsuite/gcc.target/powerpc/pr88100.c b/gcc/testsuite/gcc.target/powerpc/pr88100.c new file mode 100644 index 0000000..4452145 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr88100.c @@ -0,0 +1,44 @@ +/* PR88100. Verify that rs6000 gimple-folding code handles the + vec_splat_{su}{8,16,32} invalid data properly. */ + +/* { dg-do compile } */ +/* { dg-require-effective-target powerpc_altivec_ok } */ +/* { dg-options "-maltivec" } */ + +#include + +vector unsigned char +splatu1 (void) +{ + return vec_splat_u8(0x100);/* { dg-error "argument 1 must be a 5-bit signed literal" } */ +} + +vector unsigned short +splatu2 (void) +{ + return vec_splat_u16(0x10000);/* { dg-error "argument 1 must be a 5-bit signed literal" } */ +} + +vector unsigned int +splatu3 (void) +{ + return vec_splat_u32(0x10000000);/* { dg-error "argument 1 must be a 5-bit signed literal" } */ +} + +vector signed char +splats1 (void) +{ + return vec_splat_s8(0x100);/* { dg-error "argument 1 must be a 5-bit signed literal" } */ +} + +vector signed short +splats2 (void) +{ + return vec_splat_s16(0x10000);/* { dg-error "argument 1 must be a 5-bit signed literal" } */ +} + +vector signed int +splats3 (void) +{ + return vec_splat_s32(0x10000000);/* { dg-error "argument 1 must be a 5-bit signed literal" } */ +}