This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/78037] Incorrect code generated at optimization level -O2 for tzcnt and binary and
- From: "jakub at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 19 Oct 2016 12:03:00 +0000
- Subject: [Bug target/78037] Incorrect code generated at optimization level -O2 for tzcnt and binary and
- Auto-submitted: auto-generated
- References: <bug-78037-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78037
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org,
| |uros at gcc dot gnu.org
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
That is because _tzcnt_u64 is expanded as __builtin_ctzll, which is explicitly
UB with zero argument. So, either we need to expand it like
x ? __builtin_ctzll (x) : 64 and make sure at RTL level we optimize this into
just tzcnt instruction if available (though, that is questionable, because if
you run tzcntq instruction on non-BMI CPUs, it will just be BSF with undefined
result for 0), or add a new builtin, or unconditionally expand to the
conditional.