[PATCH] x86 NaCl: Emit LAHF/SAHF instead of PUSHF/POPF

JF Bastien jfb at chromium.org
Fri Dec 19 14:56:24 PST 2014


Remove the NaCl specificity, and never emit PUSHF/POPF. Update the test accordingly.

There now seems to be a bug with the code generation in x86-64 for `test_feed_cmov`. The following gets generated:

  test_feed_cmov:
  	pushq	%r14
  	pushq	%rbx
  	pushq	%rax
  	movl	%edx, %ebx
  	movl	%esi, %eax
  	lock
  	cmpxchgl	%ebx, (%rdi)
  	seto	%al
  	lahf
  	movq	%rax, %r14
  	callq	foo
  	movq	%r14, %rax
  	addb	$127, %al
  	sahf
  	cmovel	%ebx, %eax
  	addq	$8, %rsp
  	popq	%rbx
  	popq	%r14
  	retq

The bitcode:

  define i32 @test_feed_cmov(i32* %addr, i32 %desired, i32 %new) {
    %res = cmpxchg i32* %addr, i32 %desired, i32 %new seq_cst seq_cst
    %success = extractvalue { i32, i1 } %res, 1
    %rhs = call i32 @foo()
    %ret = select i1 %success, i32 %new, i32 %rhs
    ret i32 %ret
  }

IIUC it's correctly returning `%ebx` (`%new`) on success but on failure it's returning `%eax` which is clobbered 3 times after `callq` sets it. I think `CMOV`'s use/def isn't annotated properly:

  	%EAX<def,tied1> = CMOVE32rr %EAX<kill,tied0>, %EBX<kill>, %EFLAGS<imp-use>

I'm trying to figure out the dark magic that tablegen conjured into `X86InstrCMovSetCC.td`, and which incantation would nullify this powerful spell.


http://reviews.llvm.org/D6629

Files:
  lib/Target/X86/X86InstrInfo.cpp
  test/CodeGen/X86/cmpxchg-clobber-flags.ll

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D6629.17522.patch
Type: text/x-patch
Size: 8478 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141219/0c4167b6/attachment.bin>


More information about the llvm-commits mailing list