Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizer does not take advantage of -value == ~(value - 1) #47903

Closed
mahkoh opened this issue Dec 19, 2020 · 3 comments
Closed

Optimizer does not take advantage of -value == ~(value - 1) #47903

mahkoh opened this issue Dec 19, 2020 · 3 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla

Comments

@mahkoh
Copy link
Member

mahkoh commented Dec 19, 2020

Bugzilla Link 48559
Resolution FIXED
Resolved on Dec 21, 2020 09:52
Version 11.0
OS Linux
CC @rotateright
Fixed by commit(s) 38ca7fa

Extended Description

Test case:

long f(long align) {
return (align - 1) & -align;
}

long g(long align) {
return (align - 1) & ~(align - 1);
}

int h(long align) {
return -align == ~(align - 1);
}

Generated assembly:

f:
leaq -1(%rdi), %rax
negq %rdi
andq %rdi, %rax
retq
g:
xorl %eax, %eax
retq
h:
movl $1, %eax
retq

@mahkoh
Copy link
Member Author

mahkoh commented Dec 19, 2020

assigned to @rotateright

@rotateright
Copy link
Contributor

This is a special-case of a more general pattern that ends in a bitwise logic op and includes add/sub operands. For example:
https://alive2.llvm.org/ce/z/mxoxUz

I think these are the generalizations we should handle in instsimplify:
https://rise4fun.com/Alive/gR0

@rotateright
Copy link
Contributor

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

2 participants