@@ -435,6 +435,8 @@ class AArch64DAGToDAGISel : public SelectionDAGISel {
435435 bool trySelectCastFixedLengthToScalableVector (SDNode *N);
436436 bool trySelectCastScalableToFixedLengthVector (SDNode *N);
437437
438+ bool trySelectXAR (SDNode *N);
439+
438440// Include the pieces autogenerated from the target description.
439441#include " AArch64GenDAGISel.inc"
440442
@@ -4273,6 +4275,40 @@ bool AArch64DAGToDAGISel::trySelectCastScalableToFixedLengthVector(SDNode *N) {
42734275 return true ;
42744276}
42754277
4278+ bool AArch64DAGToDAGISel::trySelectXAR (SDNode *N) {
4279+ assert (N->getOpcode () == ISD::OR && " Expected OR instruction" );
4280+
4281+ SDValue N0 = N->getOperand (0 );
4282+ SDValue N1 = N->getOperand (1 );
4283+
4284+ if (N0->getOpcode () != AArch64ISD::VSHL ||
4285+ N1->getOpcode () != AArch64ISD::VLSHR)
4286+ return false ;
4287+
4288+ if (N0->getOperand (0 ) != N1->getOperand (0 ) ||
4289+ N1->getOperand (0 )->getOpcode () != ISD::XOR)
4290+ return false ;
4291+
4292+ SDValue XOR = N0.getOperand (0 );
4293+ SDValue R1 = XOR.getOperand (0 );
4294+ SDValue R2 = XOR.getOperand (1 );
4295+
4296+ unsigned HsAmt = N0.getConstantOperandVal (1 );
4297+ unsigned ShAmt = N1.getConstantOperandVal (1 );
4298+
4299+ SDLoc DL = SDLoc (N0.getOperand (1 ));
4300+ SDValue Imm = CurDAG->getTargetConstant (
4301+ ShAmt, DL, N0.getOperand (1 ).getValueType (), false );
4302+
4303+ if (ShAmt + HsAmt != 64 )
4304+ return false ;
4305+
4306+ SDValue Ops[] = {R1, R2, Imm};
4307+ CurDAG->SelectNodeTo (N, AArch64::XAR, N0.getValueType (), Ops);
4308+
4309+ return true ;
4310+ }
4311+
42764312void AArch64DAGToDAGISel::Select (SDNode *Node) {
42774313 // If we have a custom node, we already have selected!
42784314 if (Node->isMachineOpcode ()) {
@@ -4336,6 +4372,8 @@ void AArch64DAGToDAGISel::Select(SDNode *Node) {
43364372 case ISD::OR:
43374373 if (tryBitfieldInsertOp (Node))
43384374 return ;
4375+ if (Subtarget->hasSHA3 () && trySelectXAR (Node))
4376+ return ;
43394377 break ;
43404378
43414379 case ISD::EXTRACT_SUBVECTOR: {
0 commit comments