diff mbox series

rs6000: Consider explicitly set options in target option parsing [PR115713]

Message ID 1602c550-1189-dcd2-9053-ce080a2ac0a5@linux.ibm.com
State New
Headers show
Series rs6000: Consider explicitly set options in target option parsing [PR115713] | expand

Commit Message

Kewen.Lin July 10, 2024, 8:44 a.m. UTC
Hi,

In rs6000_inner_target_options, when enabling VSX we enable
altivec and disable -mavoid-indexed-addresses implicitly,
but it doesn't consider the case that the options altivec
and avoid-indexed-addresses can be explicitly disabled.  As
the test case in PR115713#c1 shows, with target attribute
"no-altivec,vsx", it results in that VSX unexpectedly set
altivec flag and there isn't an expected error.

This patch is to avoid the automatic enablement when they
are explicitly specified.  With this change, an existing
test case ppc-target-4.c also requires an adjustment by
specifying explicit altivec in target attribute (since it
requires altivec feature and command line is specifying
no-altivec).

Bootstrapped and regtested on powerpc64-linux-gnu P8/P9 and
powerpc64le-linux-gnu P9 and P10.

I'm going to push this next week if no objections.

BR,
Kewen
-----

	PR target/115713

gcc/ChangeLog:

	* config/rs6000/rs6000.cc (rs6000_inner_target_options): Avoid to
	enable altivec or disable avoid-indexed-addresses automatically
	when they get specified explicitly.

gcc/testsuite/ChangeLog:

	* gcc.target/powerpc/pr115713-1.c: New test.
	* gcc.target/powerpc/ppc-target-4.c: Adjust by specifying altivec
	in target attribute.
---
 gcc/config/rs6000/rs6000.cc                   |  7 +++++--
 .../gcc.target/powerpc/ppc-target-4.c         |  2 +-
 gcc/testsuite/gcc.target/powerpc/pr115713-1.c | 20 +++++++++++++++++++
 3 files changed, 26 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/pr115713-1.c

--
2.45.2
diff mbox series

Patch

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 3b1ee3a262a..ed7a9fdeb58 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -24643,8 +24643,11 @@  rs6000_inner_target_options (tree args, bool attr_p)
 			  {
 			    if (mask == OPTION_MASK_VSX)
 			      {
-				mask |= OPTION_MASK_ALTIVEC;
-				TARGET_AVOID_XFORM = 0;
+				if (!(rs6000_isa_flags_explicit
+				      & OPTION_MASK_ALTIVEC))
+				  mask |= OPTION_MASK_ALTIVEC;
+				if (!OPTION_SET_P (TARGET_AVOID_XFORM))
+				  TARGET_AVOID_XFORM = 0;
 			      }
 			  }

diff --git a/gcc/testsuite/gcc.target/powerpc/ppc-target-4.c b/gcc/testsuite/gcc.target/powerpc/ppc-target-4.c
index 43a98b353cf..db9ba500e0e 100644
--- a/gcc/testsuite/gcc.target/powerpc/ppc-target-4.c
+++ b/gcc/testsuite/gcc.target/powerpc/ppc-target-4.c
@@ -18,7 +18,7 @@ 
 #error "__VSX__ should not be defined."
 #endif

-#pragma GCC target("vsx")
+#pragma GCC target("altivec,vsx")
 #include <altivec.h>
 #pragma GCC reset_options

diff --git a/gcc/testsuite/gcc.target/powerpc/pr115713-1.c b/gcc/testsuite/gcc.target/powerpc/pr115713-1.c
new file mode 100644
index 00000000000..1b93a78682a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr115713-1.c
@@ -0,0 +1,20 @@ 
+/* { dg-do compile } */
+/* Force power7 to avoid possible error message on AltiVec ABI change.  */
+/* { dg-options "-mdejagnu-cpu=power7" } */
+
+/* Verify there is an error message for incompatible -maltivec and -mvsx
+   even when they are specified by target attributes.  */
+
+int __attribute__ ((target ("no-altivec,vsx")))
+test1 (void)
+{
+  /* { dg-error "'-mvsx' and '-mno-altivec' are incompatible" "" { target *-*-* } .-1 } */
+  return 0;
+}
+
+int __attribute__ ((target ("vsx,no-altivec")))
+test2 (void)
+{
+  /* { dg-error "'-mvsx' and '-mno-altivec' are incompatible" "" { target *-*-* } .-1 } */
+  return 0;
+}