@@ -2444,6 +2444,7 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
2444
2444
ISD::SRL,
2445
2445
ISD::OR,
2446
2446
ISD::AND,
2447
+ ISD::BITREVERSE,
2447
2448
ISD::ADD,
2448
2449
ISD::FADD,
2449
2450
ISD::FSUB,
@@ -51835,6 +51836,33 @@ static SDValue combineXor(SDNode *N, SelectionDAG &DAG,
51835
51836
return combineFneg(N, DAG, DCI, Subtarget);
51836
51837
}
51837
51838
51839
+ static SDValue combineBITREVERSE(SDNode *N, SelectionDAG &DAG,
51840
+ TargetLowering::DAGCombinerInfo &DCI,
51841
+ const X86Subtarget &Subtarget) {
51842
+ SDValue N0 = N->getOperand(0);
51843
+ EVT VT = N->getValueType(0);
51844
+
51845
+ // Convert a (iX bitreverse(bitcast(vXi1 X))) -> (iX bitcast(shuffle(X)))
51846
+ if (VT.isInteger() && N0.getOpcode() == ISD::BITCAST && N0.hasOneUse()) {
51847
+ SDValue Src = N0.getOperand(0);
51848
+ EVT SrcVT = Src.getValueType();
51849
+ if (SrcVT.isVector() && SrcVT.getScalarType() == MVT::i1 &&
51850
+ (DCI.isBeforeLegalize() ||
51851
+ DAG.getTargetLoweringInfo().isTypeLegal(SrcVT)) &&
51852
+ Subtarget.hasSSSE3()) {
51853
+ unsigned NumElts = SrcVT.getVectorNumElements();
51854
+ SmallVector<int, 32> ReverseMask(NumElts);
51855
+ for (unsigned I = 0; I != NumElts; ++I)
51856
+ ReverseMask[I] = (NumElts - 1) - I;
51857
+ SDValue Rev =
51858
+ DAG.getVectorShuffle(SrcVT, SDLoc(N), Src, Src, ReverseMask);
51859
+ return DAG.getBitcast(VT, Rev);
51860
+ }
51861
+ }
51862
+
51863
+ return SDValue();
51864
+ }
51865
+
51838
51866
static SDValue combineBEXTR(SDNode *N, SelectionDAG &DAG,
51839
51867
TargetLowering::DAGCombinerInfo &DCI,
51840
51868
const X86Subtarget &Subtarget) {
@@ -56124,6 +56152,7 @@ SDValue X86TargetLowering::PerformDAGCombine(SDNode *N,
56124
56152
case ISD::AND: return combineAnd(N, DAG, DCI, Subtarget);
56125
56153
case ISD::OR: return combineOr(N, DAG, DCI, Subtarget);
56126
56154
case ISD::XOR: return combineXor(N, DAG, DCI, Subtarget);
56155
+ case ISD::BITREVERSE: return combineBITREVERSE(N, DAG, DCI, Subtarget);
56127
56156
case X86ISD::BEXTR:
56128
56157
case X86ISD::BEXTRI: return combineBEXTR(N, DAG, DCI, Subtarget);
56129
56158
case ISD::LOAD: return combineLoad(N, DAG, DCI, Subtarget);
0 commit comments