Skip to content

x.trailing_zeros() > n is not optimized as well as x & ((1 << n) - 1) == 0 on x86 #43024

Closed
@oli-obk

Description

@oli-obk

the bitshift and bitand version optimizes to

	testb	$15, %dil
	sete	%al
	retq

while the trailing_zeros version optimizes to

	movl	$32, %eax
	testl	%edi, %edi
	je	.LBB6_2
	bsfl	%edi, %eax
.LBB6_2:
	cmpl	$4, %eax
	seta	%al
	retq

even though I find the trailing_zeros version much more straight forward

Should this be reported upstream in llvm or is this something a mir pass should do?

Metadata

Metadata

Assignees

Labels

A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-enhancementCategory: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions