This ports the clrsb builtin part of builtin_zero_pattern to match.pd. A simple pattern to port.
OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * match.pd (a != 0 ? CLRSB(a) : CST -> CLRSB(a)): New pattern. --- gcc/match.pd | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gcc/match.pd b/gcc/match.pd index 0e782cde71d..bf918ba70ce 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -7787,6 +7787,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (cond (ne @0 integer_zerop@1) (func@4 (convert? @2)) integer_zerop@3) @4)) +/* a != 0 ? FUN(a) : CST -> Fun(a) for some CLRSB builtins + where CST is precision-1. */ +(for func (CLRSB) + (simplify + (cond (ne @0 integer_zerop@1) (func@5 (convert?@4 @2)) INTEGER_CST@3) + (if (wi::to_widest (@3) == TYPE_PRECISION (TREE_TYPE (@4)) - 1) + @5))) + #if GIMPLE /* a != 0 ? CLZ(a) : CST -> .CLZ(a) where CST is the result of the internal function for 0. */ (for func (CLZ) -- 2.31.1