Re: [AVR PATCH] Optimize (X>>C)&1 for C in [1,4,8,16,24] in *insv.any_shift..

2023-11-09 Thread Georg-Johann Lay
Am 02.11.23 um 12:50 schrieb Roger Sayle: This patch optimizes a few special cases in avr.md's *insv.any_shift. instruction. This template handles tests for a single bit, where the result has only a (different) single bit set in the result. Usually (currently) this always requires a three-in

[AVR PATCH] Optimize (X>>C)&1 for C in [1, 4, 8, 16, 24] in *insv.any_shift..

2023-11-02 Thread Roger Sayle
This patch optimizes a few special cases in avr.md's *insv.any_shift. instruction. This template handles tests for a single bit, where the result has only a (different) single bit set in the result. Usually (currently) this always requires a three-instruction sequence of a BST, a CLR and a BLD (

Re: [PATCH] Optimize (X<

2022-09-14 Thread Richard Biener via Gcc-patches
On Wed, Sep 14, 2022 at 11:42 PM Marc Glisse via Gcc-patches wrote: > > On Tue, 13 Sep 2022, Roger Sayle wrote: > > > This patch tweaks the match.pd transformation previously added to fold > > (X< > (wrapping) types, to also allow signed integer types provided that they > > don't trap and the over

Re: [PATCH] Optimize (X<

2022-09-14 Thread Marc Glisse via Gcc-patches
On Tue, 13 Sep 2022, Roger Sayle wrote: This patch tweaks the match.pd transformation previously added to fold (X< In https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html , I read: "Bitwise operators act on the representation of the value including both the sign and value bits, w

Re: [PATCH] Optimize (X<

2022-09-14 Thread Richard Biener via Gcc-patches
On Tue, Sep 13, 2022 at 8:37 PM Roger Sayle wrote: > > > This patch tweaks the match.pd transformation previously added to fold > (X< (wrapping) types, to also allow signed integer types provided that they > don't trap and the overflow needn't be preserved for sanitization. > i.e. this should now

[PATCH] Optimize (X<

2022-09-13 Thread Roger Sayle
This patch tweaks the match.pd transformation previously added to fold (X< gcc/ChangeLog * match.pd (op (lshift @0 @1) (lshift @2 @1)): Optimize the expression (X

Re: [PATCH] Optimize x ? bswap(x) : 0 in tree-ssa-phiopt

2021-08-05 Thread Martin Liška
Hello. I noticed the patch caused new Clang warnings: /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang/build/gcc/tree-ssa-phiopt.c:2586:10: warning: comparison of different enumeration types in switch statement ('combined_fn' and 'built_in_function') [-Wenum-compare-switch] /home/marx

Re: [PATCH] Optimize x ? bswap(x) : 0 in tree-ssa-phiopt

2021-08-02 Thread Richard Biener via Gcc-patches
On Sat, Jul 31, 2021 at 9:56 AM Roger Sayle wrote: > > > Many thanks again to Jakub Jelinek for a speedy fix for PR 101642. > Interestingly, that test case "bswap16(x) ? : x" also reveals a > missed optimization opportunity. The resulting "x ? bswap(x) : 0" > can be further simplified to just bsw

[PATCH] Optimize x ? bswap(x) : 0 in tree-ssa-phiopt

2021-07-31 Thread Roger Sayle
Many thanks again to Jakub Jelinek for a speedy fix for PR 101642. Interestingly, that test case "bswap16(x) ? : x" also reveals a missed optimization opportunity. The resulting "x ? bswap(x) : 0" can be further simplified to just bswap(x). Conveniently, tree-ssa-phiopt.c already recognizes/opti

Re: [PATCH] Optimize x < 0 ? ~y : y to (x >> 31) ^ y in match.pd

2021-05-30 Thread Jeff Law via Gcc-patches
On 5/23/2021 10:21 AM, Andrew Pinski via Gcc-patches wrote: On Sun, May 23, 2021 at 6:14 AM Marc Glisse wrote: On Sun, 23 May 2021, apinski--- via Gcc-patches wrote: +(for cmp (ge lt) +/* x < 0 ? ~y : y into (x >> (prec-1)) ^ y. */ +/* x >= 0 ? ~y : y into ~((x >> (prec-1)) ^ y). */ + (sim

Re: [PATCH] Optimize x < 0 ? ~y : y to (x >> 31) ^ y in match.pd

2021-05-23 Thread Andrew Pinski via Gcc-patches
On Sun, May 23, 2021 at 5:49 AM Martin Liška wrote: > > Hello. > > Similarly to: > https://gcc.gnu.org/pipermail/gcc-patches/2021-May/571039.html > > I've just reverted the ChangeLog commit change. I'm planning update > of the documentation. Obviously is for the other patch which I pushed and not

Re: [PATCH] Optimize x < 0 ? ~y : y to (x >> 31) ^ y in match.pd

2021-05-23 Thread Andrew Pinski via Gcc-patches
On Sun, May 23, 2021 at 6:14 AM Marc Glisse wrote: > > On Sun, 23 May 2021, apinski--- via Gcc-patches wrote: > > > +(for cmp (ge lt) > > +/* x < 0 ? ~y : y into (x >> (prec-1)) ^ y. */ > > +/* x >= 0 ? ~y : y into ~((x >> (prec-1)) ^ y). */ > > + (simplify > > + (cond (cmp @0 integer_zerop) (bit

Re: [PATCH] Optimize x < 0 ? ~y : y to (x >> 31) ^ y in match.pd

2021-05-23 Thread Marc Glisse
On Sun, 23 May 2021, apinski--- via Gcc-patches wrote: +(for cmp (ge lt) +/* x < 0 ? ~y : y into (x >> (prec-1)) ^ y. */ +/* x >= 0 ? ~y : y into ~((x >> (prec-1)) ^ y). */ + (simplify + (cond (cmp @0 integer_zerop) (bit_not @1) @1) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) +&& !TYPE_UN

Re: [PATCH] Optimize x < 0 ? ~y : y to (x >> 31) ^ y in match.pd

2021-05-23 Thread Martin Liška
Hello. Similarly to: https://gcc.gnu.org/pipermail/gcc-patches/2021-May/571039.html I've just reverted the ChangeLog commit change. I'm planning update of the documentation. Cheers, Martin

[PATCH] Optimize x < 0 ? ~y : y to (x >> 31) ^ y in match.pd

2021-05-23 Thread apinski--- via Gcc-patches
From: Andrew Pinski This copies the optimization that is done in phiopt for "x < 0 ? ~y : y to (x >> 31) ^ y" into match.pd. The code for phiopt is kept around until phiopt uses match.pd (which I am working towards). Note the original testcase is now optimized early on and I added a new testcase

Re: [PATCH] Optimize x == 0 && y == 0 into (x | y) == 0 in reassoc range opt (PR middle-end/35691)

2017-09-26 Thread Richard Biener
On Tue, 26 Sep 2017, Jakub Jelinek wrote: > Hi! > > Right now we handle x == 0 && y == 0 into (x | y) == 0 > and x == -1 && y == -1 into (x & y) == -1 optimizations just in > match.pd, where it will handle the case where the && (or || if using !=) > is actually & (or |) and they are next to each

[PATCH] Optimize x == 0 && y == 0 into (x | y) == 0 in reassoc range opt (PR middle-end/35691)

2017-09-26 Thread Jakub Jelinek
Hi! Right now we handle x == 0 && y == 0 into (x | y) == 0 and x == -1 && y == -1 into (x & y) == -1 optimizations just in match.pd, where it will handle the case where the && (or || if using !=) is actually & (or |) and they are next to each other. It doesn't handle the case when we have such com

Re: [PATCH] Optimize x == -1 && y == -1 (PR middle-end/35691)

2017-09-22 Thread Richard Biener
On September 22, 2017 6:59:48 PM GMT+02:00, Jakub Jelinek wrote: >Hi! > >While fixing libgcc2.c (__mulvDI3), I've noticed that while we >optimize x == 0 && y == 0 into (x | y) == 0, we don't optimize >analogical x == -1 && y == -1 into (x & y) == -1. > >The following patch does that, bootstrapped

[PATCH] Optimize x == -1 && y == -1 (PR middle-end/35691)

2017-09-22 Thread Jakub Jelinek
Hi! While fixing libgcc2.c (__mulvDI3), I've noticed that while we optimize x == 0 && y == 0 into (x | y) == 0, we don't optimize analogical x == -1 && y == -1 into (x & y) == -1. The following patch does that, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-09-22 Jaku

Re: [PATCH] Optimize X << Y with low bits of Y known to be 0 (PR tree-optimization/71563, take 2)

2017-01-04 Thread Richard Biener
On Thu, 29 Dec 2016, Jakub Jelinek wrote: > Hi! > > On Tue, Dec 20, 2016 at 09:45:03PM +0100, Jakub Jelinek wrote: > > > Note that you can write (shift @0 SSA_NAME@1) in the pattern instead of a > > > separate test. > > > > That is what I tried first, but there is some bug in genmatch.c that > >

[PATCH] Optimize X << Y with low bits of Y known to be 0 (PR tree-optimization/71563, take 2)

2016-12-29 Thread Jakub Jelinek
Hi! On Tue, Dec 20, 2016 at 09:45:03PM +0100, Jakub Jelinek wrote: > > Note that you can write (shift @0 SSA_NAME@1) in the pattern instead of a > > separate test. > > That is what I tried first, but there is some bug in genmatch.c that > prevents it. The: > (for vec (VECTOR_CST CONSTRUCTOR) >

Re: [PATCH] Optimize X << Y with low bits of Y known to be 0 (PR tree-optimization/71563)

2016-12-20 Thread Jakub Jelinek
On Tue, Dec 20, 2016 at 09:30:17PM +0100, Marc Glisse wrote: > would it make sense to extend it to rotates later? I wasn't 100% sure if rotates also require 0..prec-1 rotate counts, or if they accept arbitrary ones. > Note that you can write (shift @0 SSA_NAME@1) in the pattern instead of a > sep

Re: [PATCH] Optimize X << Y with low bits of Y known to be 0 (PR tree-optimization/71563)

2016-12-20 Thread Marc Glisse
On Tue, 20 Dec 2016, Jakub Jelinek wrote: If the shift count has enough known zero low bits (non-zero bits only above the ceil_log2 (precision)), then the only valid shift count that is not out of bounds is 0, so we can as well fold it into the first argument of the shift. This resolves a regre

[PATCH] Optimize X << Y with low bits of Y known to be 0 (PR tree-optimization/71563)

2016-12-20 Thread Jakub Jelinek
Hi! If the shift count has enough known zero low bits (non-zero bits only above the ceil_log2 (precision)), then the only valid shift count that is not out of bounds is 0, so we can as well fold it into the first argument of the shift. This resolves a regression introduced by partly optimizing it

Re: [PATCH] Optimize (x % 5) % 5 in VRP (PR tree-optimization/64454)

2015-01-12 Thread Jeff Law
On 01/12/15 13:28, Jakub Jelinek wrote: Hi! This patch optimizes away TRUNC_MOD_EXPR by constant second argument (if not 0 and not type's minimum) if the range of the first argument is already known to be [-op1 + 1, op1 - 1] or its subset. Bootstrapped/regtested on x86_64-linux and i686-linux,

[PATCH] Optimize (x % 5) % 5 in VRP (PR tree-optimization/64454)

2015-01-12 Thread Jakub Jelinek
Hi! This patch optimizes away TRUNC_MOD_EXPR by constant second argument (if not 0 and not type's minimum) if the range of the first argument is already known to be [-op1 + 1, op1 - 1] or its subset. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2015-01-12 Jakub Jelinek

Re: [PATCH] Optimize (x * 8) | 5 and (x << 3) ^ 3 to use lea (PR target/48688)

2011-06-04 Thread Jakub Jelinek
On Sat, Jun 04, 2011 at 08:19:57AM -0700, H.J. Lu wrote: > I don't think this pattern is correct. See: > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49281 Fixed thusly, committed as obvious: 2011-06-04 Jakub Jelinek PR target/49281 * config/i386/i386.md (*lea_general_4): R

Re: [PATCH] Optimize (x * 8) | 5 and (x << 3) ^ 3 to use lea (PR target/48688)

2011-06-04 Thread H.J. Lu
On Wed, Apr 20, 2011 at 9:09 AM, Jakub Jelinek wrote: > Hi! > > This splitter allows us to optimize (x {* {2,4,8},<< {1,2,3}}) {|,^} y > for constant integer y <= {1ULL,3ULL,7ULL} using lea{l,q} (| or ^ in > that case, when the low bits are known to be all 0, is like plus). > > Bootstrapped/regtes

Re: [PATCH] Optimize (x * 8) | 5 and (x << 3) ^ 3 to use lea (PR target/48688)

2011-04-21 Thread Jakub Jelinek
On Wed, Apr 20, 2011 at 10:27:36AM -0700, Richard Henderson wrote: > On 04/20/2011 09:09 AM, Jakub Jelinek wrote: > > Hi! > > > > This splitter allows us to optimize (x {* {2,4,8},<< {1,2,3}}) {|,^} y > > for constant integer y <= {1ULL,3ULL,7ULL} using lea{l,q} (| or ^ in > > that case, when the

Re: [PATCH] Optimize (x * 8) | 5 and (x << 3) ^ 3 to use lea (PR target/48688)

2011-04-20 Thread Richard Henderson
On 04/20/2011 09:09 AM, Jakub Jelinek wrote: > Hi! > > This splitter allows us to optimize (x {* {2,4,8},<< {1,2,3}}) {|,^} y > for constant integer y <= {1ULL,3ULL,7ULL} using lea{l,q} (| or ^ in > that case, when the low bits are known to be all 0, is like plus). > > Bootstrapped/regtested on x

[PATCH] Optimize (x * 8) | 5 and (x << 3) ^ 3 to use lea (PR target/48688)

2011-04-20 Thread Jakub Jelinek
Hi! This splitter allows us to optimize (x {* {2,4,8},<< {1,2,3}}) {|,^} y for constant integer y <= {1ULL,3ULL,7ULL} using lea{l,q} (| or ^ in that case, when the low bits are known to be all 0, is like plus). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2011-04-20 Jaku