[clang] [Clang][MVE] Use IRBuilder methods to emit masked load/store (NFC) (PR #163790)

Simon Tatham via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 17 02:14:16 PDT 2025


================
@@ -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";
----------------
statham-arm wrote:

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:

```c++
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.

https://github.com/llvm/llvm-project/pull/163790


More information about the cfe-commits mailing list