This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch][PR91504] Inlining misses some logical operation folding


2019-08-26  Kamlesh Kumar  <kamleshbhalui@gmail.com>

        * gcc/match.pd: Added simplification
        pattern.
        * gcc.dg/tree-ssa/pr91504.c: New test.
====================

diff --git a/gcc/match.pd b/gcc/match.pd
index 93dcef9..b3734f8 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -831,6 +831,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (bit_xor:c (bit_and:cs @0 (bit_not @1)) (bit_not @0))
  (bit_not (bit_and @0 @1)))

+/* (~a & b) ^ a  -->   (a | b)   */
+(simplify
+ (bit_xor:c (bit_and:cs (bit_not @0) @1) @0)
+ (bit_ior @0 @1))
+
 /* (a | b) & ~(a ^ b)  -->  a & b  */
 (simplify
  (bit_and:c (bit_ior @0 @1) (bit_not (bit_xor:c @0 @1)))
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr91504.c
b/gcc/testsuite/gcc.dg/tree-ssa/pr91504.c
new file mode 100644
index 0000000..a52dea4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr91504.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-optimized-raw" } */
+
+static inline unsigned deposit32(unsigned value, int start, int length,
+                                 unsigned fieldval)
+{
+    unsigned mask = (~0U >> (32 - length)) << start;
+    return (value & ~mask) | ((fieldval << start) & mask);
+}
+
+unsigned foo(unsigned value)
+{
+   return deposit32(value, 10, 1, 1);
+}
+
+/* { dg-final { scan-tree-dump-not "bit_and_expr" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "bit_xor_expr" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "bit_not_expr" "optimized" } } */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]