-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[X86] Improve KnownBits for X86ISD::PSADBW nodes #83830
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36739,6 +36739,26 @@ X86TargetLowering::targetShrinkDemandedConstant(SDValue Op, | |
return TLO.CombineTo(Op, NewOp); | ||
} | ||
|
||
static void computeKnownBitsForPSADBW(SDValue LHS, SDValue RHS, | ||
KnownBits &Known, | ||
const APInt &DemandedElts, | ||
const SelectionDAG &DAG, unsigned Depth) { | ||
KnownBits Known2; | ||
unsigned NumSrcElts = LHS.getValueType().getVectorNumElements(); | ||
APInt DemandedSrcElts = APIntOps::ScaleBitMask(DemandedElts, NumSrcElts); | ||
Known = DAG.computeKnownBits(RHS, DemandedSrcElts, Depth + 1); | ||
Known2 = DAG.computeKnownBits(LHS, DemandedSrcElts, Depth + 1); | ||
Known = KnownBits::absdiff(Known, Known2).zext(16); | ||
// Known = (((D0 + D1) + (D2 + D3)) + ((D4 + D5) + (D6 + D7))) | ||
Known = KnownBits::computeForAddSub(/*Add=*/true, /*NSW=*/true, /*NUW=*/true, | ||
Known, Known); | ||
Known = KnownBits::computeForAddSub(/*Add=*/true, /*NSW=*/true, /*NUW=*/true, | ||
Known, Known); | ||
Known = KnownBits::computeForAddSub(/*Add=*/true, /*NSW=*/true, /*NUW=*/true, | ||
Known, Known); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other than this, it all looks good. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I was just trying to make it explicitly match the PSADBW expansion as possible, but I can just replace it with a shl by 3 (not 8). Fun fact: KnownBits::shl doesn't need the shift amount to be the same bitwidth as the shift value :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would KnownBits::shl make the lower 3 bits of Known.Zero true? That would be wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah you're right :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, noticed that when I tried it - I used the computeForAddSub chain instead |
||
Known = Known.zext(64); | ||
} | ||
|
||
void X86TargetLowering::computeKnownBitsForTargetNode(const SDValue Op, | ||
KnownBits &Known, | ||
const APInt &DemandedElts, | ||
|
@@ -36888,12 +36908,13 @@ void X86TargetLowering::computeKnownBitsForTargetNode(const SDValue Op, | |
break; | ||
} | ||
case X86ISD::PSADBW: { | ||
SDValue LHS = Op.getOperand(0); | ||
SDValue RHS = Op.getOperand(1); | ||
assert(VT.getScalarType() == MVT::i64 && | ||
Op.getOperand(0).getValueType().getScalarType() == MVT::i8 && | ||
LHS.getValueType() == RHS.getValueType() && | ||
LHS.getValueType().getScalarType() == MVT::i8 && | ||
"Unexpected PSADBW types"); | ||
|
||
// PSADBW - fills low 16 bits and zeros upper 48 bits of each i64 result. | ||
Known.Zero.setBitsFrom(16); | ||
computeKnownBitsForPSADBW(LHS, RHS, Known, DemandedElts, DAG, Depth); | ||
break; | ||
} | ||
case X86ISD::PCMPGT: | ||
|
@@ -37047,6 +37068,23 @@ void X86TargetLowering::computeKnownBitsForTargetNode(const SDValue Op, | |
} | ||
break; | ||
} | ||
case ISD::INTRINSIC_WO_CHAIN: { | ||
switch (Op->getConstantOperandVal(0)) { | ||
case Intrinsic::x86_sse2_psad_bw: | ||
case Intrinsic::x86_avx2_psad_bw: | ||
case Intrinsic::x86_avx512_psad_bw_512: { | ||
SDValue LHS = Op.getOperand(1); | ||
SDValue RHS = Op.getOperand(2); | ||
assert(VT.getScalarType() == MVT::i64 && | ||
LHS.getValueType() == RHS.getValueType() && | ||
LHS.getValueType().getScalarType() == MVT::i8 && | ||
"Unexpected PSADBW types"); | ||
computeKnownBitsForPSADBW(LHS, RHS, Known, DemandedElts, DAG, Depth); | ||
break; | ||
} | ||
} | ||
break; | ||
} | ||
} | ||
|
||
// Handle target shuffles. | ||
|
Uh oh!
There was an error while loading. Please reload this page.