From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 51339 invoked by alias); 25 Oct 2016 11:48:35 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 51256 invoked by uid 89); 25 Oct 2016 11:48:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=no version=3.3.2 spammy= X-HELO: mail-wm0-f50.google.com Received: from mail-wm0-f50.google.com (HELO mail-wm0-f50.google.com) (74.125.82.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Oct 2016 11:48:20 +0000 Received: by mail-wm0-f50.google.com with SMTP id c78so19528576wme.0 for ; Tue, 25 Oct 2016 04:48:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=AWuoV1IF2TmEHCPtg3pRlgiIVyNmEH3Hkan3cCMJirE=; b=LaR3yjS6pXbVhm0rVuUJKv6RpOjNL8+u0AZ+Z+i42WxDDWrSNI0BSsep02o/Fa01fK c/D35GipnHx9JoE/cd/NWKcgud+1gP/ksLFuymhw4kmEtI3AIdGgi2/eS8PHSQ/Kv5Pg McQxcEEyXppgjfRFKpucA6VNpGDXmczgBapVvr4+opINb0KiL/4WQ2KteyJkwO05cdmd RiOKXsNF4/4nqVWEJIe/g1Lo79eU8AqAvS/6BwpbiWLI5PtfHJWJF53sYhN2NDNhEw7y eTRaYrtl18+0DFJj3Q4MRKVSiu09MQfKMSR7xIryUn7GfrNJjCE4BQ108mEFIYObrwTp rbHQ== X-Gm-Message-State: ABUngvcvuD+ZCnmh7iWep/Q0NhrTW5bnhqkxXv7asawurmI0z2Lg5jHeXP0hyMhBUbuomOvKTVw1LL5M/3I6Cg== X-Received: by 10.28.145.85 with SMTP id t82mr2961113wmd.40.1477396093864; Tue, 25 Oct 2016 04:48:13 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.155.146 with HTTP; Tue, 25 Oct 2016 04:48:13 -0700 (PDT) In-Reply-To: References: From: Richard Biener Date: Tue, 25 Oct 2016 11:48:00 -0000 Message-ID: Subject: Re: [PATCH GCC][1/4]Simplify (convert1 (minmax ((convert2 (x) c)))) into minmax (x c) To: Bin Cheng Cc: "gcc-patches@gcc.gnu.org" , nd Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2016-10/txt/msg02011.txt.bz2 On Tue, Oct 25, 2016 at 1:21 PM, Bin Cheng wrote: > Hi, > This is a patch set adding various match.pd patterns in order to generate= simplified MIN/MAX_EXPR mostly from COND_EXPR. This is the first one opti= mizing (convert1 (minmax ((convert2 (x) c)))) to minmax (x c), if convert2 = promotes x and convert1 demotes back to x's type. With this patch, generat= ed assembly for test: > .L4: > ldr q0, [x3, x1] > add w2, w2, 1 > cmp w0, w2 > ushll v2.4s, v0.4h, 0 > ushll2 v1.4s, v0.8h, 0 > umin v2.4s, v2.4s, v3.4s > umin v1.4s, v1.4s, v3.4s > xtn v4.4h, v2.4s > xtn2 v4.8h, v1.4s > str q4, [x3, x1] > add x1, x1, 16 > bhi .L4 > > can be improved to: > .L4: > ldr q0, [x3, x1] > add w2, w2, 1 > cmp w0, w2 > umin v1.8h, v0.8h, v2.8h > str q1, [x3, x1] > add x1, x1, 16 > bhi .L4 > > Bootstrap and test on x86_64 and AArch64 for whole patch set. Is it OK? Why restrict to GIMPLE? +/* (convert1 (minmax ((convert2 (x) c)))) -> minmax (x c) if convert2 + promotes x and convert1 demotes back to x's type. */ + +(for minmax (min max) + (simplify + (convert (minmax@0 (convert @1) INTEGER_CST@2)) + (if (types_compatible_p (TREE_TYPE (@1), type)) comment mentions convert1 and convert2, just convert is correct I think. Please use types_match instead of types_compatible_p, this is a wrapper that does the correct thing for both GENERIC and GIMPLE. + (with + { + tree minmax_type =3D TREE_TYPE (@0); + signop sgn =3D TYPE_SIGN (type); + widest_int type_min =3D widest_int::from (wi::min_value (type), sgn); + widest_int type_max =3D widest_int::from (wi::max_value (type), sgn); + } + (if (sgn =3D=3D TYPE_SIGN (minmax_type) + && TYPE_PRECISION (minmax_type) >=3D TYPE_PRECISION (type) + && wi::to_widest (@2) >=3D type_min && wi::to_widest (@2) <=3D typ= e_max) instead of this you can use int_fits_type_p (type, @2) + (minmax @1 { fold_convert (type, @2); })))))) use (minmax @1 (convert @2)) I believe the transform is also a win if @2 is not a constant but similarly promoted as @1. This slightly complicates the patter and thus can be done as followup (if we think it's useful at this point). With the simplification you should get rid of the with{} Thanks, Richard. > Thanks, > bin > > 2016-10-21 Bin Cheng > > * match.pd ((convert1 (minmax ((convert2 (x) c)))) -> minmax (x c= )): > New pattern. > > gcc/testsuite/ChangeLog > 2016-10-21 Bin Cheng > > * gcc.dg/fold-convmaxconv-1.c: New test. > * gcc.dg/fold-convminconv-1.c: New test.