Hi. I'm suggesting one multiplication simplification pattern.
Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin gcc/ChangeLog: 2019-06-05 Martin Liska <mli...@suse.cz> PR tree-optimization/87954 * match.pd: Simplify mult where both arguments are 0 or 1. gcc/testsuite/ChangeLog: 2019-06-05 Martin Liska <mli...@suse.cz> PR tree-optimization/87954 * gcc.dg/pr87954.c: New test. --- gcc/match.pd | 8 ++++++++ gcc/testsuite/gcc.dg/pr87954.c | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr87954.c
diff --git a/gcc/match.pd b/gcc/match.pd index 02e0471dd4e..7c6bf621917 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -217,6 +217,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) || !COMPLEX_FLOAT_TYPE_P (type))) (negate @0))) +/* Transform { 0 or 1 } * { 0 or 1 } into { 0 or 1 } & { 0 or 1 } */ +(simplify + (mult SSA_NAME@1 SSA_NAME@2) + (if (INTEGRAL_TYPE_P (type) + && wi::eq_p (get_nonzero_bits (@1), wi::one (TYPE_PRECISION (type))) + && wi::eq_p (get_nonzero_bits (@2), wi::one (TYPE_PRECISION (type)))) + (bit_and @1 @2))) + /* Transform x * { 0 or 1, 0 or 1, ... } into x & { 0 or -1, 0 or -1, ...}, unless the target has native support for the former but not the latter. */ (simplify diff --git a/gcc/testsuite/gcc.dg/pr87954.c b/gcc/testsuite/gcc.dg/pr87954.c new file mode 100644 index 00000000000..620657cb1f5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr87954.c @@ -0,0 +1,21 @@ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +#define __GFP_DMA 1u +#define __GFP_RECLAIM 0x10u + +#define KMALLOC_DMA 2 +#define KMALLOC_RECLAIM 1 + +unsigned int +imul(unsigned int flags) +{ + int is_dma, type_dma, is_rec; + + is_dma = !!(flags & __GFP_DMA); + type_dma = is_dma * KMALLOC_DMA; + is_rec = !!(flags & __GFP_RECLAIM); + + return type_dma + (is_rec * !is_dma) * KMALLOC_RECLAIM; +} + +/* { dg-final { scan-tree-dump-times { \* } 1 "optimized" } } */