From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1130) id 2BB593858C50; Wed, 8 Feb 2023 13:40:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2BB593858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675863640; bh=l8lD1T+VY11ElSfQM7Yej/EU+odzFpyXn1d7N2j8XOE=; h=From:To:Subject:Date:From; b=XfOeS8KTDUs3nSgXyF7xsJ/idCP58gMkszYn2oT55n06NK55gbE7LFVgJsCgi0ch3 xFJ9gsgMsnqqbzxqSIlGIczcGc4IHhHSSAZ+BVurby1juQyhFc2RH+KEKgSG+q/HnO 9iQ4hrC7uZ0j2u6povJqlJ/8skV3c/RuVrbqEaKA= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Sandiford To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5739] vect: Check gather/scatter offset types [PR108316] X-Act-Checkin: gcc X-Git-Author: Richard Sandiford X-Git-Refname: refs/heads/trunk X-Git-Oldrev: ad2bd0ad0413c2448fee0d4a062dd52ca8a75e8c X-Git-Newrev: 740a3be7df29b280f39a04c441fd4917af4eef5e Message-Id: <20230208134040.2BB593858C50@sourceware.org> Date: Wed, 8 Feb 2023 13:40:40 +0000 (GMT) List-Id: https://gcc.gnu.org/g:740a3be7df29b280f39a04c441fd4917af4eef5e commit r13-5739-g740a3be7df29b280f39a04c441fd4917af4eef5e Author: Richard Sandiford Date: Wed Feb 8 13:40:29 2023 +0000 vect: Check gather/scatter offset types [PR108316] The gather/scatter support can over-widen an offset if the target requires it, but this relies on using a pattern sequence to add the widening conversion. That failed in the testcase because an earlier pattern (bool) took priority. I think we should allow patterns to be applied to other patterns, but that's quite an invasive change and isn't suitable for stage 4. This patch instead punts if the offset type doesn't match the expected one. If we switched to using the SLP representation for everything, we would probably handle both patterns by rewriting the graph, which should be much easier. gcc/ PR tree-optimization/108316 * tree-vect-stmts.cc (get_load_store_type): When using internal functions for gather/scatter, make sure that the type of the offset argument is consistent with the offset vector type. gcc/testsuite/ PR tree-optimization/108316 * gcc.dg/vect/pr108316.c: New test. Diff: --- gcc/testsuite/gcc.dg/vect/pr108316.c | 11 +++++++++++ gcc/tree-vect-stmts.cc | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/gcc/testsuite/gcc.dg/vect/pr108316.c b/gcc/testsuite/gcc.dg/vect/pr108316.c new file mode 100644 index 00000000000..540b7f2aed4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr108316.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O3" } */ + +extern _Bool a[]; + +void +foo (short i, int b[][64][1]) +{ + for (; i < 64; i += 4) + a[i] = b[0][i] != 0; +} diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index eb4ca1f184e..c86249adcc3 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -2474,6 +2474,23 @@ get_load_store_type (vec_info *vinfo, stmt_vec_info stmt_info, *memory_access_type = VMAT_GATHER_SCATTER; if (!vect_check_gather_scatter (stmt_info, loop_vinfo, gs_info)) gcc_unreachable (); + /* When using internal functions, we rely on pattern recognition + to convert the type of the offset to the type that the target + requires, with the result being a call to an internal function. + If that failed for some reason (e.g. because another pattern + took priority), just handle cases in which the offset already + has the right type. */ + else if (gs_info->ifn != IFN_LAST + && !is_gimple_call (stmt_info->stmt) + && !tree_nop_conversion_p (TREE_TYPE (gs_info->offset), + TREE_TYPE (gs_info->offset_vectype))) + { + if (dump_enabled_p ()) + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + "%s offset requires a conversion\n", + vls_type == VLS_LOAD ? "gather" : "scatter"); + return false; + } else if (!vect_is_simple_use (gs_info->offset, vinfo, &gs_info->offset_dt, &gs_info->offset_vectype))