* [Bug tree-optimization/63568] Missed optimization (a & ~mask) | (b & mask) = a ^ ((a ^ b) & mask)
2014-10-16 23:55 [Bug tree-optimization/63568] New: Missed optimization (a & ~mask) | (b & mask) = a ^ ((a ^ b) & mask) olegendo at gcc dot gnu.org
@ 2014-10-17 8:31 ` rguenth at gcc dot gnu.org
2014-12-16 11:18 ` mpolacek at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-10-17 8:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63568
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2014-10-17
CC| |rguenth at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Looks like three vs. four ops and thus is simpler in general. Easy to
implement
as simplification on match-and-simplify branch.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/63568] Missed optimization (a & ~mask) | (b & mask) = a ^ ((a ^ b) & mask)
2014-10-16 23:55 [Bug tree-optimization/63568] New: Missed optimization (a & ~mask) | (b & mask) = a ^ ((a ^ b) & mask) olegendo at gcc dot gnu.org
2014-10-17 8:31 ` [Bug tree-optimization/63568] " rguenth at gcc dot gnu.org
@ 2014-12-16 11:18 ` mpolacek at gcc dot gnu.org
2014-12-16 13:44 ` [Bug middle-end/63568] " mpolacek at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-12-16 11:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63568
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
CC| |mpolacek at gcc dot gnu.org
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
Target Milestone|--- |5.0
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I'll try to come up with a match-and-simplify simplification.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/63568] Missed optimization (a & ~mask) | (b & mask) = a ^ ((a ^ b) & mask)
2014-10-16 23:55 [Bug tree-optimization/63568] New: Missed optimization (a & ~mask) | (b & mask) = a ^ ((a ^ b) & mask) olegendo at gcc dot gnu.org
2014-10-17 8:31 ` [Bug tree-optimization/63568] " rguenth at gcc dot gnu.org
2014-12-16 11:18 ` mpolacek at gcc dot gnu.org
@ 2014-12-16 13:44 ` mpolacek at gcc dot gnu.org
2014-12-16 13:50 ` jakub at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-12-16 13:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63568
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
FWIW, I used this to check the whether the transformation is correct:
int
main ()
{
for (int i = -1000; i < 1000; ++i)
for (int a = -1000; a < 1000; ++a)
for (int b = -1000; b < 1000; ++b)
{
int x = (a & ~i) | (b & i);
int y = a ^ ((a ^ b) & i);
//__builtin_printf ("%d %d\n", x, y);
if (x != y)
__builtin_abort ();
}
}
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/63568] Missed optimization (a & ~mask) | (b & mask) = a ^ ((a ^ b) & mask)
2014-10-16 23:55 [Bug tree-optimization/63568] New: Missed optimization (a & ~mask) | (b & mask) = a ^ ((a ^ b) & mask) olegendo at gcc dot gnu.org
` (2 preceding siblings ...)
2014-12-16 13:44 ` [Bug middle-end/63568] " mpolacek at gcc dot gnu.org
@ 2014-12-16 13:50 ` jakub at gcc dot gnu.org
2014-12-16 14:17 ` mpolacek at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-12-16 13:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63568
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Not necessarily 3 vs. 4 ops, many targets have andnot instruction and can do it
also in 3 ops.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/63568] Missed optimization (a & ~mask) | (b & mask) = a ^ ((a ^ b) & mask)
2014-10-16 23:55 [Bug tree-optimization/63568] New: Missed optimization (a & ~mask) | (b & mask) = a ^ ((a ^ b) & mask) olegendo at gcc dot gnu.org
` (3 preceding siblings ...)
2014-12-16 13:50 ` jakub at gcc dot gnu.org
@ 2014-12-16 14:17 ` mpolacek at gcc dot gnu.org
2014-12-16 14:21 ` rguenther at suse dot de
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-12-16 14:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63568
--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
True. E.g. on my x86_64 i7 Nehalem I see (using ./cc1 -quiet -O2 qq.c -mbmi)
andn %edi, %edx, %edi
andl %edx, %esi
movl %edi, %eax
orl %esi, %eax
ret
for return (a & ~m) | (b & m); and
xorl %edi, %esi
movl %edi, %eax
andl %esi, %edx
xorl %edx, %eax
ret
for return a ^ ((a ^ b) & m);
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/63568] Missed optimization (a & ~mask) | (b & mask) = a ^ ((a ^ b) & mask)
2014-10-16 23:55 [Bug tree-optimization/63568] New: Missed optimization (a & ~mask) | (b & mask) = a ^ ((a ^ b) & mask) olegendo at gcc dot gnu.org
` (4 preceding siblings ...)
2014-12-16 14:17 ` mpolacek at gcc dot gnu.org
@ 2014-12-16 14:21 ` rguenther at suse dot de
2014-12-16 20:38 ` olegendo at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenther at suse dot de @ 2014-12-16 14:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63568
--- Comment #6 from rguenther at suse dot de <rguenther at suse dot de> ---
On Tue, 16 Dec 2014, mpolacek at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63568
>
> --- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
> True. E.g. on my x86_64 i7 Nehalem I see (using ./cc1 -quiet -O2 qq.c -mbmi)
>
> andn %edi, %edx, %edi
> andl %edx, %esi
> movl %edi, %eax
> orl %esi, %eax
> ret
>
> for return (a & ~m) | (b & m); and
>
> xorl %edi, %esi
> movl %edi, %eax
> andl %esi, %edx
> xorl %edx, %eax
> ret
>
> for return a ^ ((a ^ b) & m);
The former is also better for instruction level parallelism - but
that just asks for a clever enough expander / combiner that can
generate that from the latter.
I think on GIMPLE we want to canoncalize to the variant with less
(gimple) operations. single-use restrictions may apply (with
the lack of a global unified combine / CSE phase)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/63568] Missed optimization (a & ~mask) | (b & mask) = a ^ ((a ^ b) & mask)
2014-10-16 23:55 [Bug tree-optimization/63568] New: Missed optimization (a & ~mask) | (b & mask) = a ^ ((a ^ b) & mask) olegendo at gcc dot gnu.org
` (5 preceding siblings ...)
2014-12-16 14:21 ` rguenther at suse dot de
@ 2014-12-16 20:38 ` olegendo at gcc dot gnu.org
2014-12-17 11:49 ` mpolacek at gcc dot gnu.org
2014-12-17 11:55 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: olegendo at gcc dot gnu.org @ 2014-12-16 20:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63568
--- Comment #7 from Oleg Endo <olegendo at gcc dot gnu.org> ---
If you decide not to do the transform at the tree level, please change this to
a target PR and assign it to me.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/63568] Missed optimization (a & ~mask) | (b & mask) = a ^ ((a ^ b) & mask)
2014-10-16 23:55 [Bug tree-optimization/63568] New: Missed optimization (a & ~mask) | (b & mask) = a ^ ((a ^ b) & mask) olegendo at gcc dot gnu.org
` (6 preceding siblings ...)
2014-12-16 20:38 ` olegendo at gcc dot gnu.org
@ 2014-12-17 11:49 ` mpolacek at gcc dot gnu.org
2014-12-17 11:55 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-12-17 11:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63568
--- Comment #9 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Author: mpolacek
Date: Wed Dec 17 11:48:33 2014
New Revision: 218816
URL: https://gcc.gnu.org/viewcvs?rev=218816&root=gcc&view=rev
Log:
PR middle-end/63568
* match.pd: Add (x & ~m) | (y & m) -> ((x ^ y) & m) ^ x pattern.
* gcc.dg/pr63568.c: New test.
Added:
trunk/gcc/testsuite/gcc.dg/pr63568.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/match.pd
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/63568] Missed optimization (a & ~mask) | (b & mask) = a ^ ((a ^ b) & mask)
2014-10-16 23:55 [Bug tree-optimization/63568] New: Missed optimization (a & ~mask) | (b & mask) = a ^ ((a ^ b) & mask) olegendo at gcc dot gnu.org
` (7 preceding siblings ...)
2014-12-17 11:49 ` mpolacek at gcc dot gnu.org
@ 2014-12-17 11:55 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-12-17 11:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63568
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #10 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 10+ messages in thread