[PATCH] D143467: [PowerPC] Add target feature requirement to builtins

Nemanja Ivanovic via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 20 10:15:33 PDT 2023


nemanjai added a comment.

Actually, while you're here, can you please remove all calls to `SemaFeatureCheck()` that test builtins which are only available on a specific CPU? The Sema checking happens too early before the target info is populated, which does not allow for a very common idiom where the feature is enabled for a function/region using an attribute or a pragma.

For example, we received a report from Eigen that something like this:

  __attribute__((target("mma,prefix-instrs")))
  void test5(unsigned char *vqp, unsigned char *vpp, vector unsigned char vc,
             unsigned char *resp) {
    __vector_quad vq = *((__vector_quad *)vqp);
    __vector_pair vp = *((__vector_pair *)vpp);
    __builtin_mma_pmxvf64ger(&vq, vp, vc, 0, 0);
    *((__vector_quad *)resp) = vq;
  }
  
  vector unsigned char test6(vector unsigned char a, vector unsigned char b) {
    return a + b + (vector unsigned char)121;
  }

Cannot be done with Clang because it produces errors such as:

  error: this builtin is only valid on POWER10 or later CPUs
    __builtin_mma_pmxvf64ger(&vq, vp, vc, 0, 0);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



================
Comment at: clang/include/clang/Basic/BuiltinsPPC.def:83-84
 BUILTIN(__builtin_ppc_lwarx, "iiD*", "")
-BUILTIN(__builtin_ppc_lharx, "ssD*", "")
-BUILTIN(__builtin_ppc_lbarx, "ccD*", "")
+TARGET_BUILTIN(__builtin_ppc_lharx, "ssD*", "", "isa-v206-instructions")
+TARGET_BUILTIN(__builtin_ppc_lbarx, "ccD*", "", "isa-v206-instructions")
 BUILTIN(__builtin_ppc_stdcx, "iLiD*Li", "")
----------------
Please change this to 207.


================
Comment at: clang/include/clang/Basic/BuiltinsPPC.def:87-88
 BUILTIN(__builtin_ppc_stwcx, "iiD*i", "")
-BUILTIN(__builtin_ppc_sthcx, "isD*s", "")
-BUILTIN(__builtin_ppc_stbcx, "icD*i", "")
+TARGET_BUILTIN(__builtin_ppc_sthcx, "isD*s", "", "isa-v206-instructions")
+TARGET_BUILTIN(__builtin_ppc_stbcx, "icD*i", "", "isa-v206-instructions")
 BUILTIN(__builtin_ppc_tdw, "vLLiLLiIUi", "")
----------------
Similarly to the loads.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143467



More information about the cfe-commits mailing list