[LLVMdev] confused about llvm.memory.barrier

Luke Dalessandro luked at cs.rochester.edu
Thu Sep 25 07:28:20 PDT 2008


When I request a write-before-read memory barrier on x86 I would expect 
to get an assembly instruction that would enforce this ordering (mfence, 
xchg, cas), but it just turns into a nop.

  1. ; ModuleID = 'test.bc'
  2. target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-
i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
  3. target triple = "i686-apple-darwin9"
  4. @a = external global i32                ; <i32*> [#uses=1]
  5. @b = external global i32                ; <i32*> [#uses=1]
  6.
  7. define i32 @_Z3foov() nounwind {
  8. entry:
  9.          store i32 1, i32* @a, align 4
10.          tail call void @llvm.memory.barrier(i1 true, i1 true, \
                                                  i1 true, i1 true, \
                                                  i1 false)
11.          %0 = load i32* @b, align 4              ; <i32> [#uses=1]
12.          ret i32 %0
13. }
14.
15. declare void @llvm.memory.barrier(i1, i1, i1, i1, i1) nounwind

compiled with:

1. llc -mcpu=core2 -mattr=+sse2,+sse3 -f -o test.s test.bc

becomes

  1.	.text
  2.	.align	4,0x90
  3.	.globl	__Z3foov
  4. __Z3foov:
  5.	movl	L_a$non_lazy_ptr, %eax
  6.	movl	$1, (%eax)
  7.	nop
  8.	movl	L_b$non_lazy_ptr, %eax
  9.	movl	(%eax), %eax
10.	ret
11.
12.	.section __IMPORT,__pointers,non_lazy_symbol_pointers
13. L_a$non_lazy_ptr:
14.	.indirect_symbol _a
15.	.long	0
16. L_b$non_lazy_ptr:
17.	.indirect_symbol _b
18.	.long	0
19.	.subsections_via_symbols

Is the problem related to the fact that I get i386 from uname -m? If so, 
how can I tell override this setting during compilation?

Thanks,
Luke



More information about the llvm-dev mailing list