[Patch, testsuite] Re: [Patch, updated] Make emulated TLS lto-friendly.

IainS developer@sandoe-acoustics.co.uk
Thu Jul 8 11:59:00 GMT 2010


On 8 Jul 2010, at 10:25, Richard Guenther wrote:

> On Thu, Jul 8, 2010 at 1:22 AM, Richard Henderson <rth@redhat.com>  
> wrote:
>
>> Finally, as a follow-up, I think the alias oracle needs to be  
>> taught what
>> __builtin_emutls_get_address does.  Namely, return the address of the
>> associated TLS variable.  This is the only way I can think of to  
>> avoid
>> the optimization penalty that you're introducing because of  
>> exposing the
>> control variable and the function call at this point.
>
> While teaching the oracle about __builtin_emutls_get_address will
> help disambiguating against emutls accesses it will not be enough
> to trigger CSE.  So it would be nice to have a testcase that shows
> we can properly CSE emutls accesses in FRE (in theory it shuld
> work as __builtin_emutls_get_address is const).

How about this?
  (which fails on trunk and passes on the patched version BTW)
(and I've no means to test vx-works so the conditional there is dead- 
reckoning from grepping that code)

Obv. I'm not suggesting it should be applied until trunk would pass.

Iain

testsuite/ChangeLog:

	* lib/target-supports.exp (check_effective_target_tls_native): New.
	* gcc.dg/tls/thr-cse-1.c: New.

---

Index: gcc/testsuite/lib/target-supports.exp
===================================================================
--- gcc/testsuite/lib/target-supports.exp	(revision 161874)
+++ gcc/testsuite/lib/target-supports.exp	(working copy)
@@ -596,6 +596,23 @@ proc check_effective_target_tls_native {} {
      }]
  }

+# Return 1 if *emulated* thread local storage (TLS) is supported, 0  
otherwise.
+
+proc check_effective_target_tls_emulated {} {
+    # VxWorks uses emulated TLS machinery, but with non-standard helper
+    # functions, so we fail to automatically detect it.
+    global target_triplet
+    if { [regexp ".*-.*-vxworks.*" $target_triplet] } {
+	return 1
+    }
+
+    return [check_no_messages_and_pattern tls_emulated "emutls"  
assembly {
+	__thread int i;
+	int f (void) { return i; }
+	void g (int j) { i = j; }
+    }]
+}
+
  # Return 1 if TLS executables can run correctly, 0 otherwise.

  proc check_effective_target_tls_runtime {} {
Index: gcc/testsuite/gcc.dg/tls/thr-cse-1.c
===================================================================
--- gcc/testsuite/gcc.dg/tls/thr-cse-1.c	(revision 0)
+++ gcc/testsuite/gcc.dg/tls/thr-cse-1.c	(revision 0)
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-O1" } */
+/* { dg-require-effective-target tls_emulated } */
+
+/* Test that we only get one call to emutls_get_address when CSE is
+   active.  Note that the var _must_ be initialized for the scan asm
+   to work, since otherwise there will be an initializer which will,
+   correctly, call emutls_get_address.  */
+int foo (int b, int c, int d)
+{
+  static __thread int a=1;
+  a += b;
+  a -= c;
+  a += d;
+  return a;
+}
+
+/* { dg-final { scan-assembler-not  
"emutls_get_address.*emutls_get_address.*" { target { ! *-wrs- 
vxworks } } } } */
+/* { dg-final { scan-assembler-not  
"tls_lookup.*tls_lookup.*" { target *-wrs-vxworks } } } */
+





More information about the Gcc-patches mailing list