x86: Don't enable LZCNT/POPCNT if disabled explicitly
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 30 Jul 2021 12:58:38 +0000 (05:58 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 30 Jul 2021 13:05:37 +0000 (06:05 -0700)
gcc/

PR target/101685
* config/i386/i386-options.c (ix86_option_override_internal):
Don't enable LZCNT/POPCNT if they have been disabled explicitly.

gcc/testsuite/

PR target/101685
* gcc.target/i386/pr101685.c: New test.

gcc/config/i386/i386-options.c
gcc/testsuite/gcc.target/i386/pr101685.c [new file with mode: 0644]

index 3416a4f..6b78998 100644 (file)
@@ -2124,8 +2124,10 @@ ix86_option_override_internal (bool main_args_p,
        if (((processor_alias_table[i].flags & PTA_ABM) != 0)
            && !TARGET_EXPLICIT_ABM_P (opts))
          {
-           SET_TARGET_LZCNT (opts);
-           SET_TARGET_POPCNT (opts);
+           if (!TARGET_EXPLICIT_LZCNT_P (opts))
+             SET_TARGET_LZCNT (opts);
+           if (!TARGET_EXPLICIT_POPCNT_P (opts))
+             SET_TARGET_POPCNT (opts);
          }
 
        if ((processor_alias_table[i].flags
diff --git a/gcc/testsuite/gcc.target/i386/pr101685.c b/gcc/testsuite/gcc.target/i386/pr101685.c
new file mode 100644 (file)
index 0000000..0c743ec
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=amdfam10 -mno-lzcnt -mno-popcnt" } */
+
+#ifdef __LZCNT__
+# error LZCNT should be disabled
+#endif
+
+#ifdef __POPCNT__
+# error POPCNT should be disabled
+#endif