]> gcc.gnu.org Git - gcc.git/commitdiff
Match: zero_one_valued_p should match 0 constants too
authorAndrew Pinski <apinski@marvell.com>
Tue, 6 Jun 2023 15:21:46 +0000 (08:21 -0700)
committerAndrew Pinski <apinski@marvell.com>
Wed, 7 Jun 2023 02:43:16 +0000 (19:43 -0700)
While working on `bool0 ? bool1 : bool2` I noticed that
zero_one_valued_p does not match on the constant zero
as in that case tree_nonzero_bits will return 0 and
that is different from 1.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

gcc/ChangeLog:

* match.pd (zero_one_valued_p): Match 0 integer constant
too.

gcc/match.pd

index 16482b741ea8036bb97540c591e4e249e9e18f6f..7bb7413ff652322351643fcc7aab5578cbf34a5a 100644 (file)
@@ -1983,11 +1983,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (bit_not (bit_not @0))
   @0)
 
+/* zero_one_valued_p will match when a value is known to be either
+   0 or 1 including the constant 0. */
 (match zero_one_valued_p
  @0
  (if (INTEGRAL_TYPE_P (type) && tree_nonzero_bits (@0) == 1)))
 (match zero_one_valued_p
  truth_valued_p@0)
+(match zero_one_valued_p
+ integer_zerop@0
+ (if (INTEGRAL_TYPE_P (type))))
 
 /* Transform { 0 or 1 } * { 0 or 1 } into { 0 or 1 } & { 0 or 1 }.  */
 (simplify
This page took 0.076106 seconds and 5 git commands to generate.