-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Multiply by a power of 2 and ctz+shift should often be interchangeable #84763
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
Comments
Could you also include the LLVM IR that gets generated for both functions (and ideally also an alive2 proof that the transformation is correct)? |
I think the ask is for this transform? https://alive2.llvm.org/ce/z/Aht97G |
@dtcxzyw @goldsteinn I'm a bit unsure on whether this is better suited as a middle-end or back-end transform. Any thoughts? |
I think @nikic already provided you what you were asking for, but the reason this works is as follows: The idiom |
Related #76810 |
We can canonicalize |
Confirmed that the pattern |
Looks like the canonicalization is valueless :(
I am preparing a patch for CGP. |
Is this the same issue that I've reported in GCC bug tracker? GCC bug 114341 Just for reference :) |
…is unsupported (#85066) This patch fold `shl X, cttz(Y)` to `mul (Y & -Y), X` if cttz is unsupported by the target. Alive2: https://alive2.llvm.org/ce/z/AtLN5Y Fixes #84763.
…is unsupported (llvm#85066) This patch fold `shl X, cttz(Y)` to `mul (Y & -Y), X` if cttz is unsupported by the target. Alive2: https://alive2.llvm.org/ce/z/AtLN5Y Fixes llvm#84763.
The compiler should probably be able to optimize either of these functions to the other one, depending on cost for the particular hardware (Godbolt link):
x86 znver4 emit:
RISC-V sifive_u74 emit:
The text was updated successfully, but these errors were encountered: