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

Missing transformation rotate(x) == 0 to x == 0 #50908

Closed
davidbolvansky opened this issue Aug 20, 2021 · 2 comments
Closed

Missing transformation rotate(x) == 0 to x == 0 #50908

davidbolvansky opened this issue Aug 20, 2021 · 2 comments
Labels
bugzilla Issues migrated from bugzilla

Comments

@davidbolvansky
Copy link
Collaborator

Bugzilla Link 51566
Resolution FIXED
Resolved on Sep 03, 2021 12:36
Version trunk
OS Linux
CC @RKSimon,@rotateright
Fixed by commit(s) fd80760

Extended Description

bool test1(unsigned long long x)
{
unsigned long long r = (x << 32) | (x >> 32);
return r != 0;

}

bool test2(unsigned long long x)
{
unsigned long long r = (x << 32) | (x >> 32);
return r == ~0ULL;
}

Trunk -O3:
test1(unsigned long long): # @​test1(unsigned long long)
rol rdi, 32
test rdi, rdi
setne al
ret
test2(unsigned long long): # @​test2(unsigned long long)
rol rdi, 32
cmp rdi, -1
sete al
ret
test3(unsigned long long): # @​test3(unsigned long long)
rol rdi, 32
test rdi, rdi
setne al
ret

Current codegen:
https://godbolt.org/z/q78xxhWe4


define i1 @​src(i64 %0) {
%1:
%2 = fshr i64 %0, i64 %0, i64 32
%3 = icmp ne i64 %2, 0
ret i1 %3
}
=>
define i1 @​tgt(i64 %0) {
%1:
%2 = icmp ne i64 %0, 0
ret i1 %2
}
Transformation seems to be correct!


define i1 @​src(i64 %0) {
%1:
%2 = fshr i64 %0, i64 %0, i64 32
%3 = icmp ne i64 %2, -1
ret i1 %3
}
=>
define i1 @​tgt(i64 %0) {
%1:
%2 = icmp ne i64 %0, -1
ret i1 %2
}
Transformation seems to be correct!

Alive:
https://alive2.llvm.org/ce/z/kmrBvv

@rotateright
Copy link
Contributor

https://alive2.llvm.org/ce/z/kmrBvv

To generalize, the rotate amount can be anything if the result is checking if all bits are set/clear.

So I think there are 8 cases to test:

  1. Either fshl or fshr
  2. Either eq or ne predicate
  3. Either 0 or -1 icmp constant

So something like this (and we can substitute fshr/fshl):
https://alive2.llvm.org/ce/z/V-sEy9

@rotateright
Copy link
Contributor

Should be fixed with:
https://reviews.llvm.org/rGfd807601a784

@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