diff --git a/gcc/match.pd b/gcc/match.pd index 97db0eb5f25..39c9c81966a 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2181,6 +2181,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && (TYPE_UNSIGNED (type) || TYPE_PRECISION (type) > 1)))) +/* (a&1) is always [0,1] too. This is useful again when + the range is not known. */ +(match zero_one_valued_p + (bit_and:c@0 @1 zero_one_valued_p)) + +/* A conversion from an zero_one_valued_p is still a [0,1]. + This is useful when the range of a variable is not known */ +(match zero_one_valued_p + (convert@0 zero_one_valued_p)) + /* Transform { 0 or 1 } * { 0 or 1 } into { 0 or 1 } & { 0 or 1 }. */ (simplify (mult zero_one_valued_p@0 zero_one_valued_p@1) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bool-13.c b/gcc/testsuite/gcc.dg/tree-ssa/bool-13.c index 438f15a484a..de8c99a7727 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/bool-13.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/bool-13.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O1 -fdump-tree-optimized -fdump-tree-original -fdump-tree-phiopt1 -fdump-tree-forwprop2" } */ +/* { dg-options "-O1 -fdump-tree-optimized -fdump-tree-original -fdump-tree-forwprop1 -fdump-tree-forwprop2" } */ #define bool _Bool int maxbool(bool ab, bool bb) { @@ -22,15 +22,10 @@ int minbool(bool ab, bool bb) /* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "original" } } */ /* { dg-final { scan-tree-dump-times "if " 0 "original" } } */ -/* PHI-OPT1 should have kept it as min/max. */ -/* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "phiopt1" } } */ -/* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "phiopt1" } } */ -/* { dg-final { scan-tree-dump-times "if " 0 "phiopt1" } } */ - -/* Forwprop2 (after ccp) will convert it into &\| */ -/* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "forwprop2" } } */ -/* { dg-final { scan-tree-dump-times "MIN_EXPR" 0 "forwprop2" } } */ -/* { dg-final { scan-tree-dump-times "if " 0 "forwprop2" } } */ +/* Forwprop1 will convert it into &\| as we can detect that the arguments are one_zero. */ +/* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "MIN_EXPR" 0 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "if " 0 "forwprop1" } } */ /* By optimize there should be no min/max nor if */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "optimized" } } */