Skip to content

Commit

Permalink
X86: improve (V)PMADDWD detection
Browse files Browse the repository at this point in the history
In function combineMulToPMADDWD, if 17 bit are sign bits,
not just zero bits, the optimization can be applied sometimes.
For now, detect and replace SRA pairs with SRL.
  • Loading branch information
Nekotekina committed May 13, 2021
1 parent 8ed5423 commit a7dd06b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41659,6 +41659,22 @@ static SDValue combineMulToPMADDWD(SDNode *N, SelectionDAG &DAG,
return SDValue();

APInt Mask17 = APInt::getHighBitsSet(32, 17);
if (N0.getOpcode() == ISD::SRA && N1.getOpcode() == ISD::SRA) {
// If both arguments are sign-extended, try to replace sign extends
// with zero extends, which should qualify for the optimization.
// Otherwise just fallback to zero-extension check.
if (isa<ConstantSDNode>(N0.getOperand(1).getOperand(0)) &&
N0.getOperand(1).getConstantOperandVal(0) == 16 &&
isa<ConstantSDNode>(N1.getOperand(1).getOperand(0)) &&
N1.getOperand(1).getConstantOperandVal(0) == 16) {
// Nullify mask to pass the following check
Mask17 = 0;
N0 = DAG.getNode(ISD::SRL, N0.getNode(), VT, N0.getOperand(0),
N0.getOperand(1));
N1 = DAG.getNode(ISD::SRL, N1.getNode(), VT, N1.getOperand(0),
N1.getOperand(1));
}
}
if (!DAG.MaskedValueIsZero(N1, Mask17) ||
!DAG.MaskedValueIsZero(N0, Mask17))
return SDValue();
Expand Down

0 comments on commit a7dd06b

Please sign in to comment.