Commit 29c6debc by Tamar Christina Committed by Tamar Christina

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
parent ee8b2b8e
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> 2019-02-28 Jakub Jelinek <jakub@redhat.com>
PR c/89520 PR c/89520
......
...@@ -44,7 +44,8 @@ ...@@ -44,7 +44,8 @@
the extension (for example, the 'crypto' extension depends on four the extension (for example, the 'crypto' extension depends on four
entries: aes, pmull, sha1, sha2 being present). In that case this field entries: aes, pmull, sha1, sha2 being present). In that case this field
should contain a space (" ") separated list of the strings in 'Features' 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". /* Enabling "fp" just enables "fp".
Disabling "fp" also disables "simd", "crypto", "fp16", "aes", "sha2", Disabling "fp" also disables "simd", "crypto", "fp16", "aes", "sha2",
......
...@@ -249,27 +249,35 @@ host_detect_local_cpu (int argc, const char **argv) ...@@ -249,27 +249,35 @@ host_detect_local_cpu (int argc, const char **argv)
{ {
for (i = 0; i < num_exts; i++) for (i = 0; i < num_exts; i++)
{ {
char *p = NULL; const char *p = aarch64_extensions[i].feat_string;
char *feat_string
= concat (aarch64_extensions[i].feat_string, NULL); /* If the feature contains no HWCAPS string then ignore it for the
auto detection. */
if (*p == '\0')
continue;
bool enabled = true; bool enabled = true;
/* This may be a multi-token feature string. We need /* This may be a multi-token feature string. We need
to match all parts, which could be in any order. to match all parts, which could be in any order. */
If this isn't a multi-token feature string, strtok is size_t len = strlen (buf);
just going to return a pointer to feat_string. */ do
p = strtok (feat_string, " ");
while (p != NULL)
{ {
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 /* Failed to match this token. Turn off the
features we'd otherwise enable. */ features we'd otherwise enable. */
enabled = false; enabled = false;
break; break;
} }
p = strtok (NULL, " "); if (*end == '\0')
break;
p = end + 1;
} }
while (1);
if (enabled) if (enabled)
extension_flags |= aarch64_extensions[i].flag; extension_flags |= aarch64_extensions[i].flag;
...@@ -360,12 +368,12 @@ host_detect_local_cpu (int argc, const char **argv) ...@@ -360,12 +368,12 @@ host_detect_local_cpu (int argc, const char **argv)
not_found: not_found:
{ {
/* If detection fails we ignore the option. /* If detection fails we ignore the option.
Clean up and return empty string. */ Clean up and return NULL. */
if (f) if (f)
fclose (f); fclose (f);
return ""; return NULL;
} }
} }
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> 2019-02-28 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/89522 PR c++/89522
......
/* { 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. */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment