Skip to content

Commit af4cd0b

Browse files
committed
[Clang][AArch64] Fix checkArmStreamingBuiltin for 'sve-b16b16'
The implementation made the assumption that any feature starting with "sve" meant that this was an SVE feature. This is not the case for "sve-b16b16", as this is a feature that applies to both SVE and SME. This meant that: __attribute__((target("+sme2,+sve2,+sve-b16b16"))) svbfloat16_t foo(svbfloat16_t a, svbfloat16_t b, svbfloat16_t c) __arm_streaming { return svclamp_bf16(a, b, c); } would result in an incorrect diagnostic saying that `svclamp_bf16` could only be used in non-streaming functions.
1 parent 42b696d commit af4cd0b

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

clang/lib/Sema/SemaARM.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -567,23 +567,28 @@ static bool checkArmStreamingBuiltin(Sema &S, CallExpr *TheCall,
567567
// * When compiling for SVE only, the caller must be in non-streaming mode.
568568
// * When compiling for both SVE and SME, the caller can be in either mode.
569569
if (BuiltinType == SemaARM::VerifyRuntimeMode) {
570-
auto DisableFeatures = [](llvm::StringMap<bool> &Map, StringRef S) {
571-
for (StringRef K : Map.keys())
572-
if (K.starts_with(S))
573-
Map[K] = false;
574-
};
575-
576570
llvm::StringMap<bool> CallerFeatureMapWithoutSVE;
577571
S.Context.getFunctionFeatureMap(CallerFeatureMapWithoutSVE, FD);
578-
DisableFeatures(CallerFeatureMapWithoutSVE, "sve");
572+
CallerFeatureMapWithoutSVE["sve"] = false;
573+
CallerFeatureMapWithoutSVE["sve2"] = false;
574+
CallerFeatureMapWithoutSVE["sve2p1"] = false;
575+
// FIXME: This list must be updated with future extensions, because when
576+
// an intrinsic is enabled by (sve2p1|sme2p1), disabling just "sve" is
577+
// not sufficient, as the feature dependences are not resolved.
578+
// At the moment, it should be sufficient to test the 'base' architectural
579+
// support for SVE and SME, which must always be provided in the
580+
// target guard. e.g. TargetGuard = "sve-b16b16" without "sme" or "sve"
581+
// is not sufficient.
579582

580583
// Avoid emitting diagnostics for a function that can never compile.
581584
if (FnType == SemaARM::ArmStreaming && !CallerFeatureMapWithoutSVE["sme"])
582585
return false;
583586

584587
llvm::StringMap<bool> CallerFeatureMapWithoutSME;
585588
S.Context.getFunctionFeatureMap(CallerFeatureMapWithoutSME, FD);
586-
DisableFeatures(CallerFeatureMapWithoutSME, "sme");
589+
CallerFeatureMapWithoutSME["sme"] = false;
590+
CallerFeatureMapWithoutSME["sme2"] = false;
591+
CallerFeatureMapWithoutSME["sme2p1"] = false;
587592

588593
// We know the builtin requires either some combination of SVE flags, or
589594
// some combination of SME flags, but we need to figure out which part

clang/test/Sema/aarch64-streaming-sme-or-nonstreaming-sve-builtins.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ svfloat32_t good6(svfloat32_t a, svfloat32_t b, svfloat32_t c) __arm_streaming_c
3838
return svclamp(a, b, c);
3939
}
4040

41+
// Test that the +sve-b16b16 is not considered an SVE flag (it applies to both)
42+
__attribute__((target("+sme2,+sve2,+sve-b16b16")))
43+
svbfloat16_t good7(svbfloat16_t a, svbfloat16_t b, svbfloat16_t c) __arm_streaming {
44+
return svclamp_bf16(a, b, c);
45+
}
46+
4147
// Without '+sme2', the builtin is only valid in non-streaming mode.
4248
__attribute__((target("+sve2p1,+sme")))
4349
svfloat32_t bad1(svfloat32_t a, svfloat32_t b, svfloat32_t c) __arm_streaming {

0 commit comments

Comments
 (0)