]> granicus.if.org Git - llvm/commit
[X86] Dont run combineSetCCAtomicArith() when the cmp has multiple uses
authorHans Wennborg <hans@hanshq.net>
Wed, 11 Jan 2017 00:49:54 +0000 (00:49 +0000)
committerHans Wennborg <hans@hanshq.net>
Wed, 11 Jan 2017 00:49:54 +0000 (00:49 +0000)
commitb8cd3bb4751c78067022acacaa300b8f55db643d
tree506d81d6f25d176c08e7f808f09dd92c1dbf152b
parent7249f505bd3da35bc4a65dc31c9d0903da7602b2
[X86] Dont run combineSetCCAtomicArith() when the cmp has multiple uses

We would miscompile the following:

  void g(int);
  int f(volatile long long *p) {
    bool b = __atomic_fetch_add(p, 1, __ATOMIC_SEQ_CST) < 0;
    g(b ? 12 : 34);
    return b ? 56 : 78;
  }

into

  pushq   %rax
  lock            incq    (%rdi)
  movl    $12, %eax
  movl    $34, %edi
  cmovlel %eax, %edi
  callq   g(int)
  testq   %rax, %rax   <---- Bad.
  movl    $56, %ecx
  movl    $78, %eax
  cmovsl  %ecx, %eax
  popq    %rcx
  retq

because the code failed to take into account that the cmp has multiple
uses, replaced one of them, and left the other one comparing garbage.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291630 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/X86/X86ISelLowering.cpp
test/CodeGen/X86/atomic-eflags-reuse.ll