Legalize and select G_ABS so that we can use llvm.abs intrinsic
Details
Diff Detail
Event Timeline
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp | ||
---|---|---|
2008 | This has to be a signext, so the wide value gets the same sign as the narrow value. Otherwise the wide G_ABS might behave differently from the narrow G_ABS. | |
llvm/lib/Target/AMDGPU/VOP3Instructions.td | ||
773 ↗ | (On Diff #345075) | Don't bother with this pattern, just make G_ABS s16 only legal on subtargets that have 16 bit instructions. |
llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.abs.ll | ||
11 | Typo "sgpr" in lots of function names. |
llvm/lib/Target/AMDGPU/SOPInstructions.td | ||
---|---|---|
1370 | No need for a separate pattern for this, you can do it as part of the definition of S_ABS_I32. See S_NOT_I32 for an example. |
llvm/lib/Target/AMDGPU/VOP3Instructions.td | ||
---|---|---|
758–760 ↗ | (On Diff #345075) | Should be expanding the vector case in regbankselect |
llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.abs.ll | ||
---|---|---|
42–44 | Not really related to your patch, but this sequence needs cleaning up. The s_and is redundant, and the s_cmp just computes the same scc value that s_add computed in the first place. |
llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.abs.ll | ||
---|---|---|
42–44 | This is probably a consequence of not having a pass to minimize scc/physreg liveranges |
llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.abs.ll | ||
---|---|---|
42–44 | We have this tracked as a separate issue. |
llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp | ||
---|---|---|
977 | Merge this with the G_SMIN, G_SMAX, G_UMIN, G_UMAX handling above, which is slightly better because it will widen e.g. s8 to s16 and s24 to s32, instead of lowering them. | |
1000 | Same here, mege it with the slightly better G_SMIN, G_SMAX, G_UMIN, G_UMAX handling above. |
llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp | ||
---|---|---|
2320–2322 | I would hope that you could call the LegalizerHelper for this part. However I see the lower() implementation hardcodes one path and doesn't provide the helpers for the multiple options. Ideally we could clean that up |
LGTM, but maybe try Matt's idea about using LegalizerHelper functions as a follow up?
- Added legalizeABS() as a custom lowering to be used by RegBankSelect.
I don't see a way to add multiple paths to already existing lower() for G_ABS and control which one to use. Not sure if this is the cleaner way of doing it that you had in mind.
- Add lowerAbsToMaxSub as a new LegalizerHelper function to be used by AMDGPURegisterBankInfo
- Move default code for lowering G_ABS to lowerAbs to make it more clear there are two ways of legalizing.
Maybe rename lowerAbs to lowerAbsToAshrAddXor or lowerAbsToAddXor?
LGTM.
Maybe rename lowerAbs to lowerAbsToAshrAddXor or lowerAbsToAddXor?
Maybe call them lowerAbsToAddXor and lowerAbsToMaxNeg?
llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp | ||
---|---|---|
2316 | Too many parentheses. |
This has to be a signext, so the wide value gets the same sign as the narrow value. Otherwise the wide G_ABS might behave differently from the narrow G_ABS.