-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 fold trunc(ctlz(zext(x))) -> add(ctlz(x), C) #49517
Comments
For known negative x define i32 @src(i16 %x) { |
Hi Sir, |
Go for it - you should find similar code inside InstCombineCasts.cpp already that you can reference. Once you have something its best to create an initial patch on Phabricator and people can help you there with its development. |
Hi Simon, David, I have added unit test as well for a few datatypes. Please have a look. |
Please ignore comment #2, llvm already handles it. |
ok |
Extended Description
define i16 @src(i16 %x) {
%z = zext i16 %x to i32
%p = call i32 @llvm.ctlz.i32(i32 %z, i1 false)
%zz = trunc i32 %p to i16
ret i16 %zz
}
define i16 @tgt(i16 %x) {
%p = call i16 @llvm.ctlz.i16(i16 %x, i1 false)
%z = add i16 %p, 16
ret i16 %z
}
declare i32 @llvm.ctlz.i32(i32, i1)
declare i16 @llvm.ctlz.i16(i16, i1)
define i16 @src(i16 %x) {
%0:
%z = zext i16 %x to i32
%p = ctlz i32 %z, 0
%zz = trunc i32 %p to i16
ret i16 %zz
}
=>
define i16 @tgt(i16 %x) {
%0:
%p = ctlz i16 %x, 0
%z = add i16 %p, 16
ret i16 %z
}
Transformation seems to be correct!
The text was updated successfully, but these errors were encountered: