[Bug rtl-optimization/83377] Missed optimization (x86): Bit operations should be converted to arithmetic

2018-12-12 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83377

Richard Biener  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2018-12-12
 Ever confirmed|0   |1

--- Comment #6 from Richard Biener  ---
CCP does not have conditional information here (given it is based on SSA
propagation and doesn't insert ASSERT_EXPRs).  The bit-tracking infrastructure
would need to be added for example to EVRP where conditional information
can be tracked.  Still even SSA only has nonzero-bits and not the full
lattice the CCP machinery computes.

Note since the transform is to combine the and with AGU doing this on RTL
looks more appropriate (even if similarly difficult).

   0:   40 f6 c7 02 test   $0x2,%dil
   4:   74 07   je d 
   6:   48 83 e7 fd and$0xfffd,%rdi

a 3-insn peephole could do the trick?  Or doesn't that work with control-flow?

I fear we have no RTL pass doing sth like VRP or bit tracking conditionally
(so even nonzero bits wouldn't work here, no?)

[Bug rtl-optimization/83377] Missed optimization (x86): Bit operations should be converted to arithmetic

2018-12-12 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83377

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org

--- Comment #5 from Jakub Jelinek  ---
(In reply to Vinay Kumar from comment #3)
> The below mentioned pattern match in match.pd  generates the assembly code
> similar to subtraction.
> ==
> diff --git a/gcc/match.pd b/gcc/match.pd
> index fbb4d6f..3cde6a6 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -925,6 +925,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>   (bit_and @0 integer_all_onesp)
>(non_lvalue @0))
> 
> +/*Fold (x & ~CST) into (x - CST)*/
> +(simplify(bit_and:c @0 INTEGER_CST@1)
> +(if ((INTEGRAL_TYPE_P (type) || VECTOR_INTEGER_TYPE_P (type)))
> + (minus @0 (negate @1
> +

That is completely invalid transformation.
Have you actually tried it?
The reason you can do what is in #c0 is because the test guarantees you
corresponding bit (has to be a single one) is set and so the subtraction works
like masking off that single bit.

In the RTL passes (e.g. combiner) I don't think we have information on
guaranteed set bits, we have just information on guaranteed zero bits (through
nonzero_bits).
Not sure if GIMPLE ccp can handle this or not, at least in theory it could
because it has a constant and mask for each SSA_NAME.  Dunno if it has
something similar to VRP assert expressions though or derives something from
the edge state.

[Bug rtl-optimization/83377] Missed optimization (x86): Bit operations should be converted to arithmetic

2018-12-12 Thread vinay.m.engg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83377

--- Comment #4 from Vinay Kumar  ---
Hi,

Above mentioned patch does not work for the pattern "if( x & 2 ) y = (x &
~2UL)". 

>> Probably still easier to fix in combine / simplify-rtx.
We are working as per your suggestion.

Regards,
Vinay

[Bug rtl-optimization/83377] Missed optimization (x86): Bit operations should be converted to arithmetic

2018-12-11 Thread vinay.m.engg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83377

--- Comment #3 from Vinay Kumar  ---
The below mentioned pattern match in match.pd  generates the assembly code
similar to subtraction.
==
diff --git a/gcc/match.pd b/gcc/match.pd
index fbb4d6f..3cde6a6 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -925,6 +925,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (bit_and @0 integer_all_onesp)
   (non_lvalue @0))

+/*Fold (x & ~CST) into (x - CST)*/
+(simplify(bit_and:c @0 INTEGER_CST@1)
+(if ((INTEGRAL_TYPE_P (type) || VECTOR_INTEGER_TYPE_P (type)))
+ (minus @0 (negate @1
+
/* x & x -> x,  x | x -> x  */
(for bitop (bit_and bit_ior)
  (simplify
==

 Assembly generated is as follows:
==
test.o: file format elf64-x86-64


Disassembly of section .text:

 :
   0:   48 83 ff fe   cmp$0xfffe,%rdi
   4:   74 04 je a 
   6:   48 8b 7f fd   mov-0x3(%rdi),%rdi
   a:   e9 00 00 00 00jmpq   f 
   f:   90nop

0010 :
  10:   48 83 ff fe   cmp$0xfffe,%rdi
  14:   74 04 je 1a 
  16:   48 8b 7f fe   mov-0x2(%rdi),%rdi
  1a:   e9 00 00 00 00jmpq   1f 
==

[Bug rtl-optimization/83377] Missed optimization (x86): Bit operations should be converted to arithmetic

2018-11-20 Thread umesh.kalappa0 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83377

Umesh Kalappa  changed:

   What|Removed |Added

 CC||umesh.kalappa0 at gmail dot com

--- Comment #2 from Umesh Kalappa  ---
we can this transformation in the match,pd too (at gimple level).

[Bug rtl-optimization/83377] Missed optimization (x86): Bit operations should be converted to arithmetic

2017-12-12 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83377

Richard Biener  changed:

   What|Removed |Added

   Keywords||missed-optimization
 Target||x86_64-*-* i?86-*-*
  Component|tree-optimization   |rtl-optimization

--- Comment #1 from Richard Biener  ---
Probably still easier to fix in combine / simplify-rtx.