diff --git a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp --- a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp @@ -3291,14 +3291,21 @@ const RISCV::RISCVMaskedPseudoInfo *Info = RISCV::lookupMaskedIntrinsicByUnmaskedTA(TrueOpc); if (!Info && HasTiedDest) { - Info = RISCV::getMaskedPseudoInfo(TrueOpc); - IsMasked = true; + Info = RISCV::lookupMaskedIntrinsicByUnmaskedTU(TrueOpc); + if (Info && !isImplicitDef(True->getOperand(0))) + // We only support the TA form of the _TU pseudos + return false; + // FIXME: Expect undef operand here? + if (!Info) { + Info = RISCV::getMaskedPseudoInfo(TrueOpc); + IsMasked = true; + } } if (!Info) return false; - if (HasTiedDest) { + if (HasTiedDest && !isImplicitDef(True->getOperand(0))) { // The vmerge instruction must be TU. // FIXME: This could be relaxed, but we need to handle the policy for the // resulting op correctly. @@ -3387,14 +3394,14 @@ SmallVector Ops; if (IsMasked) { - Ops.append(True->op_begin(), True->op_begin() + TrueVLIndex); + Ops.push_back(False); + Ops.append(True->op_begin() + 1, True->op_begin() + TrueVLIndex); Ops.append({VL, /* SEW */ True.getOperand(TrueVLIndex + 1)}); Ops.push_back(PolicyOp); Ops.append(True->op_begin() + TrueVLIndex + 3, True->op_end()); } else { - if (!HasTiedDest) - Ops.push_back(False); - Ops.append(True->op_begin(), True->op_begin() + TrueVLIndex); + Ops.push_back(False); + Ops.append(True->op_begin() + HasTiedDest, True->op_begin() + TrueVLIndex); Ops.append({Mask, VL, /* SEW */ True.getOperand(TrueVLIndex + 1)}); Ops.push_back(PolicyOp); diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td b/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td @@ -506,6 +506,11 @@ let Key = ["UnmaskedPseudo"]; } +def lookupMaskedIntrinsicByUnmaskedTU : SearchIndex { + let Table = RISCVMaskedPseudosTable; + let Key = ["UnmaskedTUPseudo"]; +} + def RISCVVLETable : GenericTable { let FilterClass = "RISCVVLE"; let CppTypeName = "VLEPseudo"; @@ -4306,8 +4311,8 @@ def : Pat<(vti.Vector (!cast(intrinsic) (vti.Vector undef), VLOpFrag)), - (!cast(instruction#"_V_" # vti.LMul.MX) - GPR:$vl, vti.Log2SEW)>; + (!cast(instruction#"_V_" # vti.LMul.MX # "_TU") + (vti.Vector (IMPLICIT_DEF)), GPR:$vl, vti.Log2SEW)>; def : Pat<(vti.Vector (!cast(intrinsic) (vti.Vector vti.RegClass:$merge), VLOpFrag)),