AArch64: Have empty HWCAPs string ignored during native feature detection

This patch makes the feature detection code for AArch64 GCC not add features
automatically when the feature had no hwcaps string to match against.

This means that -mcpu=native no longer adds feature flags such as +profile.
The behavior wasn't noticed before because at the time +profile was added a bug
was preventing any feature bits from being added by native detections.

The loop has also been changed as Jakub specified in order to avoid a memory
leak that was present in the existing code and to be slightly more efficient.

gcc/ChangeLog:

	PR target/88530
	* config/aarch64/aarch64-option-extensions.def: Document it.
	* config/aarch64/driver-aarch64.c (host_detect_local_cpu): Skip feature
	if empty hwcaps.

gcc/testsuite/ChangeLog:

	PR target/88530
	* gcc.target/aarch64/options_set_10.c: New test.

From-SVN: r269276
This commit is contained in:
Tamar Christina 2019-02-28 10:43:41 +00:00 committed by Tamar Christina
parent ee8b2b8ea4
commit 29c6debccf
5 changed files with 45 additions and 13 deletions

View File

@ -1,3 +1,10 @@
2019-02-28 Tamar Christina <tamar.christina@arm.com>
PR target/88530
* config/aarch64/aarch64-option-extensions.def: Document it.
* config/aarch64/driver-aarch64.c (host_detect_local_cpu): Skip feature
if empty hwcaps.
2019-02-28 Jakub Jelinek <jakub@redhat.com>
PR c/89520

View File

@ -44,7 +44,8 @@
the extension (for example, the 'crypto' extension depends on four
entries: aes, pmull, sha1, sha2 being present). In that case this field
should contain a space (" ") separated list of the strings in 'Features'
that are required. Their order is not important. */
that are required. Their order is not important. An empty string means
do not detect this feature during auto detection. */
/* Enabling "fp" just enables "fp".
Disabling "fp" also disables "simd", "crypto", "fp16", "aes", "sha2",

View File

@ -249,27 +249,35 @@ host_detect_local_cpu (int argc, const char **argv)
{
for (i = 0; i < num_exts; i++)
{
char *p = NULL;
char *feat_string
= concat (aarch64_extensions[i].feat_string, NULL);
const char *p = aarch64_extensions[i].feat_string;
/* If the feature contains no HWCAPS string then ignore it for the
auto detection. */
if (*p == '\0')
continue;
bool enabled = true;
/* This may be a multi-token feature string. We need
to match all parts, which could be in any order.
If this isn't a multi-token feature string, strtok is
just going to return a pointer to feat_string. */
p = strtok (feat_string, " ");
while (p != NULL)
to match all parts, which could be in any order. */
size_t len = strlen (buf);
do
{
if (strstr (buf, p) == NULL)
const char *end = strchr (p, ' ');
if (end == NULL)
end = strchr (p, '\0');
if (memmem (buf, len, p, end - p) == NULL)
{
/* Failed to match this token. Turn off the
features we'd otherwise enable. */
enabled = false;
break;
}
p = strtok (NULL, " ");
if (*end == '\0')
break;
p = end + 1;
}
while (1);
if (enabled)
extension_flags |= aarch64_extensions[i].flag;
@ -360,12 +368,12 @@ host_detect_local_cpu (int argc, const char **argv)
not_found:
{
/* If detection fails we ignore the option.
Clean up and return empty string. */
Clean up and return NULL. */
if (f)
fclose (f);
return "";
return NULL;
}
}

View File

@ -1,3 +1,8 @@
2019-02-28 Tamar Christina <tamar.christina@arm.com>
PR target/88530
* gcc.target/aarch64/options_set_10.c: New test.
2019-02-28 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/89522

View File

@ -0,0 +1,11 @@
/* { dg-do compile { target "aarch64*-*-linux*" } } */
/* { dg-additional-options "-mcpu=native" } */
int main ()
{
return 0;
}
/* { dg-final { scan-assembler-not {\.arch .+\+profile.*} } } */
/* Check that an empty feature string is not detected during mcpu=native. */