[clang] [FMV][RISCV] Add __riscv_feature_bits.length check (PR #110098)

Jessica Clarke via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 26 03:08:01 PDT 2024


================
@@ -2970,22 +2974,28 @@ void CodeGenFunction::EmitRISCVMultiVersionResolver(
     // (__riscv_feature_bits.features[i] & REQUIRED_BITMASK) ==
     // REQUIRED_BITMASK
     //
+    // First, check __riscv_feature_bits.length <=
+    // llvm::RISCVISAInfo::FeatureBitSize. This ensures that the
+    // __riscv_feature_bits object at runtime has the same length as on the
+    // compiler side.
+    //
+    // Second,
     // When condition is met, return this version of the function.
     // Otherwise, try the next version.
     //
-    // if (FeaturesConditionVersion1)
+    //
+    // if (__riscv_feature_bits.features.length <=
----------------
jrtc27 wrote:

>=, surely? But also this should be per set of features being tested, and specific to the min length needed for that, not apply to all versions. Otherwise if the compiler learns about a new word but is run on an older OS it will stop using optimised versions.

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


More information about the cfe-commits mailing list