eopXD updated this revision to Diff 485270.
eopXD added a comment.

Rebase to latest main.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140662/new/

https://reviews.llvm.org/D140662

Files:
  clang/include/clang/Basic/riscv_vector.td

Index: clang/include/clang/Basic/riscv_vector.td
===================================================================
--- clang/include/clang/Basic/riscv_vector.td
+++ clang/include/clang/Basic/riscv_vector.td
@@ -843,39 +843,30 @@
       ResultType = ConvertType(E->getArg(0)->getType()->getPointeeType());
       IntrinsicTypes = {ResultType, Ops.back()->getType()};
       SmallVector<llvm::Value*, 10> Operands;
-      if (IsMasked) {
-        // TAMA builtin: (val0 address, ..., mask, ptr, vl)
-        // builtin: (val0 address, ..., mask, maskedoff0, ..., ptr, vl)
-        // intrinsic: (maskedoff0, ..., ptr, mask, vl)
-        if (DefaultPolicy == TAIL_AGNOSTIC_MASK_AGNOSTIC) {
-          Operands.append(NF, llvm::PoisonValue::get(ResultType));
-          Operands.push_back(Ops[NF + 1]);
-          Operands.push_back(Ops[NF]);
-          Operands.push_back(Ops[NF + 2]);
-        } else {
-          for (unsigned I = 0; I < NF; ++I)
-            Operands.push_back(Ops[NF + I + 1]);
-          Operands.push_back(Ops[2 * NF + 1]);
-          Operands.push_back(Ops[NF]);
-          Operands.push_back(Ops[2 * NF + 2]);
-        }
+
+      // Intrinsic is in the form of below,
+      // Masked: (Vector0, ..., Vector{NF - 1}, Ptr, Mask, VL, Policy)
+      // Unmasked: (Vector0, ..., Vector{NF - 1}, Ptr, VL)
+      // where the Vectors is poison when the policy behavior allows us to not care
+      // about any masked-off elements.
+      Value *PassThruOperand = IsMasked ?
+        (DefaultPolicy == TAIL_AGNOSTIC_MASK_AGNOSTIC) ?
+          llvm::PoisonValue::get(ResultType) : Ops[NF + 1] :
+        (DefaultPolicy == TAIL_AGNOSTIC) ?
+          llvm::PoisonValue::get(ResultType) : Ops[NF];
+      unsigned PtrOperandIdx = IsMasked ?
+        (DefaultPolicy == TAIL_AGNOSTIC_MASK_AGNOSTIC) ? NF + 1 : 2 * NF + 1 :
+        (DefaultPolicy == TAIL_AGNOSTIC) ? NF : 2 * NF;
+      Value *PtrOperand = Ops[PtrOperandIdx];
+      Value *VLOperand = Ops[PtrOperandIdx + 1];
+      Operands.append(NF, PassThruOperand);
+      Operands.push_back(PtrOperand);
+      if (IsMasked)
+        Operands.push_back(Ops[NF]);
+      Operands.push_back(VLOperand);
+      if (IsMasked)
         Operands.push_back(ConstantInt::get(Ops.back()->getType(), DefaultPolicy));
-        assert(Operands.size() == NF + 4);
-      } else {
-        // TA builtin: (val0 address, val1 address, ..., ptr, vl)
-        // TU builtin: (val0 address, ..., passthru0, ..., ptr, vl)
-        // intrinsic: (passthru0, passthru1, ..., ptr, vl)
-        if (DefaultPolicy == TAIL_AGNOSTIC) {
-          Operands.append(NF, llvm::PoisonValue::get(ResultType));
-          Operands.push_back(Ops[NF]);
-          Operands.push_back(Ops[NF + 1]);
-        } else {
-          for (unsigned I = 0; I < NF; ++I)
-            Operands.push_back(Ops[NF + I]);
-          Operands.push_back(Ops[2 * NF]);
-          Operands.push_back(Ops[2 * NF + 1]);
-        }
-      }
+
       llvm::Function *F = CGM.getIntrinsic(ID, IntrinsicTypes);
       llvm::Value *LoadValue = Builder.CreateCall(F, Operands, "");
       clang::CharUnits Align =
@@ -918,45 +909,31 @@
       ResultType = ConvertType(E->getArg(0)->getType()->getPointeeType());
       IntrinsicTypes = {ResultType, Ops.back()->getType()};
       SmallVector<llvm::Value*, 12> Operands;
