-
Notifications
You must be signed in to change notification settings - Fork 12k
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
[AArch64][CodeGen][CodeSize] Redundant 'and' can be remove with shifts in addr mode #34101
Comments
In DAGCombiner.cpp around line 5590 we have this target-independent combine which is folding the 'srl' and introducing the 'and'. // fold (shl (srl x, c1), c2) -> (and (shl x, (sub c2, c1), MASK) or
// (and (srl x, (sub c1, c2), MASK)
// Only fold this if the inner shift has no other uses -- if it does, folding
// this will increase the total number of instructions. |
Here's the test in IR: define i32 @test(i64 %a, i64 %b, i32* nocapture readonly %table) {
entry:
%mul = mul i64 %b, %a
%shr = lshr i64 %mul, 58
%arrayidx = getelementptr inbounds i32, i32* %table, i64 %shr
%0 = load i32, i32* %arrayidx, align 4
ret i32 %0
} And the initial DAG:
|
I'm not sure how to implement this. This assembly test: // @test
// BB#0: // %entry
mul x8, x1, x0
lsr x8, x8, #​58
ldr w0, [x2, x8, lsl#2]
ret I get when I skip fold (shl (srl x, c1), c2) -> (and (srl x, (sub c1, c2), MASK). |
@llvm/issue-subscribers-good-first-issue |
is this still open to work on ? |
Still seems to be a problem in trunk: https://simd.godbolt.org/z/595f991fP |
can this issue be resolved by disabling optimization |
Currently, process of replacing bitwise operations consisting of `LSR`/`LSL` with `And` is performed by `DAGCombiner`. However, in certain cases, the `AND` generated by this process can be removed. Consider following case: ``` lsr x8, x8, llvm#56 and x8, x8, #0xfc ldr w0, [x2, x8] ret ``` In this case, we can remove the `AND` by changing the target of `LDR` to `[X2, X8, LSL llvm#2]` and right-shifting amount change to 56 to 58. after changed: ``` lsr x8, x8, llvm#58 ldr w0, [x2, x8, lsl llvm#2] ret ``` This patch checks to see if the `SHIFTING` + `AND` operation on load target can be optimized and optimizes it if it can.
Currently, process of replacing bitwise operations consisting of `LSR`/`LSL` with `And` is performed by `DAGCombiner`. However, in certain cases, the `AND` generated by this process can be removed. Consider following case: ``` lsr x8, x8, llvm#56 and x8, x8, #0xfc ldr w0, [x2, x8] ret ``` In this case, we can remove the `AND` by changing the target of `LDR` to `[X2, X8, LSL llvm#2]` and right-shifting amount change to 56 to 58. after changed: ``` lsr x8, x8, llvm#58 ldr w0, [x2, x8, lsl llvm#2] ret ``` This patch checks to see if the `SHIFTING` + `AND` operation on load target can be optimized and optimizes it if it can.
Currently, process of replacing bitwise operations consisting of `LSR`/`LSL` with `And` is performed by `DAGCombiner`. However, in certain cases, the `AND` generated by this process can be removed. Consider following case: ``` lsr x8, x8, #56 and x8, x8, #0xfc ldr w0, [x2, x8] ret ``` In this case, we can remove the `AND` by changing the target of `LDR` to `[X2, X8, LSL #2]` and right-shifting amount change to 56 to 58. after changed: ``` lsr x8, x8, #58 ldr w0, [x2, x8, lsl #2] ret ``` This patch checks to see if the `SHIFTING` + `AND` operation on load target can be optimized and optimizes it if it can.
) Currently, process of replacing bitwise operations consisting of `LSR`/`LSL` with `And` is performed by `DAGCombiner`. However, in certain cases, the `AND` generated by this process can be removed. Consider following case: ``` lsr x8, x8, llvm#56 and x8, x8, #0xfc ldr w0, [x2, x8] ret ``` In this case, we can remove the `AND` by changing the target of `LDR` to `[X2, X8, LSL llvm#2]` and right-shifting amount change to 56 to 58. after changed: ``` lsr x8, x8, llvm#58 ldr w0, [x2, x8, lsl llvm#2] ret ``` This patch checks to see if the `SHIFTING` + `AND` operation on load target can be optimized and optimizes it if it can.
…1863d2644 Local branch amd-gfx 08f1863 Merged main:6f618a7b8249e7baa3b2d18f8bbec3c5b6f6d24e into amd-gfx:e5edfda5900b Remote branch main 77fccb3 [AArch64] Replace AND with LSL#2 for LDR target (llvm#34101) (llvm#89531)
Extended Description
Test case:
Current assembly:
We should be able to remove the 'and' for a code size with as follows:
I'm not interested in pursuing this optimization, but I figured I'd file the bug, regardless.
The text was updated successfully, but these errors were encountered: