-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[RISCV] Improve vmsge and vmsgeu selection #115435
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1616,28 +1616,37 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) { | |
| SDValue Src1 = Node->getOperand(1); | ||
| SDValue Src2 = Node->getOperand(2); | ||
| bool IsUnsigned = IntNo == Intrinsic::riscv_vmsgeu; | ||
| bool IsCmpUnsignedZero = false; | ||
| bool IsCmpConstant = false; | ||
| bool IsCmpMinimum = false; | ||
| // Only custom select scalar second operand. | ||
| if (Src2.getValueType() != XLenVT) | ||
| break; | ||
| // Small constants are handled with patterns. | ||
| int64_t CVal = 0; | ||
| MVT Src1VT = Src1.getSimpleValueType(); | ||
| if (auto *C = dyn_cast<ConstantSDNode>(Src2)) { | ||
| int64_t CVal = C->getSExtValue(); | ||
| IsCmpConstant = true; | ||
| CVal = C->getSExtValue(); | ||
| if (CVal >= -15 && CVal <= 16) { | ||
| if (!IsUnsigned || CVal != 0) | ||
| break; | ||
| IsCmpUnsignedZero = true; | ||
| IsCmpMinimum = true; | ||
| } else if (!IsUnsigned && | ||
| CVal == APSInt::getMinValue(Src1VT.getScalarSizeInBits(), | ||
| /*Unsigned=*/false)) { | ||
| IsCmpMinimum = true; | ||
| } | ||
| } | ||
| MVT Src1VT = Src1.getSimpleValueType(); | ||
| unsigned VMSLTOpcode, VMNANDOpcode, VMSetOpcode; | ||
| unsigned VMSLTOpcode, VMNANDOpcode, VMSetOpcode, VMSGTOpcode; | ||
| switch (RISCVTargetLowering::getLMUL(Src1VT)) { | ||
| default: | ||
| llvm_unreachable("Unexpected LMUL!"); | ||
| #define CASE_VMSLT_VMNAND_VMSET_OPCODES(lmulenum, suffix, suffix_b) \ | ||
| case RISCVII::VLMUL::lmulenum: \ | ||
| VMSLTOpcode = IsUnsigned ? RISCV::PseudoVMSLTU_VX_##suffix \ | ||
| : RISCV::PseudoVMSLT_VX_##suffix; \ | ||
| VMSGTOpcode = IsUnsigned ? RISCV::PseudoVMSGTU_VX_##suffix \ | ||
| : RISCV::PseudoVMSGT_VX_##suffix; \ | ||
| VMNANDOpcode = RISCV::PseudoVMNAND_MM_##suffix; \ | ||
| VMSetOpcode = RISCV::PseudoVMSET_M_##suffix_b; \ | ||
| break; | ||
|
|
@@ -1656,11 +1665,20 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) { | |
| selectVLOp(Node->getOperand(3), VL); | ||
|
|
||
| // If vmsgeu with 0 immediate, expand it to vmset. | ||
|
||
| if (IsCmpUnsignedZero) { | ||
| if (IsCmpMinimum) { | ||
| ReplaceNode(Node, CurDAG->getMachineNode(VMSetOpcode, DL, VT, VL, SEW)); | ||
| return; | ||
| } | ||
|
|
||
| if (IsCmpConstant) { | ||
| SDValue Imm = | ||
| selectImm(CurDAG, SDLoc(Src2), XLenVT, CVal - 1, *Subtarget); | ||
|
|
||
| ReplaceNode(Node, CurDAG->getMachineNode(VMSGTOpcode, DL, VT, | ||
| {Src1, Imm, VL, SEW})); | ||
| return; | ||
| } | ||
|
|
||
| // Expand to | ||
| // vmslt{u}.vx vd, va, x; vmnand.mm vd, vd, vd | ||
| SDValue Cmp = SDValue( | ||
|
|
@@ -1675,22 +1693,29 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) { | |
| SDValue Src1 = Node->getOperand(2); | ||
| SDValue Src2 = Node->getOperand(3); | ||
| bool IsUnsigned = IntNo == Intrinsic::riscv_vmsgeu_mask; | ||
| bool IsCmpUnsignedZero = false; | ||
| bool IsCmpConstant = false; | ||
| bool IsCmpMinimum = false; | ||
| // Only custom select scalar second operand. | ||
| if (Src2.getValueType() != XLenVT) | ||
| break; | ||
| // Small constants are handled with patterns. | ||
| MVT Src1VT = Src1.getSimpleValueType(); | ||
| int64_t CVal = 0; | ||
| if (auto *C = dyn_cast<ConstantSDNode>(Src2)) { | ||
| int64_t CVal = C->getSExtValue(); | ||
| IsCmpConstant = true; | ||
| CVal = C->getSExtValue(); | ||
| if (CVal >= -15 && CVal <= 16) { | ||
| if (!IsUnsigned || CVal != 0) | ||
| break; | ||
| IsCmpUnsignedZero = true; | ||
| IsCmpMinimum = true; | ||
| } else if (!IsUnsigned && | ||
| CVal == APSInt::getMinValue(Src1VT.getScalarSizeInBits(), | ||
| /*Unsigned=*/false)) { | ||
| IsCmpMinimum = true; | ||
| } | ||
| } | ||
| MVT Src1VT = Src1.getSimpleValueType(); | ||
| unsigned VMSLTOpcode, VMSLTMaskOpcode, VMXOROpcode, VMANDNOpcode, | ||
| VMOROpcode; | ||
| VMOROpcode, VMSGTMaskOpcode; | ||
| switch (RISCVTargetLowering::getLMUL(Src1VT)) { | ||
| default: | ||
| llvm_unreachable("Unexpected LMUL!"); | ||
|
|
@@ -1700,6 +1725,8 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) { | |
| : RISCV::PseudoVMSLT_VX_##suffix; \ | ||
| VMSLTMaskOpcode = IsUnsigned ? RISCV::PseudoVMSLTU_VX_##suffix##_MASK \ | ||
| : RISCV::PseudoVMSLT_VX_##suffix##_MASK; \ | ||
| VMSGTMaskOpcode = IsUnsigned ? RISCV::PseudoVMSGTU_VX_##suffix##_MASK \ | ||
| : RISCV::PseudoVMSGT_VX_##suffix##_MASK; \ | ||
| break; | ||
| CASE_VMSLT_OPCODES(LMUL_F8, MF8, B1) | ||
| CASE_VMSLT_OPCODES(LMUL_F4, MF4, B2) | ||
|
|
@@ -1738,7 +1765,7 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) { | |
| SDValue Mask = Node->getOperand(4); | ||
|
|
||
| // If vmsgeu_mask with 0 immediate, expand it to vmor mask, maskedoff. | ||
| if (IsCmpUnsignedZero) { | ||
| if (IsCmpMinimum) { | ||
| // We don't need vmor if the MaskedOff and the Mask are the same | ||
| // value. | ||
| if (Mask == MaskedOff) { | ||
|
|
@@ -1769,6 +1796,16 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) { | |
| SDValue Glue = Chain.getValue(1); | ||
| SDValue V0 = CurDAG->getRegister(RISCV::V0, VT); | ||
|
|
||
| if (IsCmpConstant) { | ||
| SDValue Imm = | ||
| selectImm(CurDAG, SDLoc(Src2), XLenVT, CVal - 1, *Subtarget); | ||
|
|
||
| ReplaceNode(Node, CurDAG->getMachineNode( | ||
| VMSGTMaskOpcode, DL, VT, | ||
| {MaskedOff, Src1, Imm, V0, VL, SEW, Glue})); | ||
| return; | ||
| } | ||
|
|
||
| // Otherwise use | ||
| // vmslt{u}.vx vd, va, x, v0.t; vmxor.mm vd, vd, v0 | ||
| // The result is mask undisturbed. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use INT64_MIN here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Err nevermind it needs to be element sized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But you should use APInt::getSignedMinValue(Src1VT.getScalarSizeInBits())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed