This is an archive of the discontinued LLVM Phabricator instance.

[X86][ISel] Lowering llvm.thread.pointer
ClosedPublic

Authored by FreddyYe on Sep 29 2021, 12:15 AM.

Diff Detail

Event Timeline

FreddyYe created this revision.Sep 29 2021, 12:15 AM
FreddyYe requested review of this revision.Sep 29 2021, 12:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 29 2021, 12:15 AM

This patch is to align with gcc's behavior on __builtin_thread_pointer () on Linux. Example output of gcc: https://godbolt.org/z/9oTTW53qe
Related bugzilla of gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96200, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96955

FreddyYe updated this revision to Diff 375794.Sep 29 2021, 12:25 AM

clean test.

pengfei added inline comments.Oct 7 2021, 7:47 AM
llvm/lib/Target/X86/X86ISelLowering.cpp
26770

X86::FS, X86::GS?

26772
26773

We don't use else after return.

26774

Not sure we have to limit it to Linux here. I found other targets don't do this check.
Besides, we already have check in https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGBuiltin.cpp#L5040
If we don't support tls, we won't go here. But if we do, we should return the right thread pointer.

llvm/test/CodeGen/X86/thread_pointer.ll
49

Do we have to use i64? Especially we are testing X32 and X86 at the same time.

LuoYuanke added inline comments.Oct 7 2021, 6:45 PM
llvm/lib/Target/X86/X86ISelLowering.cpp
26770

X86::FS, X86::GS?

Should be X86AS::FS and X86AS::GS.

26771

Not sure about the chain. It accesses memory.

llvm/test/CodeGen/X86/thread_pointer.ll
22

The first entry of the TLS store the pointer of itself. Right?

FreddyYe updated this revision to Diff 378209.Oct 8 2021, 7:32 AM
FreddyYe marked 3 inline comments as done.

Address comments.

FreddyYe marked an inline comment as done.Oct 8 2021, 7:35 AM

Address part of comments. Thanks for review.

llvm/lib/Target/X86/X86ISelLowering.cpp
26774

Yes. X86 supports TLS in many Targets. But what I'm sure is the ELF targets has defined thread pointer on document. See the last comment here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96200

pengfei added inline comments.Oct 9 2021, 1:55 AM
llvm/lib/Target/X86/X86ISelLowering.cpp
26774

I think it makes sense to error out if we are not sure of it. Please add an error test, add fixme there and check x86_64-apple-darwin, x86_64-pc-windows etc.

FreddyYe updated this revision to Diff 378850.Oct 11 2021, 6:52 PM
FreddyYe marked an inline comment as done.

Address comments.

FreddyYe marked an inline comment as done.Oct 11 2021, 6:54 PM
FreddyYe marked an inline comment as done.
pengfei accepted this revision.Oct 11 2021, 6:55 PM

LGTM, thanks.

This revision is now accepted and ready to land.Oct 11 2021, 6:55 PM
This revision was landed with ongoing or failed builds.Oct 11 2021, 8:01 PM
This revision was automatically updated to reflect the committed changes.