From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32278 invoked by alias); 26 Oct 2016 13:51:37 -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 32069 invoked by uid 89); 26 Oct 2016 13:51:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 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=Bin, restrict, operand_equal_p, xs X-HELO: mail-vk0-f66.google.com Received: from mail-vk0-f66.google.com (HELO mail-vk0-f66.google.com) (209.85.213.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 26 Oct 2016 13:51:24 +0000 Received: by mail-vk0-f66.google.com with SMTP id c203so207374vke.4 for ; Wed, 26 Oct 2016 06:51:24 -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; bh=939Sw6y1Gfi9BC0x7DBg/Gu8xPv6VEt9aSCLrWO6vME=; b=cKSyZXq0bqH/Xgc4BeaK6l0eEFGaqVYGWJMQipyvQLXFwbXot7dWUcrz8sDnLkgfzb 13kAzdZsONvtMxAe4kVt25RLQgNEYdLkKXmFa5C5c+tc2vhjYjqwPIlhjcebSgH6jrC7 KHfewB7/8KCm96Twb5O3r9A5W7F1NG111KBzVHhzm2kfsjE37SQbXKJ4q3kLrHrRlhc5 JqwXh88ns8C1axlaYAPkpkPQCIQJcMrDKzhuPd91O2iUXygPtr7V2GLkdkYdnmfVIfSj hnow+qD4hG9li6jfaY33HBF2OIa8Mfdt7BshOoAuZRB8DjhTYTiNZAQqCkpn7ULxbL5x GEjg== X-Gm-Message-State: ABUngve7V4r9yhNryUiuXBiJJ881jFcC4sM77Y0ojLDW2ZssNR+pzTtYTEiauyXg1jpaw+53f5s1v3+X8jBuNQ== X-Received: by 10.31.182.19 with SMTP id g19mr1147908vkf.46.1477489851042; Wed, 26 Oct 2016 06:50:51 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.116.13 with HTTP; Wed, 26 Oct 2016 06:50:49 -0700 (PDT) In-Reply-To: References: From: "Bin.Cheng" Date: Wed, 26 Oct 2016 13:51:00 -0000 Message-ID: Subject: Re: [PATCH GCC][1/4]Simplify (convert1 (minmax ((convert2 (x) c)))) into minmax (x c) To: Richard Biener Cc: "gcc-patches@gcc.gnu.org" Content-Type: multipart/mixed; boundary=001a1143f77ebb29ac053fc4e925 X-IsSubscribed: yes X-SW-Source: 2016-10/txt/msg02120.txt.bz2 --001a1143f77ebb29ac053fc4e925 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-length: 2723 On Tue, Oct 25, 2016 at 12:48 PM, Richard Biener wrote: > 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 generat= e simplified MIN/MAX_EXPR mostly from COND_EXPR. This is the first one opt= imizing (convert1 (minmax ((convert2 (x) c)))) to minmax (x c), if convert2= promotes x and convert1 demotes back to x's type. With this patch, genera= ted 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), sg= n); > + widest_int type_max =3D widest_int::from (wi::max_value (type), sg= n); > + } > + (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 t= ype_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 similar= ly > 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 for reviewing, updated patch attached. Is it OK? Thanks, bin --001a1143f77ebb29ac053fc4e925 Content-Type: text/plain; charset=US-ASCII; name="01-simplify-convminmaxconv-20161023.txt" Content-Disposition: attachment; filename="01-simplify-convminmaxconv-20161023.txt" Content-Transfer-Encoding: base64 X-Attachment-Id: f_iuqz8uya0 Content-length: 2640 ZGlmZiAtLWdpdCBhL2djYy9tYXRjaC5wZCBiL2djYy9tYXRjaC5wZAppbmRl eCA3NjdkMjNhLi4wODY3MDlmIDEwMDY0NAotLS0gYS9nY2MvbWF0Y2gucGQK KysrIGIvZ2NjL21hdGNoLnBkCkBAIC0xMzM3LDYgKzEzMzcsMTYgQEAgREVG SU5FX0lOVF9BTkRfRkxPQVR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b aV07CisgICAgICBhW2ldID0gKHggPj0gMjU1ID8gMjU1IDogeCk7CisgICAg fQorICByZXR1cm4geDsKK30KKworLyogeyBkZy1maW5hbCB7IHNjYW4tdHJl ZS1kdW1wLW5vdCAiID0gTUlOX0VYUFIgPHhfXFswLTlcXSoiICJvcHRpbWl6 ZWQiIH0gfSAqLwo= --001a1143f77ebb29ac053fc4e925--