match.pd: Fix up FFS -> CTZ + 1 optimization [PR97325]
authorJakub Jelinek <jakub@redhat.com>
Fri, 9 Oct 2020 08:16:57 +0000 (10:16 +0200)
committerJakub Jelinek <jakub@redhat.com>
Fri, 9 Oct 2020 08:18:41 +0000 (10:18 +0200)
commit600cf1128e49f086522bfddc54490b4e39e30383
tree394041ef76ed7c8ba90598b84683260a69fae9dd
parent6887244269e0c412afd43474e13fa5ca12c350c4
match.pd: Fix up FFS -> CTZ + 1 optimization [PR97325]

And no testcase was included, I'm including one below.

Anyway, this PR and the other CTZ related discussions led me to discover a
bug I've made earlier, CLZ/CTZ builtins have unsigned arguments and e.g.
both the vr-values.cc and now gimple-range.cc code heavily relies on that,
but __builtin_ffs has a signed operand and this optimization was incorrectly
making the operand signed too, so I guess it would greatly confuse VRP in
some cases.

2020-10-09  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/97325
* match.pd (FFS(nonzero) -> CTZ(nonzero) + 1): Cast argument to
corresponding unsigned type.

* gcc.c-torture/execute/pr97325.c: New test.
gcc/match.pd
gcc/testsuite/gcc.c-torture/execute/pr97325.c [new file with mode: 0644]