From patchwork Fri Mar 10 20:16:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Collison X-Patchwork-Id: 66257 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0D683385841A for ; Fri, 10 Mar 2023 20:16:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf34.google.com (mail-qv1-xf34.google.com [IPv6:2607:f8b0:4864:20::f34]) by sourceware.org (Postfix) with ESMTPS id 176F73858D32 for ; Fri, 10 Mar 2023 20:16:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 176F73858D32 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-qv1-xf34.google.com with SMTP id jl13so458686qvb.10 for ; Fri, 10 Mar 2023 12:16:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; t=1678479381; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=LDidJlnuRrpzPdCS2hg7FeuI1nZlJ7LLYDz926PCM+c=; b=C6DZXlZ1i0UWCdCL5EBl3Gzx4jYV528whO43LVVvA9hqE2S0dPEr3sTEnp/32eeSEf MMP1m0CGZnu6bqz2j3Nse8zdS6lXqrUqA2mi+JZYTX08zWm/ZJ4rmct1uKbeCkgcX2q/ cnV81sTu1chXU5aMgnFF3KG4yJCcrobfpqIxGt6o0CzJ4yrGDg9ClJeLdsE/XweAyvlH EIDbVErTlP3OGnsE0m7PZoXl0f9Uld3vaVKPy6GvHi1R1nwbz1SYEYfkBLRAdg08lXJ1 IddP4agjHXhzhemRNSxH/0J82Bff2sTSEpzyNVs2QdFjX9XOtv8j1Dh/qM5HgpXsUabs ywQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678479381; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LDidJlnuRrpzPdCS2hg7FeuI1nZlJ7LLYDz926PCM+c=; b=GlWc/i7vQAZYPMg5zWul8PakVHvtIqmMg980FHcBvNBgeB0+GWTwQCrHgtOnI8u7uT tP5K8dZlUwX+XfAKJ2VE4NqcihxhqHiM4WN+Z3V0fvbMrd7SAA0OyPygWWqmRq/ga1Uk mOu+3z2Vkf6I3rFQ7nUkWfnMhiFyUGylFvRxy0kkTybwxrrVdfLrBFyOGiz+HLCVZq/d pWTqiEgTV1mWmmSocBVRFqEGoSD3hs1OoBphs1lF2Y7kdoKabKB3YDlfG4gE9Bny9fUA 2f3ldDYUcSB24BpECHhwAowclN5eya7Ur/ZRJxflJ3leXos2JlA1IDNUEeMobvfN+aTq je2g== X-Gm-Message-State: AO0yUKVdNvwuSR87w7Og78Hpt+d0B6YpQm9LSCnXZi77MG38PN3WC0Hd vt66Ik++pfEZtKzE5zx71Bsv9itApVwqgAaVeV8= X-Google-Smtp-Source: AK7set+WpYzc6x5GhvgNIVB+w8dCULgY8ZDFulX4j4j8dZv9jlZV2zlNqMOEmciIZmaTF/27Ca/EJw== X-Received: by 2002:ad4:5dcb:0:b0:56e:aeb3:52b7 with SMTP id m11-20020ad45dcb000000b0056eaeb352b7mr468909qvh.4.1678479381114; Fri, 10 Mar 2023 12:16:21 -0800 (PST) Received: from system76-pc.ba.rivosinc.com ([136.57.172.92]) by smtp.gmail.com with ESMTPSA id z11-20020ac8710b000000b003b63b8df24asm456929qto.36.2023.03.10.12.16.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 12:16:20 -0800 (PST) From: Michael Collison To: gcc-patches@gcc.gnu.org Subject: [PATCH] vect: Verify that GET_MODE_NUNITS is power-of-2 Date: Fri, 10 Mar 2023 15:16:20 -0500 Message-Id: <20230310201620.2097011-1-collison@rivosinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_NUMSUBJECT, 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 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: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" While working on autovectorizing for the RISCV port I encountered an issue where can_duplicate_and_interleave_p assumes that GET_MODE_NUNITS is a power of two. The RISC-V target has vector modes (e.g. VNx1DImode) that are not a power of two. Tested on RISCV and x86_64-linux-gnu. Okay? 2023-03-09 Michael Collison * poly-int.h (exact_div_p): New function to verify that argument is a power of 2 poly_int. * tree-vect-slp.cc (can_duplicate_and_interleave_p): Check that GET_MODE_NUNITS is a power of 2. --- gcc/poly-int.h | 17 +++++++++++++++++ gcc/tree-vect-slp.cc | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gcc/poly-int.h b/gcc/poly-int.h index 12571455081..d09632f341f 100644 --- a/gcc/poly-int.h +++ b/gcc/poly-int.h @@ -2219,6 +2219,23 @@ multiple_p (const poly_int_pod &a, const poly_int_pod &b, return constant_multiple_p (a, b, multiple); } +/* Return true, if A is known to be a multiple of B. */ + +template +inline bool +exact_div_p (const poly_int_pod &a, Cb b) +{ + typedef POLY_CONST_COEFF (Ca, Cb) C; + poly_int r; + for (unsigned int i = 0; i < N; i++) + { + if ((a.coeffs[i] % b) != 0) + return false; + + } + return true; +} + /* Return A / B, given that A is known to be a multiple of B. */ template diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index 9a4e000925e..6be2036a13a 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -426,7 +426,8 @@ can_duplicate_and_interleave_p (vec_info *vinfo, unsigned int count, if (vector_type && VECTOR_MODE_P (TYPE_MODE (vector_type)) && known_eq (GET_MODE_SIZE (TYPE_MODE (vector_type)), - GET_MODE_SIZE (base_vector_mode))) + GET_MODE_SIZE (base_vector_mode)) + && exact_div_p (GET_MODE_NUNITS (TYPE_MODE (vector_type)), 2)) { /* Try fusing consecutive sequences of COUNT / NVECTORS elements together into elements of type INT_TYPE and using the result