From patchwork Mon Nov 6 15:27:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 118065 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp2889587qgn; Mon, 6 Nov 2017 07:27:47 -0800 (PST) X-Google-Smtp-Source: ABhQp+QQCzbQRVNkdFCiJG7Ub//b1QKZUyTYT8Hx13joaAnKxbLkRrGUVUPpwJk/TXdr7ZfXC3zZ X-Received: by 10.84.138.193 with SMTP id 59mr15250914plp.446.1509982067605; Mon, 06 Nov 2017 07:27:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1509982067; cv=none; d=google.com; s=arc-20160816; b=t69u5Jz4pngzyYortvVfjDsncw7AhG4LdTVjUE40GEd77SjtDE0BI8k3o+WQVcIDzC ICGSwfQuLYLR/ApDmhXsybywJajlkLdj5586mbWpvZTvqCrTI+uHJNcKWnAkxYHOtMyB 3R6kPJquBBvIXKR90e2NrtT4yA+j0EJZcs2s5QUXH1kQ7natQ4+nG7XaHHvkXX9FzJ2j chLTYiCAVyjtZB+m3hMeHtHXwkmdWAVNS8v5eeqLCAlBJXgRIcEkO+xlO6o6ZiSg5GQK koja93QwQfvKPNBAyZrtLEvwNOevTLsDy5ijVfF8H3LfPvd8lP2pYx04OPNNmSWlHERc 3Rhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:date:subject:mail-followup-to:to :from:delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=yt01zQ5ulmcSdIgiE8OKb/1GUp59qEYmwFlHM+X6oQs=; b=ETOqvMGulxrBYNGTpLEHOZCHPVad+jOnFLU3DkvhKxT1/riTxYrMX8htM01veokKyo WnGZhT22h1xoXahEyFATNJTc931QhdQWxO65JYoBDj9G05ZK0VQ8nl0tfnIhE1znnmcM GnFrFS08wGLV7v1BWS6+D8QaSmelOahf/4tbyLUmzoQeNXSuf1qSzmw3MA3mda1TWEpY wSLh7j+wgc1LRG01+ZqrTBjumSyqRWpKwUNEd98LzFLcujKIfu5kaOgyuR9r6KovCC7A 1T8p5SlspETHmrrkB/2b4wSIlHjtlEL0S2ZELPVHOPqvTiZiO5pEWtl9tcdTHe157KFl UcpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jYzlnDwY; spf=pass (google.com: domain of gcc-patches-return-466033-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-466033-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id b68si11582159pga.182.2017.11.06.07.27.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Nov 2017 07:27:47 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-466033-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jYzlnDwY; spf=pass (google.com: domain of gcc-patches-return-466033-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-466033-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=nDAUjigqPilcbs686T4JxTbkw3zdqFkAY6v8dhUFWgG8qOHAHThlG rZ6mefCPnMpeS9j0Nrl4eq+OcRySaFU+a8zrB+ISOlIOiCedA7PYcdE2ddQ5KJO8 4XJvxWgxRBnPMEii7hXCHl//5QK0YV/LZwTPqVsrZZhxZCr0ePG9mE= 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:subject:date:message-id:mime-version:content-type; s= default; bh=JIHIreu7MAe7ve3y3Wwdy3nK4uI=; b=jYzlnDwYUwUwZIRghlHN MDECDS4Dx44oloXH1cidMIapWA5BbNenwcY5FPoy6eAkxag/E/kgqrW7wIp1b8dM O6jp9isRrfA7NN2b+RKNWbrYuP/KWMutktUqcl/cSIV2tuU2n6PdiIQB+w+msS+o eNM9yWzEAzH4YtdfKB3wY30= Received: (qmail 110544 invoked by alias); 6 Nov 2017 15:27:36 -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 110533 invoked by uid 89); 6 Nov 2017 15:27:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=fnoinline, fno-inline X-HELO: mail-wr0-f170.google.com Received: from mail-wr0-f170.google.com (HELO mail-wr0-f170.google.com) (209.85.128.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 06 Nov 2017 15:27:34 +0000 Received: by mail-wr0-f170.google.com with SMTP id p96so8958912wrb.7 for ; Mon, 06 Nov 2017 07:27:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:date:message-id :user-agent:mime-version; bh=yt01zQ5ulmcSdIgiE8OKb/1GUp59qEYmwFlHM+X6oQs=; b=SrxaSh44Z/CSv7OyDZ5BrDpPC9IsvYqXmnC/SHXOHEUw1CUsEWethZeQGvf1QlqoVr HlVwqY+fjyYdipYTvREfZJ1P2PY7UIS5sH0JwRmphqYatgzIoJcoi6h9L7LQ5iQTCYEW Y8V6B4j9ySGBuEemCgCcClfd28VhakanF57Gi62a6P9wqHphf1SaX/Weno6wuVd5R/LJ +K/znnQ9GMxntsqkBJ08ikM7U7P8sdxJzpeEUq/qewFlwqnRy3I/alOmCEPqXDIeuf+Q hxv5Z8rjPOlDeIIwNZf6PJeMpbVyJS8e5bBgPkOlIcY/95mtKn3+oiS32T9547xWgilu blhQ== X-Gm-Message-State: AMCzsaW6f2c070lVzuaFxaWYL3X784u72T7rWd0nmMqaPfh5h0FBe0ie 4fLun9n+yO+OcGvVjimu8RooHRSe0do= X-Received: by 10.223.198.130 with SMTP id j2mr13550633wrg.52.1509982052301; Mon, 06 Nov 2017 07:27:32 -0800 (PST) Received: from localhost (92.40.249.145.threembb.co.uk. [92.40.249.145]) by smtp.gmail.com with ESMTPSA id k13sm26692326wrd.95.2017.11.06.07.27.31 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 06 Nov 2017 07:27:31 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Fix folding of vector mask EQ/NE expressions Date: Mon, 06 Nov 2017 15:27:28 +0000 Message-ID: <87po8vwhpb.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 fold_binary_loc assumed that if the type of the result wasn't a vector, the operands wouldn't be either. This isn't necessarily true for EQ_EXPR and NE_EXPR of vector masks, which can return a single scalar for the mask as a whole. Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64-linux-gnu. OK to install? Richard 2017-11-06 Richard Sandiford Alan Hayward David Sherwood gcc/ * fold-const.c (fold_binary_loc): Check the argument types rather than the result type when testing for a vector operation. gcc/testsuite/ * gcc.target/aarch64/sve_vec_bool_cmp_1.c: New test. * gcc.target/aarch64/sve_vec_bool_cmp_1_run.c: Likweise. Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c 2017-11-06 15:26:35.441288554 +0000 +++ gcc/fold-const.c 2017-11-06 15:26:35.595423552 +0000 @@ -9392,7 +9392,7 @@ fold_binary_loc (location_t loc, if ((code == BIT_AND_EXPR || code == BIT_IOR_EXPR || code == EQ_EXPR || code == NE_EXPR) - && TREE_CODE (type) != VECTOR_TYPE + && TREE_CODE (TREE_TYPE (arg0)) != VECTOR_TYPE && ((truth_value_p (TREE_CODE (arg0)) && (truth_value_p (TREE_CODE (arg1)) || (TREE_CODE (arg1) == BIT_AND_EXPR Index: gcc/testsuite/gcc.target/aarch64/sve_vec_bool_cmp_1.c =================================================================== --- /dev/null 2017-11-03 22:04:05.605699023 +0000 +++ gcc/testsuite/gcc.target/aarch64/sve_vec_bool_cmp_1.c 2017-11-06 15:26:35.595423552 +0000 @@ -0,0 +1,40 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ftree-vectorize -march=armv8-a+sve" } */ + +#include +#include + +#define VEC_BOOL(NAME, OP, VARTYPE, INDUCTYPE) \ +void __attribute__ ((noinline, noclone)) \ +vec_bool_##NAME##_##VARTYPE##_##INDUCTYPE (VARTYPE *dst, VARTYPE *src, \ + INDUCTYPE start, \ + INDUCTYPE n, \ + INDUCTYPE mask) \ +{ \ + for (INDUCTYPE i = 0; i < n; i++) \ + { \ + bool lhs = i >= start; \ + bool rhs = (i & mask) != 0x3D; \ + if (lhs OP rhs) \ + dst[i] = src[i]; \ + } \ +} + +#define TEST_OP(T, NAME, OP) \ + T (NAME, OP, uint8_t, uint8_t) \ + T (NAME, OP, uint16_t, uint16_t) \ + T (NAME, OP, uint32_t, uint32_t) \ + T (NAME, OP, uint64_t, uint64_t) \ + T (NAME, OP, float, uint32_t) \ + T (NAME, OP, double, uint64_t) + +#define TEST_ALL(T) \ + TEST_OP (T, cmpeq, ==) \ + TEST_OP (T, cmpne, !=) + +TEST_ALL (VEC_BOOL) + +/* Both cmpne and cmpeq loops will contain an exclusive predicate or. */ +/* { dg-final { scan-assembler-times {\teors?\tp[0-9]*\.b, p[0-7]/z, p[0-9]*\.b, p[0-9]*\.b\n} 12 } } */ +/* cmpeq will also contain a predicate not operation. */ +/* { dg-final { scan-assembler-times {\tnot\tp[0-9]*\.b, p[0-7]/z, p[0-9]*\.b\n} 6 } } */ Index: gcc/testsuite/gcc.target/aarch64/sve_vec_bool_cmp_1_run.c =================================================================== --- /dev/null 2017-11-03 22:04:05.605699023 +0000 +++ gcc/testsuite/gcc.target/aarch64/sve_vec_bool_cmp_1_run.c 2017-11-06 15:26:35.595423552 +0000 @@ -0,0 +1,37 @@ +/* { dg-do run { target { aarch64_sve_hw } } } */ +/* { dg-options "-O3 -fno-inline -march=armv8-a+sve" } */ + +#include "sve_vec_bool_cmp_1.c" + +#define N 103 + +#define TEST_VEC_BOOL(NAME, OP, VARTYPE, INDUCTYPE) \ +{ \ + INDUCTYPE i; \ + VARTYPE src[N]; \ + VARTYPE dst[N]; \ + for (i = 0; i < N; i++) \ + { \ + src[i] = i; \ + dst[i] = i * 2; \ + asm volatile ("" ::: "memory"); \ + } \ + vec_bool_##NAME##_##VARTYPE##_##INDUCTYPE (dst, src, 13, \ + 97, 0xFF); \ + for (i = 0; i < 13; i++) \ + if (dst[i] != (VARTYPE) (0 OP 1 ? i : i * 2)) \ + __builtin_abort (); \ + for (i = 13; i < 97; i++) \ + if (dst[i] != (VARTYPE) (1 OP (i != 0x3D) ? i : i * 2)) \ + __builtin_abort (); \ + for (i = 97; i < N; i++) \ + if (dst[i] != (i * 2)) \ + __builtin_abort (); \ +} + +int __attribute__ ((optimize (1))) +main () +{ + TEST_ALL (TEST_VEC_BOOL) + return 0; +}