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

[InstCombine] fshl(x, 0, y) with in-range y not converted to shl x, y #122235

Open
nikic opened this issue Jan 9, 2025 · 2 comments · May be fixed by #122362
Open

[InstCombine] fshl(x, 0, y) with in-range y not converted to shl x, y #122235

nikic opened this issue Jan 9, 2025 · 2 comments · May be fixed by #122362

Comments

@nikic
Copy link
Contributor

nikic commented Jan 9, 2025

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

define i32 @src(i32 %x, i32 range(i32 0, 32) %y) {
    %res = call i32 @llvm.fshl(i32 %x, i32 0, i32 %y)
    ret i32 %res
}

define i32 @tgt(i32 %x, i32 range(i32 0, 32) %y) {
    %res = shl i32 %x, %y
    ret i32 %res
}

We currently only do this if the shift amount is constant, but not for a dynamic shift amount that is < bitwidth based on known bits.

@nikic
Copy link
Contributor Author

nikic commented Jan 9, 2025

@dtcxzyw suggested masking the shift amount as an alternative:

https://alive2.llvm.org/ce/z/3oTEop

define i32 @src(i32 %x, i32 %y) {
  %res = call i32 @llvm.fshl.i32(i32 %x, i32 0, i32 %y)
  ret i32 %res
}

define i32 @tgt(i32 %x, i32 %y) {
  %rem = and i32 %y, 31
  %res = shl i32 %x, %rem
  ret i32 %res
}

@AmrDeveloper
Copy link
Member

Interested, I can work on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants