Skip to content

[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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions llvm/lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Comment on lines +61030 to +61033
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Contributor

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.

"Unexpected PSADBW types");
break;
}
}
}
#endif
4 changes: 4 additions & 0 deletions llvm/lib/Target/X86/X86ISelLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading