From ea8a6038b0b86ccc037d80a9b600e51b1558ad14 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Thu, 6 Jun 2019 09:55:51 +0200 Subject: [PATCH] Simplify mult where both arguments are 0 or 1 (PR tree-optimization/87954). 2019-06-06 Martin Liska PR tree-optimization/87954 * match.pd: Simplify mult where both arguments are 0 or 1. 2019-06-06 Martin Liska PR tree-optimization/87954 * gcc.dg/pr87954.c: New test. From-SVN: r271991 --- gcc/ChangeLog | 5 +++++ gcc/match.pd | 8 ++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr87954.c | 21 +++++++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr87954.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 84c01ce3836..e6dd35a8eaa 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2019-06-06 Martin Liska + + PR tree-optimization/87954 + * match.pd: Simplify mult where both arguments are 0 or 1. + 2019-06-06 Richard Biener * vr-values.c (vr_values::extract_range_from_ssa_name): Do not diff --git a/gcc/match.pd b/gcc/match.pd index 02e0471dd4e..88dae4231d8 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) + && get_nonzero_bits (@1) == 1 + && get_nonzero_bits (@2) == 1) + (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/ChangeLog b/gcc/testsuite/ChangeLog index 8213e33ce25..4bc2c290667 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-06-06 Martin Liska + + PR tree-optimization/87954 + * gcc.dg/pr87954.c: New test. + 2019-06-06 Richard Biener * gcc.dg/tree-ssa/alias-37.c: New testcase. 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" } } */ -- 2.30.2