@@ -682,39 +682,32 @@ bool RISCVDAGToDAGISel::trySignedBitfieldInsertInMask(SDNode *Node) {
682
682
if (!Subtarget->hasVendorXqcibm ())
683
683
return false ;
684
684
685
- auto *N1C = dyn_cast<ConstantSDNode>(Node->getOperand (1 ));
686
- if (!N1C)
687
- return false ;
685
+ using namespace SDPatternMatch ;
688
686
689
- int32_t C1 = N1C->getSExtValue ();
690
- if (!isShiftedMask_32 (C1) || isInt<12 >(C1))
687
+ SDValue X;
688
+ APInt MaskImm;
689
+ if (!sd_match (Node, m_Or (m_OneUse (m_Value (X)), m_ConstInt (MaskImm))))
691
690
return false ;
692
691
693
- // INSBI will clobber the input register in N0. Bail out if we need a copy to
694
- // preserve this value.
695
- SDValue N0 = Node->getOperand (0 );
696
- if (!N0.hasOneUse ())
692
+ unsigned ShAmt, Width;
693
+ if (!MaskImm.isShiftedMask (ShAmt, Width) || MaskImm.isSignedIntN (12 ))
697
694
return false ;
698
695
699
- // If C1 is a shifted mask (but can't be formed as an ORI),
700
- // use a bitfield insert of -1.
701
- // Transform (or x, C1)
702
- // -> (qc.insbi x, -1, width, shift)
703
- const unsigned Leading = llvm::countl_zero ((uint32_t )C1);
704
- const unsigned Trailing = llvm::countr_zero ((uint32_t )C1);
705
- const unsigned Width = 32 - Leading - Trailing;
706
-
707
696
// If Zbs is enabled and it is a single bit set we can use BSETI which
708
697
// can be compressed to C_BSETI when Xqcibm in enabled.
709
698
if (Width == 1 && Subtarget->hasStdExtZbs ())
710
699
return false ;
711
700
701
+ // If C1 is a shifted mask (but can't be formed as an ORI),
702
+ // use a bitfield insert of -1.
703
+ // Transform (or x, C1)
704
+ // -> (qc.insbi x, -1, width, shift)
712
705
SDLoc DL (Node);
713
706
MVT VT = Node->getSimpleValueType (0 );
714
707
715
- SDValue Ops[] = {N0 , CurDAG->getSignedTargetConstant (-1 , DL, VT),
708
+ SDValue Ops[] = {X , CurDAG->getSignedTargetConstant (-1 , DL, VT),
716
709
CurDAG->getTargetConstant (Width, DL, VT),
717
- CurDAG->getTargetConstant (Trailing , DL, VT)};
710
+ CurDAG->getTargetConstant (ShAmt , DL, VT)};
718
711
SDNode *BitIns = CurDAG->getMachineNode (RISCV::QC_INSBI, DL, VT, Ops);
719
712
ReplaceNode (Node, BitIns);
720
713
return true ;
0 commit comments