This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/81759] New: Improve data tracking for _pext_u64 and __builtin_ffsll
- From: "bugzilla at poradnik-webmastera dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 07 Aug 2017 21:40:35 +0000
- Subject: [Bug c/81759] New: Improve data tracking for _pext_u64 and __builtin_ffsll
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81759
Bug ID: 81759
Summary: Improve data tracking for _pext_u64 and
__builtin_ffsll
Product: gcc
Version: 7.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: bugzilla@poradnik-webmastera.com
Target Milestone: ---
This simple function gets index of least significant byte with its MSB cleared:
#include <stdint.h>
#include "immintrin.h"
uint64_t get_first_msb_cleared(uint64_t val)
{
uint64_t msbs = _pext_u64(val, 0x8080808080808080);
uint64_t msb_index = __builtin_ffsll(~msbs) - 1;
return msb_index;
}
Here is assembly generated by gcc 7.1 (according to https://godbolt.org/):
get_first_msb_cleared(unsigned long):
movabs rax, -9187201950435737472
pext rdi, rdi, rax
mov rax, -1
not rdi
bsf rdi, rdi
cmove rdi, rax
movsx rax, edi
ret
gcc could do better job here. In this case value returned by _pext_u64 has bits
9-64 set to zero, so after negation they will be set to 1. Because of this gcc
could skip "mov rax, -1" and "cmove rdi, rax", this code path is dead.