//===----------- VVPInstrPatternsVec.td - VVP_* SDNode patterns -----------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file describes how VVP_* SDNodes are lowered to machine instructions. // //===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===// // // VVP SDNode definitions. // //===----------------------------------------------------------------------===// include "VVPInstrInfo.td" multiclass VectorStore { // Unmasked (imm stride). def : Pat<(vvp_store DataVT:$val, PtrVT:$addr, (i64 simm7:$stride), (MaskVT true_mask), i32:$avl), (!cast(STNoMask#"irvl") (LO7 $stride), $addr, $val, $avl)>; // Unmasked. def : Pat<(vvp_store DataVT:$val, PtrVT:$addr, i64:$stride, (MaskVT true_mask), i32:$avl), (!cast(STNoMask#"rrvl") $stride, $addr, $val, $avl)>; // Masked (imm stride). def : Pat<(vvp_store DataVT:$val, PtrVT:$addr, (i64 simm7:$stride), MaskVT:$mask, i32:$avl), (!cast(STWithMask#"irvml") (LO7 $stride), $addr, $val, $mask, $avl)>; // Masked. def : Pat<(vvp_store DataVT:$val, PtrVT:$addr, i64:$stride, MaskVT:$mask, i32:$avl), (!cast(STWithMask#"rrvml") $stride, $addr, $val, $mask, $avl)>; } defm : VectorStore; defm : VectorStore; defm : VectorStore; defm : VectorStore; multiclass VectorLoad { // Unmasked (imm stride). def : Pat<(DataVT (vvp_load PtrVT:$addr, (i64 simm7:$stride), (MaskVT true_mask), i32:$avl)), (!cast(LDNoMask#"irl") (LO7 $stride), $addr, $avl)>; // Unmasked. def : Pat<(DataVT (vvp_load PtrVT:$addr, i64:$stride, (MaskVT true_mask), i32:$avl)), (!cast(LDNoMask#"rrl") $stride, PtrVT:$addr, $avl)>; // Masked (imm stride). def : Pat<(DataVT (vvp_load PtrVT:$addr, (i64 simm7:$stride), MaskVT:$mask, i32:$avl)), (!cast(GTWithMask#"vizml") (VADDULrvml $addr, (VMULULivml (LO7 $stride), (VSEQl $avl), $mask, $avl), $mask, $avl), 0, 0, $mask, $avl)>; // Masked. def : Pat<(DataVT (vvp_load PtrVT:$addr, i64:$stride, MaskVT:$mask, i32:$avl)), (!cast(GTWithMask#"vizml") (VADDULrvml $addr, (VMULULrvml $stride, (VSEQl $avl), $mask, $avl), $mask, $avl), 0, 0, $mask, $avl)>; } defm : VectorLoad; defm : VectorLoad; defm : VectorLoad; defm : VectorLoad; // Vector Gather and scatter multiclass VectorGather { // Unmasked. def : Pat<(DataVT (vvp_gather PtrVT:$addr, (MaskVT true_mask), i32:$avl)), (!cast(GTPrefix#"vizl") $addr, 0, 0, $avl)>; // Masked. def : Pat<(DataVT (vvp_gather PtrVT:$addr, MaskVT:$mask, i32:$avl)), (!cast(GTPrefix#"vizml") $addr, 0, 0, $mask, $avl)>; } defm : VectorGather; defm : VectorGather; defm : VectorGather; defm : VectorGather; multiclass VectorScatter { // Unmasked. def : Pat<(vvp_scatter DataVT:$data, PtrVT:$addr, (MaskVT true_mask), i32:$avl), (!cast(SCPrefix#"vizvl") $addr, 0, 0, $data, $avl)>; // Masked. def : Pat<(vvp_scatter DataVT:$data, PtrVT:$addr, MaskVT:$mask, i32:$avl), (!cast(SCPrefix#"vizvml") $addr, 0, 0, $data, $mask, $avl)>; } defm : VectorScatter; defm : VectorScatter; defm : VectorScatter; defm : VectorScatter; /// FNEG { // Directly modify the sign bit to flip the sign. // Set sign bits in a pack of <2 x f32>. def packed_fneg_imm : OutPatFrag<(ins ), (i64 (SLLri (i64 (ORim 1, (i32 32))), 31))>; multiclass FNeg { // Masked with select. def : Pat<(vvp_select (vvp_fneg DataVT:$vx, (v256i1 srcvalue), (i32 srcvalue)), DataVT:$vfalse, v256i1:$mask, i32:$avl), (VXORmvml_v (i32 1), $vx, $mask, $avl, $vfalse)>; // Unmasked. def : Pat<(vvp_fneg DataVT:$vx, (v256i1 true_mask), i32:$avl), (VXORmvl (i32 1), $vx, $avl)>; // Masked. def : Pat<(vvp_fneg DataVT:$vx, v256i1:$mask, i32:$avl), (VXORmvml (i32 1), $vx, $mask, $avl)>; } defm: FNeg; defm: FNeg; ///// Packed FNeg ///// // Masked with select. def : Pat<(vvp_select (vvp_fneg v512f32:$vx, (v512i1 srcvalue), (i32 srcvalue)), v512f32:$vfalse, v512i1:$mask, i32:$avl), (v512f32 (PVXORrvml_v (packed_fneg_imm ), $vx, $mask, $avl, $vfalse))>; // Unmasked. def : Pat<(vvp_fneg v512f32:$vx, (v512i1 true_mask), i32:$avl), (v512f32 (PVXORrvl (packed_fneg_imm ), $vx, $avl))>; // Masked. def : Pat<(vvp_fneg v512f32:$vx, v512i1:$mask, i32:$avl), (v512f32 (PVXORrvml (packed_fneg_imm ), $vx, $mask, $avl))>; /// } FNEG multiclass Binary_rv { // Masked with passthru, broadcast. def : Pat<(vvp_select (OpNode (any_broadcast ScalarVT:$sx), DataVT:$vy, (MaskVT srcvalue), (i32 srcvalue)), DataVT:$vfalse, MaskVT:$mask, i32:$pivot), (!cast(OpBaseName#"rvml_v") ScalarVT:$sx, $vy, $mask, $pivot, $vfalse)>; // Unmasked, broadcast. def : Pat<(OpNode (any_broadcast ScalarVT:$sx), DataVT:$vy, (MaskVT true_mask), i32:$avl), (!cast(OpBaseName#"rvl") ScalarVT:$sx, $vy, $avl)>; // Masked, broadcast. def : Pat<(OpNode (any_broadcast ScalarVT:$sx), DataVT:$vy, MaskVT:$mask, i32:$avl), (!cast(OpBaseName#"rvml") ScalarVT:$sx, $vy, $mask, $avl)>; } multiclass Binary_vr { // Masked with passthru, broadcast. def : Pat<(vvp_select (OpNode DataVT:$vx, (any_broadcast ScalarVT:$sy), (MaskVT srcvalue), (i32 srcvalue)), DataVT:$vfalse, MaskVT:$mask, i32:$pivot), (!cast(OpBaseName#"vrml_v") $vx, ScalarVT:$sy, $mask, $pivot, $vfalse)>; // Unmasked, broadcast. def : Pat<(OpNode DataVT:$vx, (any_broadcast ScalarVT:$sy), (MaskVT true_mask), i32:$avl), (!cast(OpBaseName#"vrl") $vx, ScalarVT:$sy, $avl)>; // Masked, broadcast. def : Pat<(OpNode DataVT:$vx, (any_broadcast ScalarVT:$sy), MaskVT:$mask, i32:$avl), (!cast(OpBaseName#"vrml") $vx, ScalarVT:$sy, $mask, $avl)>; } multiclass Binary_vv { // Masked with passthru, broadcast. def : Pat<(vvp_select (OpNode DataVT:$vx, DataVT:$vy, (MaskVT srcvalue), (i32 srcvalue)), DataVT:$vfalse, MaskVT:$mask, i32:$pivot), (!cast(OpBaseName#"vvml_v") $vx, $vy, $mask, $pivot, $vfalse)>; // Masked with select. // TODO // Unmasked. def : Pat<(OpNode DataVT:$vx, DataVT:$vy, (MaskVT true_mask), i32:$avl), (!cast(OpBaseName#"vvl") $vx, $vy, $avl)>; // Masked. def : Pat<(OpNode DataVT:$vx, DataVT:$vy, MaskVT:$mask, i32:$avl), (!cast(OpBaseName#"vvml") $vx, $vy, $mask, $avl)>; } multiclass Binary_rv_vv< SDPatternOperator OpNode, ValueType ScalarVT, ValueType DataVT, ValueType MaskVT, string OpBaseName> { defm : Binary_rv; defm : Binary_vv; } multiclass Binary_vr_vv< SDPatternOperator OpNode, ValueType ScalarVT, ValueType DataVT, ValueType MaskVT, string OpBaseName> { defm : Binary_vr; defm : Binary_vv; } multiclass Binary_rv_vr_vv< SDPatternOperator OpNode, ValueType ScalarVT, ValueType DataVT, ValueType MaskVT, string OpBaseName> { defm : Binary_rv; defm : Binary_vr_vv; } // Expand both 64bit and 32 bit variant (256 elements) multiclass Binary_rv_vv_ShortLong< SDPatternOperator OpNode, ValueType LongScalarVT, ValueType LongDataVT, string LongOpBaseName, ValueType ShortScalarVT, ValueType ShortDataVT, string ShortOpBaseName> { defm : Binary_rv_vv; defm : Binary_rv_vv; } multiclass Binary_vr_vv_ShortLong< SDPatternOperator OpNode, ValueType LongScalarVT, ValueType LongDataVT, string LongOpBaseName, ValueType ShortScalarVT, ValueType ShortDataVT, string ShortOpBaseName> { defm : Binary_vr_vv; defm : Binary_vr_vv; } multiclass Binary_rv_vr_vv_ShortLong< SDPatternOperator OpNode, ValueType LongScalarVT, ValueType LongDataVT, string LongOpBaseName, ValueType ShortScalarVT, ValueType ShortDataVT, string ShortOpBaseName> { defm : Binary_rv_vr_vv; defm : Binary_rv_vr_vv; } defm : Binary_rv_vv_ShortLong; defm : Binary_rv_vv_ShortLong; defm : Binary_rv_vv_ShortLong; defm : Binary_rv_vr_vv_ShortLong; defm : Binary_rv_vr_vv_ShortLong; defm : Binary_rv_vv_ShortLong; defm : Binary_rv_vv_ShortLong; defm : Binary_rv_vv_ShortLong; defm : Binary_vr_vv_ShortLong; defm : Binary_vr_vv_ShortLong; defm : Binary_vr_vv_ShortLong; defm : Binary_rv_vv_ShortLong; defm : Binary_rv_vv_ShortLong; defm : Binary_rv_vv_ShortLong; defm : Binary_rv_vr_vv_ShortLong; defm : Binary_rv_vv; defm : Binary_rv_vv; defm : Binary_rv_vv; defm : Binary_rv_vv; defm : Binary_rv_vv; defm : Binary_vr_vv; defm : Binary_vr_vv; defm : Binary_vr_vv; defm : Binary_rv_vv; defm : Binary_rv_vv; defm : Binary_rv_vv; multiclass Ternary_vvv< SDPatternOperator OpNode, ValueType DataVT, ValueType MaskVT, string OpBaseName> { // Masked with passthru. def : Pat<(vvp_select (OpNode DataVT:$vx, DataVT:$vy, DataVT:$vz, (MaskVT srcvalue), (i32 srcvalue)), DataVT:$vfalse, MaskVT:$mask, i32:$avl), (!cast(OpBaseName#"vvvml_v") $vx, $vy, $vz, $mask, $avl, $vfalse)>; // Unmasked. def : Pat<(OpNode DataVT:$vx, DataVT:$vy, DataVT:$vz, (MaskVT true_mask), i32:$avl), (!cast(OpBaseName#"vvvl") $vx, $vy, $vz, $avl)>; // Masked. def : Pat<(OpNode DataVT:$vx, DataVT:$vy, DataVT:$vz, MaskVT:$mask, i32:$avl), (!cast(OpBaseName#"vvvml") $vx, $vy, $vz, $mask, $avl)>; } multiclass Ternary_rvv< SDPatternOperator OpNode, ValueType ScalarVT, ValueType DataVT, ValueType MaskVT, string OpBaseName> { // Masked with passthru, broadcast first. def : Pat<(vvp_select (OpNode (any_broadcast ScalarVT:$sx), DataVT:$vy, DataVT:$vz, (MaskVT srcvalue), (i32 srcvalue)), DataVT:$vfalse, MaskVT:$mask, i32:$avl), (!cast(OpBaseName#"rvvml_v") $sx, $vy, $vz, $mask, $avl, $vfalse)>; // Unmasked, broadcast first. def : Pat<(OpNode (any_broadcast ScalarVT:$sx), DataVT:$vy, DataVT:$vz, (MaskVT true_mask), i32:$avl), (!cast(OpBaseName#"rvvl") $sx, $vy, $vz, $avl)>; // Masked, broadcast first. def : Pat<(OpNode (any_broadcast ScalarVT:$sx), DataVT:$vy, DataVT:$vz, MaskVT:$mask, i32:$avl), (!cast(OpBaseName#"rvvml") $sx, $vy, $vz, $mask, $avl)>; } multiclass Ternary_vrv< SDPatternOperator OpNode, ValueType ScalarVT, ValueType DataVT, ValueType MaskVT, string OpBaseName> { // Masked with passthru, broadcast second. def : Pat<(vvp_select (OpNode DataVT:$vx, (any_broadcast ScalarVT:$sy), DataVT:$vz, (MaskVT srcvalue), (i32 srcvalue)), DataVT:$vfalse, MaskVT:$mask, i32:$avl), (!cast(OpBaseName#"vrvml_v") $vx, $sy, $vz, $mask, $avl, $vfalse)>; // Unmasked, broadcast second. def : Pat<(OpNode DataVT:$vx, (any_broadcast ScalarVT:$sy), DataVT:$vz, (MaskVT true_mask), i32:$avl), (!cast(OpBaseName#"vrvl") $vx, $sy, $vz, $avl)>; // Masked, broadcast second. def : Pat<(OpNode DataVT:$vx, (any_broadcast ScalarVT:$sy), DataVT:$vz, MaskVT:$mask, i32:$avl), (!cast(OpBaseName#"vrvml") $vx, $sy, $vz, $mask, $avl)>; } multiclass Ternary_rvv_vrv_vvv< SDPatternOperator OpNode, ValueType ScalarVT, ValueType DataVT, ValueType MaskVT, string OpBaseName> { defm : Ternary_rvv; defm : Ternary_vrv; defm : Ternary_vvv; } // Expand both 64bit and 32 bit variant (256 elements) multiclass Ternary_ShortLong< SDPatternOperator OpNode, ValueType LongScalarVT, ValueType LongDataVT, string LongOpBaseName, ValueType ShortScalarVT, ValueType ShortDataVT, string ShortOpBaseName> { defm : Ternary_rvv_vrv_vvv; defm : Ternary_rvv_vrv_vvv; } defm : Ternary_ShortLong; defm : Ternary_rvv_vrv_vvv; multiclass Merge_mvv< SDPatternOperator OpNode, ValueType DataVT, ValueType MaskVT, string OpBaseName> { // Masked. def : Pat<(OpNode DataVT:$vtrue, DataVT:$vfalse, MaskVT:$vm, i32:$avl), (!cast(OpBaseName#"vvml_v") $vfalse, $vtrue, $vm, $avl, $vfalse)>; } multiclass Merge_mvv_ShortLong< SDPatternOperator OpNode, ValueType LongDataVT, ValueType ShortDataVT, string OpBaseName> { defm : Merge_mvv; defm : Merge_mvv; } defm : Merge_mvv_ShortLong; defm : Merge_mvv_ShortLong; multiclass Set_CC { // Unmasked. def : Pat<(v256i1 (vvp_setcc DataVT:$LHS, DataVT:$RHS, CCMatcher:$cond, (v256i1 true_mask), i32:$vl)), (!cast(FmkBaseName#"vl") (CCConv $cond), (!cast(CmpBaseName#"vvl") $LHS, $RHS, $vl), $vl)>; // Masked. def : Pat<(v256i1 (vvp_setcc DataVT:$LHS, DataVT:$RHS, CCMatcher:$cond, v256i1:$vm, i32:$vl)), (!cast(FmkBaseName#"vml") (CCConv $cond), (!cast(CmpBaseName#"vvl") $LHS, $RHS, $vl), $vm, $vl)>; } defm : Set_CC; defm : Set_CC; defm : Set_CC; defm : Set_CC; defm : Set_CC; defm : Set_CC; multiclass Reduce_GenericInt { // Unmasked. def : Pat <(ResVT (!cast("vvp_reduce_"#VVPRedOp) VectorVT:$vx, (v256i1 true_mask), i32:$vl)), (COPY_TO_REGCLASS (!cast("LVSvi") (!cast(RedInstName#"vl") $vx, $vl), 0), ResRC)>; // Masked. def : Pat <(ResVT (!cast("vvp_reduce_"#VVPRedOp) VectorVT:$vx, v256i1:$vm, i32:$vl)), (COPY_TO_REGCLASS (!cast("LVSvi") (!cast(RedInstName#"vml") $vx, $vm, $vl), 0), ResRC)>; } multiclass IntReduce_ShortLong { defm: Reduce_GenericInt; defm: Reduce_GenericInt; defm: Reduce_GenericInt; defm: Reduce_GenericInt; defm: Reduce_GenericInt; } defm: IntReduce_ShortLong; defm: IntReduce_ShortLong;