This helps simplify a USHR+ORR into USRA on AArch64
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/test/CodeGen/AArch64/shift-accumulate.ll | ||
---|---|---|
124 | Pre-commit this test and rebase the current patch on top of it? |
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp | ||
---|---|---|
1976 | Could you you change it to dyn_cast with if to get the correct assert and error message? |
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp | ||
---|---|---|
1979 | I think its needs to be the same width as Known. Otherwise Known bitwidth will be changed and cause trouble later. | |
llvm/test/CodeGen/AArch64/shift-accumulate.ll | ||
124 | Hi Jay Thank you for the comment. Do you mean I should change this test and commit it as a separate patch before the actual change (i.e. the implementation of the MOVI) ? |
llvm/test/CodeGen/AArch64/shift-accumulate.ll | ||
---|---|---|
124 | Yes. Commit the test in a form that will pass on trunk, and then when you rebase this patch, it'll show the difference in the codegen caused by your patch. That makes it much easier for reviewers to see the effect of your patch. (I'm not an AArch64 reviewer but this is pretty common practice for the backends I've worked on.) |
llvm/test/CodeGen/AArch64/shift-accumulate.ll | ||
---|---|---|
124 | Makes sense !. I will do so once this patch is accepted. Thanks for teaching me this. |
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp | ||
---|---|---|
1976 | I still believe that you need and if to check in Release mode whether it really is a constant node. |
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp | ||
---|---|---|
1976 | No, just use cast<> and remove the assert. |
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp | ||
---|---|---|
1976 | Thanks for the comment. I went back to check "The cast<> operator is a “checked cast” operation. It converts a pointer or reference from a base class to a derived class, causing an assertion failure if it is not really an instance of the right type." This seems to be what we want. Let me know if there are other concerns! |
There are other MOVI nodes created in ISel, have you considered adding support for those too?
MOVI, MOVIshift, MOVIedit, MOVImsl, FMOV, MVNIshift, MVNImsl,
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp | ||
---|---|---|
1976 | cast will do the assert for you. I would think it would be OK to always use case and drop the assert. The operand of a MOVI will always be a ConstantSDNode. There is no need to check for it in release builds, it should be correct by construction. | |
llvm/test/CodeGen/AArch64/shift-accumulate.ll | ||
124 | Can you expand this to other types too. For example this, as well as i64 variants: define <4 x i32> @usra_with_movi16(<8 x i16> %0, <8 x i16> %1) { ; CHECK-LABEL: usra_with_movi: ; CHECK: // %bb.0: ; CHECK-NEXT: movi v2.16b, #1 ; CHECK-NEXT: cmeq v0.16b, v0.16b, v1.16b ; CHECK-NEXT: and v0.16b, v0.16b, v2.16b ; CHECK-NEXT: usra v0.8h, v0.8h, #7 ; CHECK-NEXT: ret %3 = icmp eq <8 x i16> %0, %1 %4 = zext <8 x i1> %3 to <8 x i16> %5 = bitcast <8 x i16> %4 to <4 x i32> %6 = lshr <4 x i32> %5, <i32 7, i32 7, i32 7, i32 7> %7 = or <4 x i32> %6, %5 ret <4 x i32> %7 } |
This patch comes out of a workload we have inside the company. Only MOVI needs to be fixed here. I will certainly implement support for others if there are use cases for them.
It may be worth implementing them in separate patches to keep the changes small. If you can add the test cases for different sizes, this LGTM.
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp | ||
---|---|---|
1979 | Makes sense. The constant should always be an i32, even though the typesize is i8. |
Could you you change it to dyn_cast with if to get the correct assert and error message?