Skip to content

Instantly share code, notes, and snippets.

@alexcrichton
Created April 30, 2019 14:46
Show Gist options
  • Save alexcrichton/a9a90412152d04caa7011042aa89b6bf to your computer and use it in GitHub Desktop.
Save alexcrichton/a9a90412152d04caa7011042aa89b6bf to your computer and use it in GitHub Desktop.
target triple = "x86_64-apple-darwin"
@foo = thread_local global i32 0
define i32 @bar() {
start:
%current = load i32, i32* @foo
%eq_one = icmp eq i32 %current, 1
br i1 %eq_one, label %exit, label %store
store:
store i32 1, i32* @foo
br label %exit
exit:
%val = phi i32 [ 2, %start ], [ 3, %store ]
ret i32 %val
}
.section __TEXT,__text,regular,pure_instructions
.globl _bar ## -- Begin function bar
.p2align 4, 0x90
_bar: ## @bar
.cfi_startproc
## %bb.0: ## %start
pushq %rax
.cfi_def_cfa_offset 16
movq _foo@TLVP(%rip), %rdi
callq *(%rdi)
movq %rax, %rcx
movl $2, %eax
cmpl $1, (%rcx)
je LBB0_2
## %bb.1: ## %store
movq _foo@TLVP(%rip), %rdi
callq *(%rdi)
movl $1, (%rax)
movl $3, %eax
LBB0_2: ## %exit
popq %rcx
retq
.cfi_endproc
## -- End function
.tbss _foo$tlv$init, 4, 2 ## @foo
.section __DATA,__thread_vars,thread_local_variables
.globl _foo
_foo:
.quad __tlv_bootstrap
.quad 0
.quad _foo$tlv$init
.subsections_via_symbols
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment