diff mbox series

Add '__OPTIMIZE__' DejaGnu selector

Message ID 87cztoc9n3.fsf@dem-tschwing-1.ger.mentorg.com
State New
Headers show
Series Add '__OPTIMIZE__' DejaGnu selector | expand

Commit Message

Thomas Schwinge May 18, 2021, 4:02 p.m. UTC
Hi!

Is the attached "Add '__OPTIMIZE__' DejaGnu selector" OK to push after
testing?


Grüße
 Thomas


-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf

Comments

Mike Stump May 23, 2021, 4:28 p.m. UTC | #1
On May 18, 2021, at 9:02 AM, Thomas Schwinge <thomas@codesourcery.com> wrote:
> Is the attached "Add '__OPTIMIZE__' DejaGnu selector" OK to push after
> testing?

Ok.
diff mbox series

Patch

From f2228df26acc3036357debfb5b08501047b78756 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Tue, 18 May 2021 17:30:34 +0200
Subject: [PATCH] Add '__OPTIMIZE__' DejaGnu selector

	gcc/testsuite/
	* lib/target-supports.exp (check_effective_target___OPTIMIZE__):
	New proc.
	* gcc.c-torture/compile/ssa-unused-1.c: New file.
	gcc/
	* doc/sourcebuild.texi (Other attributes): Document '__OPTIMIZE__'
	DejaGnu selector.
---
 gcc/doc/sourcebuild.texi                          |  4 ++++
 .../gcc.c-torture/compile/ssa-unused-1.c          | 15 +++++++++++++++
 gcc/testsuite/lib/target-supports.exp             | 10 ++++++++++
 3 files changed, 29 insertions(+)
 create mode 100644 gcc/testsuite/gcc.c-torture/compile/ssa-unused-1.c

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index ed811d103a5..cf3098749c0 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -2755,6 +2755,10 @@  constant.
 
 @item lgccjit
 Target supports -lgccjit, i.e. libgccjit.so can be linked into jit tests.
+
+@item __OPTIMIZE__
+Optimizations are enabled (@code{__OPTIMIZE__}) per the current
+compiler flags.
 @end table
 
 @subsubsection Local to tests in @code{gcc.target/i386}
diff --git a/gcc/testsuite/gcc.c-torture/compile/ssa-unused-1.c b/gcc/testsuite/gcc.c-torture/compile/ssa-unused-1.c
new file mode 100644
index 00000000000..e8fb93c74c2
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/ssa-unused-1.c
@@ -0,0 +1,15 @@ 
+/* This is just to exercise the '__OPTIMIZE__' DejaGnu selector.  */
+
+/* { dg-do "assemble" } */
+/* { dg-additional-options "-fdump-tree-ssa" } */
+
+void f()
+{
+  int unused = 3;
+  (void) &unused;
+}
+
+/* { dg-final { scan-tree-dump-not {No longer having address taken: unused} ssa { target { ! __OPTIMIZE__ } } } }
+   { dg-final { scan-tree-dump-times {No longer having address taken: unused} 1 ssa { target __OPTIMIZE__ } } } */
+/* { dg-final { scan-tree-dump-not {Now a gimple register: unused} ssa { target { ! __OPTIMIZE__ } } } }
+   { dg-final { scan-tree-dump-times {Now a gimple register: unused} 1 ssa { target __OPTIMIZE__ } } } */
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 8192da5ec9f..849f1bbeda5 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -11103,3 +11103,13 @@  proc check_effective_target_lra { } {
     return 1
 }
 
+# Test whether optimizations are enabled ('__OPTIMIZE__') per the
+# 'current_compiler_flags' (thus don't cache).
+
+proc check_effective_target___OPTIMIZE__ {} {
+    return [check_no_compiler_messages_nocache __OPTIMIZE__ assembly {
+	#ifndef __OPTIMIZE__
+	# error nein
+	#endif
+    } [current_compiler_flags]]
+}
-- 
2.25.1