we can safely replace a zext instruction with sext if the top bit is zero. This is useful because we can select smull when both operands are sign extended.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp | ||
---|---|---|
4466 | NewOpc has no value if LastBitValue is not zero in the previous if block. It will lost some opportunities to use UMULL to do unsigned multiplication. It is why some test cases become worse. Do you think it is a good way to check NewOpc before checking isN0ZExt && isN1ZExt? That is if (!NewOpc) { if (isN0ZExt && isN1ZExt) NewOpc = AArch64ISD::UMULL; else if (isN1SExt || isN1ZExt) { // ... } } |
Thanks for the patch @zjaffal! Please update the code as suggested by @HsiangKai to fix the regressions in the test case.
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp | ||
---|---|---|
4448 | The logic with the nested ifs is a bit hard to follow now. Would it be possible to simplify the code by moving all those checks to a static helper function which returns the new opcode (and updates the other variables as required)? This would allow to use early exits to reduce the need for nested of conditions. |
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp | ||
---|---|---|
4455 | Just a couple of drive-by comments:
|
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp | ||
---|---|---|
4455 | The depth is 4 following a similar code block in the same file // Check if the value is zero-extended from i1 to i8 static bool checkZExtBool(SDValue Arg, const SelectionDAG &DAG) { unsigned SizeInBits = Arg.getValueType().getSizeInBits(); if (SizeInBits < 8) return false; APInt RequredZero(SizeInBits, 0xFE); KnownBits Bits = DAG.computeKnownBits(Arg, 4); bool ZExtBool = (Bits.Zero & RequredZero) == RequredZero; return ZExtBool; } I tested the implementation using DAG.SignBitIsZero() and it works with depth=0 |
Refactor common code for selecting multiplication instruction out of the main code for LowerMul, rewrite checking for the top bit to use DAG.SignBitIsZero and refactor on top of the added new tests
Thanks for the update! Could you split out the code that adds selectUmullSmull into a separate NFC patch and then update this patch to just add the new handling for converting zext to sext?
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp | ||
---|---|---|
4381 | Is there some other changes needed here, to pass a DL through to the function from the callsites of selectUmullSmull? |
Thanks. A small nit, but otherwise this looks like a good patch. The newly created node will never be used, but I don't think that would be a problem. LGTM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp | ||
---|---|---|
4407 | Small nit but can you move this above the new code? This condition and the new one are mutually exclusive, and it would seem a little better to have the check for two zext next to the bool IsN0ZExt = ..., the same as the base smull case. |
Is there some other changes needed here, to pass a DL through to the function from the callsites of selectUmullSmull?