Skip to content

Implement support in clang-cl for the /GT option #19551

Open
@llvmbot

Description

@llvmbot
Bugzilla Link 19177
Version unspecified
OS All
Reporter LLVM Bugzilla Contributor
CC @ohmantics,@Bigcheese,@vns-mn,@deadalnix,@filcab,@zmodem,@rnk,@wjristow

Extended Description

The option is defined in
http://msdn.microsoft.com/en-us/library/6e298fy4.aspx

In summary, it means that we cannot assume that the address of a tls doesn't change across a call, since the call might causes a fiber to move to another thread.

This has implications for both IR and codegen. For the IR issue, consider

struct foo {
  int v[10];
};
static __thread struct foo var;
struct foo *h(void) { return &var; }
void f(int *);
void g(int x, int y) {
  for (int i = 0; i < x; ++i) {
    f(&var.v[y]);
  }
}

This currently produces

for.body.lr.ph:
...
%arrayidx = getelementptr inbounds %struct.foo* @var, i64 0, i32 0, i64 %idxprom
br label %for.body

for.body:
...
tail call void @f(i32* %arrayidx)
...
br i1 %exitcond, label %for.end, label %for.body

but the address is not actually loop invariant.

For codegen, consider

static __thread int var;
int *h(void) { return &var; }
void f(int);
void g(void) {
  f(var);
  f(var);
}

We only call __tls_get_addr@PLT once with the local dynamic model.

We chatted a bit about it and it looks like we would need to change clang's IRGen when the option is given to use an intrinsic to get the actual address. Something like

%addr = llvm.get_tls_addr(@var)

so that the optimizers know that %addr can be different in each loop iteration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaclang-cl`clang-cl` driver. Don't use for other compiler partsenhancementImproving things as opposed to bug fixing, e.g. new or missing featureextension:microsoft

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions