Skip to content

Combine and-mask+icmp eq -> icmp ule when mask was all-ones in low bits #37471

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

Closed
LebedevRI opened this issue Jul 10, 2018 · 9 comments
Closed
Assignees
Labels
bugzilla Issues migrated from bugzilla

Comments

@LebedevRI
Copy link
Member

Bugzilla Link 38123
Resolution FIXED
Resolved on Aug 31, 2018 06:28
Version trunk
OS Linux
CC @topperc,@RKSimon,@rotateright

Extended Description

https://rise4fun.com/Alive/W2u
https://godbolt.org/g/sCX9A6

This pattern will be produced by Implicit Integer Trucation sanitizer,
(https://reviews.llvm.org/D48958)
in unsigned case, therefore it is probably a good idea to improve it.

@LebedevRI
Copy link
Member Author

assigned to @LebedevRI

@LebedevRI
Copy link
Member Author

https://godbolt.org/g/sCX9A6
That was of course should have been https://godbolt.org/g/eMV9aw

@rotateright
Copy link
Contributor

This seems less likely, but there's always some kind of symmetrical pattern if you solve the problem generally:

Name: range using high bits
%masked = or i8 %arg, 192
%r = icmp ne i8 %masked, %arg
=>
%r = icmp ult i8 %arg, 192

?

@LebedevRI
Copy link
Member Author

This seems less likely, but there's always some kind of symmetrical pattern
if you solve the problem generally:

Name: range using high bits
%masked = or i8 %arg, 192
%r = icmp ne i8 %masked, %arg
=>
%r = icmp ult i8 %arg, 192

?

Heh, yes, i was planning on handling more patterns.
These are all the patterns with low-bit-mask i can think of:
https://rise4fun.com/Alive/Rny

The patterns with high bit mask will be similar, but not everything at once..

@rotateright
Copy link
Contributor

Not sure if we wanted this bug to cover all of the predicates, but let me add the example from D49179 using signed compares, so we don't forget it:

Pre: isPowerOf2(C1+1)
%masked = and i32 %arg, C1
%truncheck = icmp sge i32 %masked, %arg
=>
%truncheck = icmp sle i32 %arg, C1

https://rise4fun.com/Alive/K8H

@LebedevRI
Copy link
Member Author

Not sure if we wanted this bug to cover all of the predicates, but let me
add the example from D49179 using signed compares, so we don't forget it:

Pre: isPowerOf2(C1+1)
%masked = and i32 %arg, C1
%truncheck = icmp sge i32 %masked, %arg
=>
%truncheck = icmp sle i32 %arg, C1

https://rise4fun.com/Alive/K8H

Ok, finished up the rest of unsigned predicates (for when mask is (-1 >> y)).

https://rise4fun.com/Alive/I3O <- following 4 folds are possible for signed predicates.

@LebedevRI
Copy link
Member Author

Not sure if we wanted this bug to cover all of the predicates, but let me
add the example from D49179 using signed compares, so we don't forget it:

Pre: isPowerOf2(C1+1)
%masked = and i32 %arg, C1
%truncheck = icmp sge i32 %masked, %arg
=>
%truncheck = icmp sle i32 %arg, C1

https://rise4fun.com/Alive/K8H

Ok, finished up the rest of unsigned predicates (for when mask is (-1 >> y)).

https://rise4fun.com/Alive/I3O <- following 4 folds are possible for signed
predicates.

Done, too. In this case with signed predicates, we had to explicitly ignore
the versions with "commuted" sides of the comparison.
That was a lot of commits, sorry for the noise.

The part (-1 << y) is TODO.

Also, i wonder if we can/should do anything about
patterns like (-1 >> y) | (-1 << (width - 1))
I.e. a mask with some low bits set, and always with a sign bit set, too.

@LebedevRI
Copy link
Member Author

This pattern with low-bit-mask was fixed via numerous commits.

I've filed llvm/llvm-bugzilla-archive#38791 to track the opposite pattern.

@LebedevRI
Copy link
Member Author

mentioned in issue llvm/llvm-bugzilla-archive#38791

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 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