-
Notifications
You must be signed in to change notification settings - Fork 13.9k
[X86] Add verifyTargetSDNode for x86 target specific nodes #123589
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
base: main
Are you sure you want to change the base?
Conversation
This allows us to verify/assert the node's validity on creation instead of waiting for when its used in a combine/analysis. Add some initial verification for X86ISD::KSHIFL\R and X86ISD::PSADBW types - more to follow.
@llvm/pr-subscribers-backend-x86 Author: Simon Pilgrim (RKSimon) ChangesThis allows us to verify/assert the node's validity on creation instead of waiting for when its used in a combine/analysis. Added some initial verification for X86ISD::KSHIFL\R and X86ISD::PSADBW types - more to follow. Full diff: https://github.com/llvm/llvm-project/pull/123589.diff 2 Files Affected:
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 33ddcb57e9b08b..8a4844bc0afce8 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -61009,3 +61009,31 @@ Align X86TargetLowering::getPrefLoopAlignment(MachineLoop *ML) const {
return Align(1ULL << ExperimentalPrefInnermostLoopAlignment);
return TargetLowering::getPrefLoopAlignment();
}
+
+#ifndef NDEBUG
+void X86TargetLowering::verifyTargetSDNode(const SDNode *N) const {
+ switch (N->getOpcode()) {
+ default:
+ break;
+ case X86ISD::KSHIFTL:
+ case X86ISD::KSHIFTR: {
+ EVT VT = N->getValueType(0);
+ auto *Amt = cast<ConstantSDNode>(N->getOperand(1));
+ assert(Amt->getAPIntValue().ult(VT.getVectorNumElements()) &&
+ "Out of range KSHIFT shift amount");
+ break;
+ }
+ case X86ISD::PSADBW: {
+ EVT VT = N->getValueType(0);
+ SDValue LHS = N->getOperand(0);
+ SDValue RHS = N->getOperand(1);
+ assert((VT == MVT::v2i64 || VT == MVT::v4i64 || VT == MVT::v8i64) &&
+ LHS.getValueType() == RHS.getValueType() &&
+ LHS.getValueSizeInBits() == VT.getSizeInBits() &&
+ LHS.getValueType().getScalarType() == MVT::i8 &&
+ "Unexpected PSADBW types");
+ break;
+ }
+ }
+}
+#endif
diff --git a/llvm/lib/Target/X86/X86ISelLowering.h b/llvm/lib/Target/X86/X86ISelLowering.h
index 03f10a3c83e30c..b8517018067d8b 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.h
+++ b/llvm/lib/Target/X86/X86ISelLowering.h
@@ -1658,6 +1658,10 @@ namespace llvm {
return TargetLoweringBase::getTypeToTransformTo(Context, VT);
}
+#ifndef NDEBUG
+ void verifyTargetSDNode(const SDNode *N) const override;
+#endif
+
protected:
std::pair<const TargetRegisterClass *, uint8_t>
findRepresentativeClass(const TargetRegisterInfo *TRI,
|
assert((VT == MVT::v2i64 || VT == MVT::v4i64 || VT == MVT::v8i64) && | ||
LHS.getValueType() == RHS.getValueType() && | ||
LHS.getValueSizeInBits() == VT.getSizeInBits() && | ||
LHS.getValueType().getScalarType() == MVT::i8 && |
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.
We have defined the node with
SDTCVecEltisVT<0, i64>
, SDTCVecEltisVT<1, i8>
and SDTCisSameAs<1,2>
.
Do we still need these check 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.
That would only check at selection - it'd be nice to be able to auto generate these checks for verifyTargetSDNode but it'd be a rather large job.
What I'm finding is that verifyTargetSDNode is fantastic for tracing problems, especially during debugging, as its called as part of getNode() - so the assertion occurs in the code stack where the node is created - we have some similar asserts in the node combines / known bits etc. but working out where the node came from isn't always straightforward (or requires trawling through logs).
I'm tempted to remove the equivalent asserts from other locations as verifyTargetSDNode should have caught most cases.
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.
it'd be nice to be able to auto generate these checks for verifyTargetSDNode but it'd be a rather large job.
FYI I'm doing that in #119709.
Although as-is it doesn't catch everything yet.
Is it worth putting them in a separate file if there are a lot of nodes to check? |
Going to leave this as draft and see what we still need to do after #119709 |
This allows us to verify/assert the node's validity on creation instead of waiting for when its used in a combine/analysis.
Added some initial verification for X86ISD::KSHIFL\R and X86ISD::PSADBW types - more to follow.