-      Value *NewVL;
 
-      if (IsMasked) {
-        // TAMA builtin: (val0 address, ..., mask, ptr, new_vl, vl)
-        // builtin: (val0 address, ..., mask, maskedoff0, ..., ptr, new_vl, vl)
-        // intrinsic: (maskedoff0, ..., ptr, mask, vl)
-        if (DefaultPolicy == TAIL_AGNOSTIC_MASK_AGNOSTIC) {
-          Operands.append(NF, llvm::PoisonValue::get(ResultType));
-          Operands.push_back(Ops[NF + 1]);
-          Operands.push_back(Ops[NF]);
-          Operands.push_back(Ops[NF + 3]);
-          NewVL = Ops[NF + 2];
-        } else {
-          for (unsigned I = 0; I < NF; ++I)
-            Operands.push_back(Ops[NF + I + 1]);
-          Operands.push_back(Ops[2 * NF + 1]);
-          Operands.push_back(Ops[NF]);
-          Operands.push_back(Ops[2 * NF + 3]);
-          NewVL = Ops[2 * NF + 2];
-        }
+      // Intrinsic is in the form of below,
+      // Masked: (Vector0, ..., Vector{NF - 1}, Ptr, Mask, NewVL, VL, Policy)
+      // Unmasked: (Vector0, ..., Vector{NF - 1}, Ptr, NewVL, VL)
+      // where the Vectors is poison when the policy behavior allows us to not care
+      // about any masked-off elements.
+      Value *PassThruOperand = IsMasked ?
+        (DefaultPolicy == TAIL_AGNOSTIC_MASK_AGNOSTIC) ?
+          llvm::PoisonValue::get(ResultType) : Ops[NF + 1] :
+        (DefaultPolicy == TAIL_AGNOSTIC) ?
+          llvm::PoisonValue::get(ResultType) : Ops[NF];
+      unsigned PtrOperandIdx = IsMasked ?
+        (DefaultPolicy == TAIL_AGNOSTIC_MASK_AGNOSTIC) ? NF + 1 : 2 * NF + 1 :
+        (DefaultPolicy == TAIL_AGNOSTIC) ? NF : 2 * NF;
+      Value *PtrOperand = Ops[PtrOperandIdx];
+      Value *NewVLOperand = Ops[PtrOperandIdx + 1];
+      Value *VLOperand = Ops[PtrOperandIdx + 2];
+      Operands.append(NF, PassThruOperand);
+      Operands.push_back(PtrOperand);
+      if (IsMasked)
+        Operands.push_back(Ops[NF]);
+      Operands.push_back(VLOperand);
+      if (IsMasked)
         Operands.push_back(ConstantInt::get(Ops.back()->getType(), DefaultPolicy));
-        assert(Operands.size() == NF + 4);
-      } else {
-        // TA builtin: (val0 address, val1 address, ..., ptr, new_vl, vl)
-        // TU builtin: (val0 address, ..., passthru0, ..., ptr, new_vl, vl)
-        // intrinsic: (passthru0, passthru1, ..., ptr, vl)
-        if (DefaultPolicy == TAIL_AGNOSTIC) {
-          Operands.append(NF, llvm::PoisonValue::get(ResultType));
-          Operands.push_back(Ops[NF]);
-          Operands.push_back(Ops[NF + 2]);
-          NewVL = Ops[NF + 1];
-        } else {
-          for (unsigned I = 0; I < NF; ++I)
-            Operands.push_back(Ops[NF + I]);
-          Operands.push_back(Ops[2 * NF]);
-          Operands.push_back(Ops[2 * NF + 2]);
-          NewVL = Ops[2 * NF + 1];
-        }
-      }
+
       llvm::Function *F = CGM.getIntrinsic(ID, IntrinsicTypes);
       llvm::Value *LoadValue = Builder.CreateCall(F, Operands, "");
       clang::CharUnits Align =
@@ -967,7 +944,7 @@
       }
       // Store new_vl.
       llvm::Value *Val = Builder.CreateExtractValue(LoadValue, {NF});
