Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions clang/include/clang/Basic/arm_mve.td
Original file line number Diff line number Diff line change
Expand Up @@ -831,9 +831,8 @@ multiclass contiguous_load<string mnemonic, PrimitiveType memtype,
NameOverride<mnemonic>;
def: Intrinsic<Vector, (args CPtr<CopyKind<same_size[0], Scalar>>:$addr,
Predicate:$pred),
(IRIntBase<"masked_load", [Vector, CPtr<Vector>]>
(CPtr<Vector> $addr), !srl(memtype.size,3),
$pred, (zeroinit Vector))>,
(masked_load Vector, (CPtr<Vector> $addr),
!srl(memtype.size,3), $pred, (zeroinit Vector))>,
NameOverride<mnemonic # "_z">;
}

Expand All @@ -846,9 +845,8 @@ multiclass contiguous_load<string mnemonic, PrimitiveType memtype,
NameOverride<"vld1q">;
def: Intrinsic<Vector, (args CPtr<CopyKind<same_size[0], Scalar>>:$addr,
Predicate:$pred),
(IRIntBase<"masked_load", [Vector, CPtr<Vector>]>
(CPtr<Vector> $addr), !srl(memtype.size,3),
$pred, (zeroinit Vector))>,
(masked_load Vector, (CPtr<Vector> $addr),
!srl(memtype.size,3), $pred, (zeroinit Vector))>,
NameOverride<"vld1q_z">;
}

Expand All @@ -863,9 +861,7 @@ multiclass contiguous_load<string mnemonic, PrimitiveType memtype,
NameOverride<mnemonic>;
def: Intrinsic<Vector, (args CPtr<CopyKind<same_size[0], Scalar>>:$addr,
Predicate:$pred),
(extend (IRIntBase<"masked_load",
[NarrowedVecOf<memtype,Vector>,
CPtr<NarrowedVecOf<memtype,Vector>>]>
(extend (masked_load NarrowedVecOf<memtype,Vector>,
(CPtr<NarrowedVecOf<memtype,Vector>> $addr),
!srl(memtype.size,3), $pred,
(zeroinit NarrowedVecOf<memtype,Vector>)),
Expand All @@ -890,8 +886,7 @@ multiclass contiguous_store<string mnemonic, PrimitiveType memtype,
NameOverride<mnemonic>;
def: Intrinsic<Void, (args Ptr<CopyKind<same_size[0], Scalar>>:$addr,
Vector:$value, Predicate:$pred),
(IRIntBase<"masked_store", [Vector, Ptr<Vector>]>
$value, (Ptr<Vector> $addr),
(masked_store $value, (Ptr<Vector> $addr),
!srl(memtype.size,3), $pred)>,
NameOverride<mnemonic # "_p">;
}
Expand All @@ -907,8 +902,7 @@ multiclass contiguous_store<string mnemonic, PrimitiveType memtype,
NameOverride<"vst1q">;
def: Intrinsic<Void, (args Ptr<CopyKind<same_size[0], Scalar>>:$addr,
Vector:$value, Predicate:$pred),
(IRIntBase<"masked_store", [Vector, Ptr<Vector>]>
$value, (Ptr<Vector> $addr),
(masked_store $value, (Ptr<Vector> $addr),
!srl(memtype.size,3), $pred)>,
NameOverride<"vst1q_p">;
}
Expand All @@ -925,9 +919,7 @@ multiclass contiguous_store<string mnemonic, PrimitiveType memtype,
NameOverride<mnemonic>;
def: Intrinsic<Void, (args Ptr<CopyKind<same_size[0], Scalar>>:$addr,
Vector:$value, Predicate:$pred),
(IRIntBase<"masked_store",
[NarrowedVecOf<memtype,Vector>,
Ptr<NarrowedVecOf<memtype,Vector>>]>
(masked_store
(trunc $value, NarrowedVecOf<memtype,Vector>),
(Ptr<NarrowedVecOf<memtype,Vector>> $addr),
!srl(memtype.size,3), $pred)>,
Expand Down
7 changes: 7 additions & 0 deletions clang/include/clang/Basic/arm_mve_defs.td
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ def unzip: CGHelperFn<"VectorUnzip"> {
}
def zip: CGHelperFn<"VectorZip">;

def masked_load: IRBuilder<"CreateMaskedLoad"> {
let special_params = [IRBuilderIntParam<2, "Align">];
}
def masked_store: IRBuilder<"CreateMaskedStore"> {
let special_params = [IRBuilderIntParam<2, "Align">];
}

// Trivial 'codegen' function that just returns its argument. Useful
// for wrapping up a variable name like $foo into a thing you can pass
// around as type 'dag'.
Expand Down
3 changes: 2 additions & 1 deletion clang/utils/TableGen/MveEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,8 @@ void EmitterBase::EmitBuiltinCG(raw_ostream &OS) {
OS << " case ARM::BI__builtin_arm_" << OI.Int->builtinExtension()
<< "_" << OI.Name << ":\n";
for (size_t i = 0, e = MG.ParamTypes.size(); i < e; ++i)
OS << " Param" << utostr(i) << " = " << OI.ParamValues[i] << ";\n";
OS << " Param" << utostr(i) << " = static_cast<"
<< MG.ParamTypes[i] << ">(" << OI.ParamValues[i] << ");\n";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit message doesn't explain why this change is needed, and I can't work it out by myself. What goes wrong without it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Align constructor is explicit, so it's not possible to directly assign an integer to an Align variable.

Copy link
Collaborator

@statham-arm statham-arm Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd guessed that much, but I was still confused about why the cast there, when the static_cast<Align> was already present in the actual call to Builder.CreateMaskedStore.

But now I've looked at the output of your modified clang-tblgen, I understand:

case ARM::BI__builtin_arm_mve_vst1q_p_f16:
// ...
case ARM::BI__builtin_arm_mve_vstrwq_p_u32: {
  llvm::Type * Param0;
  Align  Param1;
  switch (BuiltinID) {
  case ARM::BI__builtin_arm_mve_vst1q_p_f16:
    Param0 = static_cast<llvm::Type *>(llvm::FixedVectorType::get(Builder.getInt1Ty(), 8));
    Param1 = static_cast<Align>(2);
    break;
    // ...
  case ARM::BI__builtin_arm_mve_vstrwq_p_u32:
    Param0 = static_cast<llvm::Type *>(llvm::FixedVectorType::get(Builder.getInt1Ty(), 4));
    Param1 = static_cast<Align>(4);
    break;
  }
  // ...
  return Builder.CreateMaskedStore(Val0, Val2, static_cast<Align>(Param1), Val5);
}

If the cast in the CreateMaskedStore were to be enough, it would have to be because Param1 had some other type which could be initialized via an integer literal, and it's easier to add a second cast to the same type than to invent an appropriate alternative type.

Sorry about being slow to get the point!

OS << " break;\n";
}
OS << " }\n";
Expand Down