[llvm-bugs] [Bug 39225] New: Failure to use condition to simplify branch

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Oct 9 06:31:41 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=39225

            Bug ID: 39225
           Summary: Failure to use condition to simplify branch
           Product: new-bugs
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: llvm-dev at redking.me.uk
                CC: andrea.dibiagio at gmail.com, filcab at gmail.com,
                    llvm-bugs at lists.llvm.org, llvm-bugzilla at jfbastien.com

https://godbolt.org/z/I7HTBx

void test(int &v, int i) {
  if (v == i)
    v = i;
}

clang -O3 -march=btver2

_Z4testRii: # @_Z4testRii
  cmpl %esi, (%rdi)
  jne .LBB0_2
  movl %esi, (%rdi)
.LBB0_2:
  retq

How come we couldn't remove this store and just return?

More complicated could also avoid some work:

void test1(int &v, int i, bool replace) {
  if (replace || v == i)
    v = i;
}

_Z5test1Riib: # @_Z5test1Riib
  cmpl %esi, (%rdi)
  je .LBB1_2
  testb %dl, %dl
  jne .LBB1_2
  retq
.LBB1_2:
  movl %esi, (%rdi)
  retq

How come we couldn't just store based on the test?

int test3(int &v, int i, bool replace) {
  if (replace || v == i) {
    v = i;
    return 1;
  }
  return 0;
}

_Z5test3Riib: # @_Z5test3Riib
  cmpl %esi, (%rdi)
  je .LBB2_2
  xorl %eax, %eax
  testb %dl, %dl
  jne .LBB2_2
  retq
.LBB2_2:
  movl $1, %eax
  movl %esi, (%rdi)
  retq

Trickier, but we could avoid the store and just set the returncode:

_Z5test3Riib: # @_Z5test3Riib
  cmpl %esi, (%rdi)
  je .LBB2_3
  xorl %eax, %eax
  testb %dl, %dl
  jne .LBB2_2
  retq
.LBB2_2:
  movl %esi, (%rdi)
.LBB2_3:
  movl $1, %eax
  retq

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20181009/8c86e641/attachment.html>


More information about the llvm-bugs mailing list