From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by sourceware.org (Postfix) with ESMTPS id 07B2C385736A for ; Wed, 27 Jul 2022 08:42:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 07B2C385736A Received: by mail-ed1-x535.google.com with SMTP id o13so5554464edc.0 for ; Wed, 27 Jul 2022 01:42:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=HVJrVwPQMI9OEpyGFpq5EZL/iqkTIfE7ZfhIOGmi/8s=; b=gADkAgZG0tNorjhhC8873lVVsP5RpejRsDDQyYAxPefNnoybYRKEPkBU8TAIiXeOgZ vguqU8AXlDMX9fgLsjus6amkk1SFEeGyDEsxWzGfTUahhsonffGKT1je/opOw4kE+5Wx NUvZkTLila3hmpFINdBcizkvsI1vhc/6LdnmZ9HtCKuJ9qXyyX4Tp3FdIwuRYc7jhvyt N4LdHw4Q6yap1vfRICK1gDFdgaTvcsNOdo7q2H5oHao4Q9B5wQaWIa/7mq5Uj1SrJulx mTS+iYQ7CYFesOkk73PSF6/Znizj7dsWev9AUrF8RXz5KTnN9GjnqANL7EE2IH+w8In5 KbAQ== X-Gm-Message-State: AJIora/3xagmVbE9xMvmAsQzKMwRvFPvEJEPKPJr5Nk4lRTITgXiqih8 2Ncfmo44ZrWvlxCFEP85/62rVx52ppjc1PlpiVf8zUe2Iq4= X-Google-Smtp-Source: AGRyM1sr7TPxy69eULocmniPJR8rwFGLuzKlgdOllvFfsY7Z1nCOmgrQ6F69Wo1EZdMD1gPjYJqnl2rZa7bfk0Z/b+Y= X-Received: by 2002:a05:6402:268f:b0:43b:e506:a761 with SMTP id w15-20020a056402268f00b0043be506a761mr18355528edd.250.1658911373689; Wed, 27 Jul 2022 01:42:53 -0700 (PDT) MIME-Version: 1.0 References: <20220725193425.511903-1-sfeifer@redhat.com> In-Reply-To: From: Richard Biener Date: Wed, 27 Jul 2022 10:42:41 +0200 Message-ID: Subject: Re: [PATCH] match.pd: Add new division pattern [PR104992] To: Sam Feifer Cc: Andrew Pinski , GCC Patches Content-Type: text/plain; charset="UTF-8" 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 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: , X-List-Received-Date: Wed, 27 Jul 2022 08:42:57 -0000 On Tue, Jul 26, 2022 at 4:32 PM Sam Feifer via Gcc-patches wrote: > > > > > int f(_Complex int x, _Complex int y) > > { > > return x == x / y * y; > > } > > > > After some research about mod with complex types, I found that the binary > mod operation does not work with complex types. If so, the complex test > case should not be simplified. Is this correct? > > I should also note that the above function, f, causes a segmentation fault. > I can only get a function with complex types to compile by breaking up the > operations like I would in a forward propagation test case. When I do this, > it does not simplify into mod, which I think is right. _Complex int are strange beasts, I'd simply avoid the transform for them. Can you please move the pattern next to the existing div/mod patterns, like after the related /* Simplify (A / B) * B + (A % B) -> A. */ (for div (trunc_div ceil_div floor_div round_div) mod (trunc_mod ceil_mod floor_mod round_mod) (simplify (plus:c (mult:c (div @0 @1) @1) (mod @0 @1)) @0)) pattern? +/* x / y * y == x -> x % y == 0. */ +(simplify + (eq (mult (trunc_div @0 @1) @1) @0) + (eq (trunc_mod @0 @1) { build_zero_cst TREE_TYPE(@0); })) there are parens missing around the TREE_TYPE (@0), how did you test the patch? You probably want :s on the trunc_div and as Andrew said :c on the eq and the mult. Richard. > Thanks > -Sam > > > > For vector try (which works for both the C and C++ front-end): > > #define vector __attribute__((vector_size(4*sizeof(int)) )) > > vector int f(vector int x, vector int y) > > { > > return x == x / y * y; > > } > > > > That is for the vector case, == still returns a vector type. > > > > Thanks, > > Andrew Pinski > > > > > > > > Thanks > > > -Sam > > > > > >> Thanks, > > >> Andrew Pinski > > >> > > >> > diff --git a/gcc/testsuite/gcc.dg/pr104992-1.c > > b/gcc/testsuite/gcc.dg/pr104992-1.c > > >> > new file mode 100644 > > >> > index 00000000000..a80e5e180ce > > >> > --- /dev/null > > >> > +++ b/gcc/testsuite/gcc.dg/pr104992-1.c > > >> > @@ -0,0 +1,30 @@ > > >> > +/* PR tree-optimization/104992 */ > > >> > +/* { dg-do run } */ > > >> > +/* { dg-options "-O2"} */ > > >> > + > > >> > +#include "pr104992.c" > > >> > + > > >> > +int main () { > > >> > + > > >> > + /* Should be true. */ > > >> > + if (!foo(6, 3) > > >> > + || !bar(12, 2) > > >> > + || !baz(34, 17) > > >> > + || !qux(50, 10) > > >> > + || !fred(16, 8) > > >> > + || !baz(-9, 3) > > >> > + || !baz(9, -3) > > >> > + || !baz(-9, -3) > > >> > + ) { > > >> > + __builtin_abort(); > > >> > + } > > >> > + > > >> > + /* Should be false. */ > > >> > + if (foo(5, 30) > > >> > + || bar(72, 27) > > >> > + || baz(42, 15)) { > > >> > + __builtin_abort(); > > >> > + } > > >> > + > > >> > + return 0; > > >> > +} > > >> > diff --git a/gcc/testsuite/gcc.dg/pr104992.c > > b/gcc/testsuite/gcc.dg/pr104992.c > > >> > new file mode 100644 > > >> > index 00000000000..b4b0ca53118 > > >> > --- /dev/null > > >> > +++ b/gcc/testsuite/gcc.dg/pr104992.c > > >> > @@ -0,0 +1,35 @@ > > >> > +/* PR tree-optimization/104992 */ > > >> > +/* { dg-do compile } */ > > >> > +/* { dg-options "-O2 -fdump-tree-optimized" } */ > > >> > + > > >> > +/* Form from PR. */ > > >> > +__attribute__((noipa)) unsigned foo(unsigned x, unsigned y) > > >> > +{ > > >> > + return x / y * y == x; > > >> > +} > > >> > + > > >> > +__attribute__((noipa)) unsigned bar(unsigned x, unsigned y) { > > >> > + return x == x / y * y; > > >> > +} > > >> > + > > >> > +/* Signed test case. */ > > >> > +__attribute__((noipa)) unsigned baz (int x, int y) { > > >> > + return x / y * y == x; > > >> > +} > > >> > + > > >> > +/* Changed order. */ > > >> > +__attribute__((noipa)) unsigned qux (unsigned x, unsigned y) { > > >> > + return y * (x / y) == x; > > >> > +} > > >> > + > > >> > +/* Wrong order. */ > > >> > +__attribute__((noipa)) unsigned fred (unsigned x, unsigned y) { > > >> > + return y * x / y == x; > > >> > +} > > >> > + > > >> > +/* Wrong pattern. */ > > >> > +__attribute__((noipa)) unsigned waldo (unsigned x, unsigned y, > > unsigned z) { > > >> > + return x / y * z == x; > > >> > +} > > >> > + > > >> > +/* { dg-final {scan-tree-dump-times " % " 4 "optimized" } } */ > > >> > > > >> > base-commit: 633e9920589ddfaf2d6da1c24ce99b18a2638db4 > > >> > -- > > >> > 2.31.1 > > >> > > > >> > > > >