-      return Builder.CreateStore(Val, Address(NewVL, Val->getType(), Align));
+      return Builder.CreateStore(Val, Address(NewVLOperand, Val->getType(), Align));
     }
     }] in {
           defvar PV = PVString<nf, /*signed=*/true>.S;
@@ -1001,43 +978,31 @@
       IntrinsicTypes = {ResultType, Ops.back()->getType()};
       SmallVector<llvm::Value*, 12> Operands;
 
-      if (IsMasked) {
-        // TAMA builtin: (val0 address, ..., mask, ptr, stride, vl)
-        // builtin: (val0 address, ..., mask, maskedoff0, ..., ptr, stride, vl)
-        // intrinsic: (maskedoff0, ..., ptr, stride, mask, vl)
-        if (DefaultPolicy == TAIL_AGNOSTIC_MASK_AGNOSTIC) {
-          Operands.append(NF, llvm::PoisonValue::get(ResultType));
-          Operands.push_back(Ops[NF + 1]);
-          Operands.push_back(Ops[NF + 2]);
-          Operands.push_back(Ops[NF]);
-          Operands.push_back(Ops[NF + 3]);
-        } else {
-          for (unsigned I = 0; I < NF; ++I)
-            Operands.push_back(Ops[NF + I + 1]);
-          Operands.push_back(Ops[2 * NF + 1]);
-          Operands.push_back(Ops[2 * NF + 2]);
-          Operands.push_back(Ops[NF]);
-          Operands.push_back(Ops[2 * NF + 3]);
-        }
+      // Intrinsic is in the form of below,
+      // Masked: (Vector0, ..., Vector{NF - 1}, Ptr, Stride, Mask, VL, Policy)
+      // Unmasked: (Vector0, ..., Vector{NF - 1}, Ptr, Stride, VL)
+      // where the Vectors is poison when the policy behavior allows us to not care
+      // about any masked-off elements.
+      Value *PassThruOperand = IsMasked ?
+        (DefaultPolicy == TAIL_AGNOSTIC_MASK_AGNOSTIC) ?
+          llvm::PoisonValue::get(ResultType) : Ops[NF + 1] :
+        (DefaultPolicy == TAIL_AGNOSTIC) ?
+          llvm::PoisonValue::get(ResultType) : Ops[NF];
+      unsigned PtrOperandIdx = IsMasked ?
+        (DefaultPolicy == TAIL_AGNOSTIC_MASK_AGNOSTIC) ? NF + 1 : 2 * NF + 1 :
+        (DefaultPolicy == TAIL_AGNOSTIC) ? NF : 2 * NF;
+      Value *PtrOperand = Ops[PtrOperandIdx];
+      Value *StrideOperand = Ops[PtrOperandIdx + 1];
+      Value *VLOperand = Ops[PtrOperandIdx + 2];
+      Operands.append(NF, PassThruOperand);
+      Operands.push_back(PtrOperand);
+      Operands.push_back(StrideOperand);
+      if (IsMasked)
+        Operands.push_back(Ops[NF]);
+      Operands.push_back(VLOperand);
+      if (IsMasked)
         Operands.push_back(ConstantInt::get(Ops.back()->getType(), DefaultPolicy));
-        assert(Operands.size() == NF + 5);
-      } else {
-        // TA builtin: (val0 address, val1 address, ..., ptr, stride, vl)
-        // TU builtin: (val0 address, ..., passthru0, ..., ptr, stride, vl)
-        // intrinsic: (passthru0, passthru1, ..., ptr, stride, vl)
-        if (DefaultPolicy == TAIL_AGNOSTIC) {
-          Operands.append(NF, llvm::PoisonValue::get(ResultType));
-          Operands.push_back(Ops[NF]);
-          Operands.push_back(Ops[NF + 1]);
-          Operands.push_back(Ops[NF + 2]);
-        } else {
-          for (unsigned I = 0; I < NF; ++I)
-            Operands.push_back(Ops[NF + I]);
-          Operands.push_back(Ops[2 * NF]);
-          Operands.push_back(Ops[2 * NF + 1]);
-          Operands.push_back(Ops[2 * NF + 2]);
-        }
-      }
+
       llvm::Function *F = CGM.getIntrinsic(ID, IntrinsicTypes);
       llvm::Value *LoadValue = Builder.CreateCall(F, Operands, "");
       clang::CharUnits Align =
@@ -1075,47 +1040,33 @@
     {
       ResultType = ConvertType(E->getArg(0)->getType()->getPointeeType());
       SmallVector<llvm::Value*, 12> Operands;
-      if (IsMasked) {
-        // TAMA builtin: (val0 address, ..., mask, ptr, index, vl)
-        // builtin: (val0 address, ..., mask, maskedoff0, ..., ptr, index, vl)
-        // intrinsic: (maskedoff0, ..., ptr, index, mask, vl)
-        if (DefaultPolicy == TAIL_AGNOSTIC_MASK_AGNOSTIC) {
-          Operands.append(NF, llvm::PoisonValue::get(ResultType));
-          Operands.push_back(Ops[NF + 1]);
-          Operands.push_back(Ops[NF + 2]);
-          Operands.push_back(Ops[NF]);
-          Operands.push_back(Ops[NF + 3]);
-          IntrinsicTypes = {ResultType, Ops[NF + 2]->getType(), Ops.back()->getType()};
-        } else {
-          for (unsigned I = 0; I < NF; ++I)
-            Operands.push_back(Ops[NF + I + 1]);
-          Operands.push_back(Ops[2 * NF + 1]);
-          Operands.push_back(Ops[2 * NF + 2]);
-          Operands.push_back(Ops[NF]);
-          Operands.push_back(Ops[2 * NF + 3]);
-          IntrinsicTypes = {ResultType, Ops[2 * NF + 2]->getType(), Ops.back()->getType()};
-        }
+
+      // Intrinsic is in the form of below,
+      // Masked: (Vector0, ..., Vector{NF - 1}, Ptr, Index, Mask, VL, Policy)
+      // Unmasked: (Vector0, ..., Vector{NF - 1}, Ptr, Index, VL)
+      // where the Vectors is poison when the policy behavior allows us to not care
+      // about any masked-off elements.
+      Value *PassThruOperand = IsMasked ?
+        (DefaultPolicy == TAIL_AGNOSTIC_MASK_AGNOSTIC) ?
+          llvm::PoisonValue::get(ResultType) : Ops[NF + 1] :
+        (DefaultPolicy == TAIL_AGNOSTIC) ?
+          llvm::PoisonValue::get(ResultType) : Ops[NF];
+      unsigned PtrOperandIdx = IsMasked ?
+        (DefaultPolicy == TAIL_AGNOSTIC_MASK_AGNOSTIC) ? NF + 1 : 2 * NF + 1 :
+        (DefaultPolicy == TAIL_AGNOSTIC) ? NF : 2 * NF;
+      Value *PtrOperand = Ops[PtrOperandIdx];
+      Value *IndexOperand = Ops[PtrOperandIdx + 1];
+      Value *VLOperand = Ops[PtrOperandIdx + 2];
+      Operands.append(NF, PassThruOperand);
+      Operands.push_back(PtrOperand);
+      Operands.push_back(IndexOperand);
+      if (IsMasked)
+        Operands.push_back(Ops[NF]);
+      Operands.push_back(VLOperand);
+      if (IsMasked)
         Operands.push_back(ConstantInt::get(Ops.back()->getType(), DefaultPolicy));
-        assert(Operands.size() == NF + 5);
-      } else {
-        // TA builtin: (val0 address, val1 address, ..., ptr, index, vl)
-        // TU builtin: (val0 address, ..., passthru0, ..., ptr, index, vl)
-        // intrinsic: (passthru0, passthru1, ..., ptr, index, vl)
-        if (DefaultPolicy == TAIL_AGNOSTIC) {
-          Operands.append(NF, llvm::PoisonValue::get(ResultType));
-          Operands.push_back(Ops[NF]);
-          Operands.push_back(Ops[NF + 1]);
-          Operands.push_back(Ops[NF + 2]);
-          IntrinsicTypes = {ResultType, Ops[NF + 1]->getType(), Ops.back()->getType()};
-        } else {
-          for (unsigned I = 0; I < NF; ++I)
-            Operands.push_back(Ops[NF + I]);
-          Operands.push_back(Ops[2 * NF]);
-          Operands.push_back(Ops[2 * NF + 1]);
-          Operands.push_back(Ops[2 * NF + 2]);
-          IntrinsicTypes = {ResultType, Ops[2 * NF + 1]->getType(), Ops.back()->getType()};
-        }
-      }
+      IntrinsicTypes = {ResultType, IndexOperand->getType(), Ops.back()->getType()};
+
       llvm::Function *F = CGM.getIntrinsic(ID, IntrinsicTypes);
       llvm::Value *LoadValue = Builder.CreateCall(F, Operands, "");
       clang::CharUnits Align =
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to