@@ -721,8 +721,6 @@ multiclass RVVUnitStridedSegLoadTuple<string op> {
721721 NF = nf,
722722 ManualCodegen = [{
723723 {
724- SmallVector<llvm::Value*, 6> Operands;
725-
726724 bool NoPassthru =
727725 (IsMasked && (PolicyAttrs & RVV_VTA) && (PolicyAttrs & RVV_VMA)) |
728726 (!IsMasked && (PolicyAttrs & RVV_VTA));
@@ -733,24 +731,18 @@ multiclass RVVUnitStridedSegLoadTuple<string op> {
733731 else
734732 IntrinsicTypes = {ResultType, Ops[Offset]->getType(), Ops.back()->getType()};
735733
736- if (NoPassthru) { // Push poison into passthru
737- Operands.push_back(llvm::PoisonValue::get(ResultType));
738- } else { // Push intrinsics operands into passthru
739- llvm::Value *PassthruOperand = IsMasked ? Ops[1] : Ops[0];
740- Operands.push_back(PassthruOperand);
741- }
742-
743- Operands.push_back(Ops[Offset]); // Ptr
744734 if (IsMasked)
745- Operands.push_back(Ops[0]);
746- Operands.push_back(Ops[Offset + 1]); // VL
735+ std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end() - 1);
736+ if (NoPassthru)
737+ Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
738+
747739 if (IsMasked)
748- Operands .push_back(ConstantInt::get(Ops.back()->getType(), PolicyAttrs));
749- Operands .push_back(ConstantInt::get(Ops.back()->getType(), SegInstSEW));
740+ Ops .push_back(ConstantInt::get(Ops.back()->getType(), PolicyAttrs));
741+ Ops .push_back(ConstantInt::get(Ops.back()->getType(), SegInstSEW));
750742
751743 llvm::Function *F = CGM.getIntrinsic(ID, IntrinsicTypes);
752744
753- llvm::Value *LoadValue = Builder.CreateCall(F, Operands , "");
745+ llvm::Value *LoadValue = Builder.CreateCall(F, Ops , "");
754746 if (ReturnValue.isNull())
755747 return LoadValue;
756748 else
@@ -787,26 +779,24 @@ multiclass RVVUnitStridedSegStoreTuple<string op> {
787779 {
788780 // Masked
789781 // Builtin: (mask, ptr, v_tuple, vl)
790- // Intrinsic: (tuple, ptr, mask, vl)
782+ // Intrinsic: (tuple, ptr, mask, vl, SegInstSEW )
791783 // Unmasked
792784 // Builtin: (ptr, v_tuple, vl)
793- // Intrinsic: (tuple, ptr, vl)
794- unsigned Offset = IsMasked ? 1 : 0;
785+ // Intrinsic: (tuple, ptr, vl, SegInstSEW)
795786
796- SmallVector<llvm::Value*, 5> Operands;
797- Operands.push_back(Ops[Offset + 1]); // tuple
798- Operands.push_back(Ops[Offset]); // Ptr
799787 if (IsMasked)
800- Operands.push_back(Ops[0]);
801- Operands.push_back(Ops[Offset + 2]); // VL
802- Operands.push_back(ConstantInt::get(Ops.back()->getType(), SegInstSEW));
788+ std::swap(Ops[0], Ops[2]);
789+ else
790+ std::swap(Ops[0], Ops[1]);
791+
792+ Ops.push_back(ConstantInt::get(Ops.back()->getType(), SegInstSEW));
803793
804794 if (IsMasked)
805- IntrinsicTypes = {Operands [0]->getType(), Ops[Offset ]->getType(), Ops[0 ]->getType(), Operands.back() ->getType()};
795+ IntrinsicTypes = {Ops [0]->getType(), Ops[1 ]->getType(), Ops[2 ]->getType(), Ops[3] ->getType()};
806796 else
807- IntrinsicTypes = {Operands [0]->getType(), Ops[Offset ]->getType(), Operands.back() ->getType()};
808- llvm::Function *F = CGM.getIntrinsic(ID, IntrinsicTypes);
809- return Builder.CreateCall(F, Operands, "") ;
797+ IntrinsicTypes = {Ops [0]->getType(), Ops[1 ]->getType(), Ops[2] ->getType()};
798+
799+ break ;
810800 }
811801 }] in {
812802 defvar T = "(Tuple:" # nf # ")";
@@ -836,8 +826,6 @@ multiclass RVVUnitStridedSegLoadFFTuple<string op> {
836826 NF = nf,
837827 ManualCodegen = [{
838828 {
839- SmallVector<llvm::Value*, 6> Operands;
840-
841829 bool NoPassthru =
842830 (IsMasked && (PolicyAttrs & RVV_VTA) && (PolicyAttrs & RVV_VMA)) |
843831 (!IsMasked && (PolicyAttrs & RVV_VTA));
@@ -848,24 +836,21 @@ multiclass RVVUnitStridedSegLoadFFTuple<string op> {
848836 else
849837 IntrinsicTypes = {ResultType, Ops.back()->getType(), Ops[Offset]->getType()};
850838
851- if (NoPassthru) { // Push poison into passthru
852- Operands.push_back(llvm::PoisonValue::get(ResultType));
853- } else { // Push intrinsics operands into passthru
854- llvm::Value *PassthruOperand = IsMasked ? Ops[1] : Ops[0];
855- Operands.push_back(PassthruOperand);
856- }
857-
858- Operands.push_back(Ops[Offset]); // Ptr
859839 if (IsMasked)
860- Operands.push_back(Ops[0]);
861- Operands.push_back(Ops[Offset + 2]); // vl
840+ std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end() - 1);
841+ if (NoPassthru)
842+ Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
843+
862844 if (IsMasked)
863- Operands.push_back(ConstantInt::get(Ops.back()->getType(), PolicyAttrs));
864- Operands.push_back(ConstantInt::get(Ops.back()->getType(), SegInstSEW));
845+ Ops.push_back(ConstantInt::get(Ops.back()->getType(), PolicyAttrs));
846+ Ops.push_back(ConstantInt::get(Ops.back()->getType(), SegInstSEW));
847+
848+ Value *NewVL = Ops[2];
849+ Ops.erase(Ops.begin() + 2);
865850
866851 llvm::Function *F = CGM.getIntrinsic(ID, IntrinsicTypes);
867852
868- llvm::Value *LoadValue = Builder.CreateCall(F, Operands , "");
853+ llvm::Value *LoadValue = Builder.CreateCall(F, Ops , "");
869854 // Get alignment from the new vl operand
870855 clang::CharUnits Align =
871856 CGM.getNaturalPointeeTypeAlignment(E->getArg(Offset + 1)->getType());
@@ -874,7 +859,7 @@ multiclass RVVUnitStridedSegLoadFFTuple<string op> {
874859
875860 // Store new_vl
876861 llvm::Value *V = Builder.CreateExtractValue(LoadValue, 1);
877- Builder.CreateStore(V, Address(Ops[Offset + 1] , V->getType(), Align));
862+ Builder.CreateStore(V, Address(NewVL , V->getType(), Align));
878863
879864 if (ReturnValue.isNull())
880865 return ReturnTuple;
@@ -909,8 +894,6 @@ multiclass RVVStridedSegLoadTuple<string op> {
909894 NF = nf,
910895 ManualCodegen = [{
911896 {
912- SmallVector<llvm::Value*, 7> Operands;
913-
914897 bool NoPassthru =
915898 (IsMasked && (PolicyAttrs & RVV_VTA) && (PolicyAttrs & RVV_VMA)) |
916899 (!IsMasked && (PolicyAttrs & RVV_VTA));
@@ -921,24 +904,17 @@ multiclass RVVStridedSegLoadTuple<string op> {
921904 else
922905 IntrinsicTypes = {ResultType, Ops[Offset]->getType(), Ops.back()->getType()};
923906
924- if (NoPassthru) { // Push poison into passthru
925- Operands.push_back(llvm::PoisonValue::get(ResultType));
926- } else { // Push intrinsics operands into passthru
927- llvm::Value *PassthruOperand = IsMasked ? Ops[1] : Ops[0];
928- Operands.push_back(PassthruOperand);
929- }
930-
931- Operands.push_back(Ops[Offset]); // Ptr
932- Operands.push_back(Ops[Offset + 1]); // Stride
933907 if (IsMasked)
934- Operands.push_back(Ops[0]);
935- Operands.push_back(Ops[Offset + 2]); // VL
908+ std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end() - 1);
909+ if (NoPassthru)
910+ Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
911+
936912 if (IsMasked)
937- Operands .push_back(ConstantInt::get(Ops.back()->getType(), PolicyAttrs));
938- Operands .push_back(ConstantInt::get(Ops.back()->getType(), SegInstSEW));
913+ Ops .push_back(ConstantInt::get(Ops.back()->getType(), PolicyAttrs));
914+ Ops .push_back(ConstantInt::get(Ops.back()->getType(), SegInstSEW));
939915
940916 llvm::Function *F = CGM.getIntrinsic(ID, IntrinsicTypes);
941- llvm::Value *LoadValue = Builder.CreateCall(F, Operands , "");
917+ llvm::Value *LoadValue = Builder.CreateCall(F, Ops , "");
942918
943919 if (ReturnValue.isNull())
944920 return LoadValue;
@@ -977,27 +953,23 @@ multiclass RVVStridedSegStoreTuple<string op> {
977953 {
978954 // Masked
979955 // Builtin: (mask, ptr, stride, v_tuple, vl)
980- // Intrinsic: (tuple, ptr, stride, mask, vl)
956+ // Intrinsic: (tuple, ptr, stride, mask, vl, SegInstSEW )
981957 // Unmasked
982958 // Builtin: (ptr, stride, v_tuple, vl)
983- // Intrinsic: (tuple, ptr, stride, vl)
984- unsigned Offset = IsMasked ? 1 : 0;
959+ // Intrinsic: (tuple, ptr, stride, vl, SegInstSEW)
985960
986- SmallVector<llvm::Value*, 6> Operands;
987- Operands.push_back(Ops[Offset + 2]); // tuple
988- Operands.push_back(Ops[Offset]); // Ptr
989- Operands.push_back(Ops[Offset + 1]); // Stride
990961 if (IsMasked)
991- Operands.push_back(Ops[0]);
992- Operands.push_back(Ops[Offset + 3]); // VL
993- Operands.push_back(ConstantInt::get(Ops.back()->getType(), SegInstSEW));
962+ std::swap(Ops[0], Ops[3]);
963+ else
964+ std::rotate(Ops.begin(), Ops.begin() + 2, Ops.begin() + 3);
965+
966+ Ops.push_back(ConstantInt::get(Ops.back()->getType(), SegInstSEW));
994967
995968 if (IsMasked)
996- IntrinsicTypes = {Operands [0]->getType(), Operands [1]->getType(), Operands.back() ->getType(), Ops[0 ]->getType()};
969+ IntrinsicTypes = {Ops [0]->getType(), Ops [1]->getType(), Ops[4] ->getType(), Ops[3 ]->getType()};
997970 else
998- IntrinsicTypes = {Operands[0]->getType(), Operands[1]->getType(), Operands.back()->getType()};
999- llvm::Function *F = CGM.getIntrinsic(ID, IntrinsicTypes);
1000- return Builder.CreateCall(F, Operands, "");
971+ IntrinsicTypes = {Ops[0]->getType(), Ops[1]->getType(), Ops[3]->getType()};
972+ break;
1001973 }
1002974 }] in {
1003975 defvar T = "(Tuple:" # nf # ")";
@@ -1022,40 +994,30 @@ multiclass RVVIndexedSegLoadTuple<string op> {
1022994 NF = nf,
1023995 ManualCodegen = [{
1024996 {
1025- SmallVector<llvm::Value*, 7> Operands;
1026-
1027997 bool NoPassthru =
1028998 (IsMasked && (PolicyAttrs & RVV_VTA) && (PolicyAttrs & RVV_VMA)) |
1029999 (!IsMasked && (PolicyAttrs & RVV_VTA));
1030- unsigned Offset = IsMasked ? NoPassthru ? 1 : 2 : NoPassthru ? 0 : 1;
10311000
1032- if (NoPassthru) { // Push poison into passthru
1033- Operands.push_back(llvm::PoisonValue::get(ResultType));
1034- } else { // Push intrinsics operands into passthru
1035- llvm::Value *PassthruOperand = IsMasked ? Ops[1] : Ops[0];
1036- Operands.push_back(PassthruOperand);
1037- }
1038-
1039- Operands.push_back(Ops[Offset]); // Ptr
1040- Operands.push_back(Ops[Offset + 1]); // Idx
10411001 if (IsMasked)
1042- Operands.push_back(Ops[0]);
1043- Operands.push_back(Ops[Offset + 2]); // VL
1002+ std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end() - 1);
1003+ if (NoPassthru)
1004+ Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
1005+
10441006 if (IsMasked)
1045- Operands .push_back(ConstantInt::get(Ops.back()->getType(), PolicyAttrs));
1046- Operands .push_back(ConstantInt::get(Ops.back()->getType(), SegInstSEW));
1007+ Ops .push_back(ConstantInt::get(Ops.back()->getType(), PolicyAttrs));
1008+ Ops .push_back(ConstantInt::get(Ops.back()->getType(), SegInstSEW));
10471009
10481010 if (IsMasked)
1049- IntrinsicTypes = {ResultType, Ops[Offset ]->getType(),
1050- Ops[Offset + 1 ]->getType(),
1051- Ops[0 ]->getType(),
1052- Ops.back() ->getType()};
1011+ IntrinsicTypes = {ResultType, Ops[1 ]->getType(),
1012+ Ops[2 ]->getType(),
1013+ Ops[3 ]->getType(),
1014+ Ops[4] ->getType()};
10531015 else
1054- IntrinsicTypes = {ResultType, Ops[Offset ]->getType(),
1055- Ops[Offset + 1 ]->getType(),
1056- Ops.back() ->getType()};
1016+ IntrinsicTypes = {ResultType, Ops[1 ]->getType(),
1017+ Ops[2 ]->getType(),
1018+ Ops[3] ->getType()};
10571019 llvm::Function *F = CGM.getIntrinsic(ID, IntrinsicTypes);
1058- llvm::Value *LoadValue = Builder.CreateCall(F, Operands , "");
1020+ llvm::Value *LoadValue = Builder.CreateCall(F, Ops , "");
10591021
10601022 if (ReturnValue.isNull())
10611023 return LoadValue;
@@ -1090,30 +1052,25 @@ multiclass RVVIndexedSegStoreTuple<string op> {
10901052 {
10911053 // Masked
10921054 // Builtin: (mask, ptr, index, v_tuple, vl)
1093- // Intrinsic: (tuple, ptr, index, mask, vl)
1055+ // Intrinsic: (tuple, ptr, index, mask, vl, SegInstSEW )
10941056 // Unmasked
10951057 // Builtin: (ptr, index, v_tuple, vl)
1096- // Intrinsic: (tuple, ptr, index, vl)
1097- unsigned Offset = IsMasked ? 1 : 0;
1058+ // Intrinsic: (tuple, ptr, index, vl, SegInstSEW)
10981059
1099- SmallVector<llvm::Value*, 6> Operands;
1100- Operands.push_back(Ops[Offset + 2]); // tuple
1101- Operands.push_back(Ops[Offset]); // Ptr
1102- Operands.push_back(Ops[Offset + 1]); // Idx
11031060 if (IsMasked)
1104- Operands.push_back(Ops[0]);
1105- Operands.push_back(Ops[Offset + 3]); // VL
1106- Operands.push_back(ConstantInt::get(Ops.back()->getType(), SegInstSEW));
1061+ std::swap(Ops[0], Ops[3]);
1062+ else
1063+ std::rotate(Ops.begin(), Ops.begin() + 2, Ops.begin() + 3);
1064+
1065+ Ops.push_back(ConstantInt::get(Ops.back()->getType(), SegInstSEW));
11071066
11081067 if (IsMasked)
1109- IntrinsicTypes = {Operands[0]->getType(), Ops[Offset]->getType(), Ops[Offset + 1]->getType(),
1110- Ops[0]->getType(),
1111- Operands.back()->getType()};
1068+ IntrinsicTypes = {Ops[0]->getType(), Ops[1]->getType(), Ops[2]->getType(),
1069+ Ops[3]->getType(), Ops[4]->getType()};
11121070 else
1113- IntrinsicTypes = {Operands[0]->getType(), Ops[Offset]->getType(), Ops[Offset + 1]->getType(),
1114- Operands.back()->getType()};
1115- llvm::Function *F = CGM.getIntrinsic(ID, IntrinsicTypes);
1116- return Builder.CreateCall(F, Operands, "");
1071+ IntrinsicTypes = {Ops[0]->getType(), Ops[1]->getType(), Ops[2]->getType(),
1072+ Ops[3]->getType()};
1073+ break;
11171074 }
11181075 }] in {
11191076 defvar T = "(Tuple:" # nf # ")";
0 commit comments