From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by sourceware.org (Postfix) with ESMTPS id E06A7384AB7E for ; Fri, 19 Apr 2024 13:33:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E06A7384AB7E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E06A7384AB7E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::22e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713533595; cv=none; b=KBeBaGAo/FnlXEVKs0JWXZ7ruJEUSXiV/XQV3AsDN8X3HhP1uU1NAJyMG/ELBQCb1NzxI/OY2xL3E8DtJNqz1TJWJ/H1vcrIaAeWb29UQp9Uo8pBKq1drBRQOmIrC7D/8EhPeexI/+cSvqoK28T1BZGLXkZCEmiiXm2jhAMnhdU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713533595; c=relaxed/simple; bh=6wEn9NmDogZHUN8vVIBxqfeasb8B0PFYmfQqH2nzG2g=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=F4k7tGjbsbm8KO4ZnATp9emdZdiISgwV/OUCVHZ30kcn0v2iGAEi/h8VGQLm/JiGze/WCf0rAXbWYb8WmJrDioqbPvYmzuCtIBJPEl9WtUH0FVYebuo5wk8Fd1/d2IcCloAjGDBbctkXG5Quc1GE4s7s1gAGsQrqC47a7TfKx3A= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2d8b2389e73so24230071fa.3 for ; Fri, 19 Apr 2024 06:33:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713533583; x=1714138383; darn=gcc.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ihK/CqEOgXoy0zaDk97jrTI6m4xNNJEe8hhy75my5V0=; b=bAzaAXMMGpM3t12mbaOkNz7CKk7qaiXav99SvQeq+PSOvhx4uZIBaGdM1t8GgHqhhs XO2X9KZx2EFyfqfwGhhGqZY8ey18Tixq57brBEnhiadRbY+0lnDn7ULwb27ccdBae+Cb 6Z0IWVFwfDfKUPxgicIOk+He7o7mEGEshvfkaivCqZoSck9wr2sJEH7dNHVGB715FQgH nx2wwTbuWvQxb/ClRWZfXb+Srw5ChUgwxBoLfiTYQsZjs41syUsWuaiOGwv0Y2rDfoEm RicXYDLjGtNsu6MpZpr9eoMlLm7TfiEUs8qWcfxh/RPgqhJ8O4XCP5KT2B8d6WtPNKfK uf9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713533583; x=1714138383; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ihK/CqEOgXoy0zaDk97jrTI6m4xNNJEe8hhy75my5V0=; b=iI5vfMs0cDHBnWYrDQy6tJVmYvPOT9gYGRZzG6FjlPG6SZIjdAQ/0dJcLGh0e7pgdn cqCJb5Gsf1azQ/GN00ogQdVsJ33dOQaGtVnIxkj63G9ewcIseIA+8tjdey1URnUG8/2V 9gbxJuoU/JDK/Gnz/GD7OEqvq1m+u3K+Ivp+4bhRoqXqMfsJadAR+dWaxeW9BTnS1H60 QXVLm2Y3Hu8QsJd7A7FZeS2t5EUlQ7LFmP4q5qJsMIoIJyLHAft5dAm1xLp8L7nmGVUW GWm3x6m40ofkTW7XMSOZacZZTSCAAMJT/bi+6sVS7qNCGQAOkv3qvsLLgzfA397/6pCh 3uQA== X-Gm-Message-State: AOJu0YxWFU4G+MI/IZ55pvOtGlinGyO/6YmV/BokR/bWbJg+35h/kVaU D7aZvW3HoHLYWt+dS+NH47JHbv+JAkl0aKTkOGiWnhHv67MTmvfnGaYGACTcNkPXeinH3J92Lg8 rCOGYQrirl/F+3rO/71l7zjnZ1d0= X-Google-Smtp-Source: AGHT+IGnkB+gpyqRuxarwJsokrFyti0uNZc9GNX396XuKzQb0Mi8k7gv2vAJLDPBLO956isVF7qKCrxpk7keENU96GA= X-Received: by 2002:ac2:494b:0:b0:518:e5e9:c5b4 with SMTP id o11-20020ac2494b000000b00518e5e9c5b4mr1239758lfi.55.1713533582887; Fri, 19 Apr 2024 06:33:02 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Richard Biener Date: Fri, 19 Apr 2024 15:32:51 +0200 Message-ID: Subject: Re: [PATCH]middle-end: refactory vect_recog_absolute_difference to simplify flow [PR114769] To: Tamar Christina Cc: gcc-patches@gcc.gnu.org, nd@arm.com, rguenther@suse.de, jlaw@ventanamicro.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,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 List-Id: On Fri, Apr 19, 2024 at 3:29=E2=80=AFPM Tamar Christina wrote: > > Hi All, > > As the reporter in PR114769 points out the control flow for the abd detec= tion > is hard to follow. This is because vect_recog_absolute_difference has tw= o > different ways it can return true. > > 1. It can return true when the widening operation is matched, in which ca= se > unprom is set, half_type is not NULL and diff_stmt is not set. > > 2. It can return true when the widening operation is not matched, but the= stmt > being checked is a minus. In this case unprom is not set, half_type i= s set > to NULL and diff_stmt is set. This because to get to diff_stmt you ha= ve to > dig through the abs statement and any possible promotions. > > This however leads to complicated uses of the function at the call sites = as the > exact semantic needs to be known to use it safely. > > vect_recog_absolute_difference has two callers: > > 1. vect_recog_sad_pattern where if you return true with unprom not set, t= hen > *half_type will be NULL. The call to vect_supportable_direct_optab_p = will > always reject it since there's no vector mode for NULL. Note that if = looking > at the dump files, the convention in the dump files have always been t= hat we > first indicate that a pattern could possibly be recognize and then che= ck that > it's supported. > > This change somewhat incorrectly makes the diagnostic message get prin= ted for > "invalid" patterns. > > 2. vect_recog_abd_pattern, where if half_type is NULL, it then uses diff_= stmt to > set them. > > So while the note in the dump file is misleading, the code is safe. > > This refactors the code, it now only has 1 success condition, and diff_st= mt is > always set to the minus statement in the abs if there is one. > > The function now only returns success if the widening minus is found, in = which > case unprom and half_type set. > > This then leaves it up to the caller to decide if they want to do anythin= g with > diff_stmt. > > Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. > > Ok for master? OK. Thanks, Richard. > Thanks, > Tamar > > gcc/ChangeLog: > > PR tree-optimization/114769 > * tree-vect-patterns.cc: > (vect_recog_absolute_difference): Have only one success condition= . > (vect_recog_abd_pattern): Handle further checks if > vect_recog_absolute_difference fails. > > --- > diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc > index 4f491c6b8336f8710c3519dec1fa7e0f49387d2b..87c2acff386d91d22a3b2d6e6= 443d1f2f2326ea6 100644 > --- a/gcc/tree-vect-patterns.cc > +++ b/gcc/tree-vect-patterns.cc > @@ -797,8 +797,7 @@ vect_split_statement (vec_info *vinfo, stmt_vec_info = stmt2_info, tree new_rhs, > HALF_TYPE and UNPROM will be set should the statement be found to > be a widened operation. > DIFF_STMT will be set to the MINUS_EXPR > - statement that precedes the ABS_STMT unless vect_widened_op_tree > - succeeds. > + statement that precedes the ABS_STMT if it is a MINUS_EXPR.. > */ > static bool > vect_recog_absolute_difference (vec_info *vinfo, gassign *abs_stmt, > @@ -843,6 +842,12 @@ vect_recog_absolute_difference (vec_info *vinfo, gas= sign *abs_stmt, > if (!diff_stmt_vinfo) > return false; > > + gassign *diff =3D dyn_cast (STMT_VINFO_STMT (diff_stmt_vin= fo)); > + if (diff_stmt && diff > + && gimple_assign_rhs_code (diff) =3D=3D MINUS_EXPR > + && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (abs_oprnd))) > + *diff_stmt =3D diff; > + > /* FORNOW. Can continue analyzing the def-use chain when this stmt in= a phi > inside the loop (in case we are analyzing an outer-loop). */ > if (vect_widened_op_tree (vinfo, diff_stmt_vinfo, > @@ -850,17 +855,6 @@ vect_recog_absolute_difference (vec_info *vinfo, gas= sign *abs_stmt, > false, 2, unprom, half_type)) > return true; > > - /* Failed to find a widen operation so we check for a regular MINUS_EX= PR. */ > - gassign *diff =3D dyn_cast (STMT_VINFO_STMT (diff_stmt_vin= fo)); > - if (diff_stmt && diff > - && gimple_assign_rhs_code (diff) =3D=3D MINUS_EXPR > - && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (abs_oprnd))) > - { > - *diff_stmt =3D diff; > - *half_type =3D NULL_TREE; > - return true; > - } > - > return false; > } > > @@ -1499,27 +1493,22 @@ vect_recog_abd_pattern (vec_info *vinfo, > tree out_type =3D TREE_TYPE (gimple_assign_lhs (last_stmt)); > > vect_unpromoted_value unprom[2]; > - gassign *diff_stmt; > - tree half_type; > - if (!vect_recog_absolute_difference (vinfo, last_stmt, &half_type, > + gassign *diff_stmt =3D NULL; > + tree abd_in_type; > + if (!vect_recog_absolute_difference (vinfo, last_stmt, &abd_in_type, > unprom, &diff_stmt)) > - return NULL; > - > - tree abd_in_type, abd_out_type; > - > - if (half_type) > - { > - abd_in_type =3D half_type; > - abd_out_type =3D abd_in_type; > - } > - else > { > + /* We cannot try further without having a non-widening MINUS. */ > + if (!diff_stmt) > + return NULL; > + > unprom[0].op =3D gimple_assign_rhs1 (diff_stmt); > unprom[1].op =3D gimple_assign_rhs2 (diff_stmt); > abd_in_type =3D signed_type_for (out_type); > - abd_out_type =3D abd_in_type; > } > > + tree abd_out_type =3D abd_in_type; > + > tree vectype_in =3D get_vectype_for_scalar_type (vinfo, abd_in_type); > if (!vectype_in) > return NULL; > > > > > --