]> git.ipfire.org Git - thirdparty/gcc.git/commit
fold-const: Fix up CLZ handling in tree_call_nonnegative_warnv_p [PR115337]
authorJakub Jelinek <jakub@redhat.com>
Tue, 4 Jun 2024 13:49:41 +0000 (15:49 +0200)
committerJakub Jelinek <jakub@redhat.com>
Tue, 4 Jun 2024 13:49:41 +0000 (15:49 +0200)
commitb82a816000791e7a286c7836b3a473ec0e2a577b
treebfd15d2385b06cd65c152bd18121efaba4d8a045
parent00fb385a25a7fbaa9c7060ddd5f41a8c3b1548d1
fold-const: Fix up CLZ handling in tree_call_nonnegative_warnv_p [PR115337]

The function currently incorrectly assumes all the __builtin_clz* and .CLZ
calls have non-negative result.  That is the case of the former which is UB
on zero and has [0, prec-1] return value otherwise, and is the case of the
single argument .CLZ as well (again, UB on zero), but for two argument
.CLZ is the case only if the second argument is also nonnegative (or if we
know the argument can't be zero, but let's do that just in the ranger IMHO).

The following patch does that.

2024-06-04  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/115337
* fold-const.cc (tree_call_nonnegative_warnv_p) <CASE_CFN_CLZ>:
If arg1 is non-NULL, RECURSE on it, otherwise return true.

* gcc.dg/bitint-106.c: New test.
gcc/fold-const.cc
gcc/testsuite/gcc.dg/bitint-106.c [new file with mode: 0644]