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

vinay.m.engg at gmail dot com gcc-bugzilla@gcc.gnu.org
Tue Dec 11 10:01:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83377

--- Comment #3 from Vinay Kumar <vinay.m.engg at gmail dot com> ---
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:

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

0000000000000010 <c>:
  10:   48 83 ff fe               cmp    $0xfffffffffffffffe,%rdi
  14:   74 04                     je     1a <c+0xa>
  16:   48 8b 7f fe               mov    -0x2(%rdi),%rdi
  1a:   e9 00 00 00 00            jmpq   1f <c+0xf>
==========================================


More information about the Gcc-bugs mailing list