[llvm-bugs] [Bug 41129] New: Regression caused by CodeGenPrepare patch rL354298

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Mar 18 10:56:20 PDT 2019


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

            Bug ID: 41129
           Summary: Regression caused by CodeGenPrepare patch rL354298
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: carrot at google.com
                CC: llvm-bugs at lists.llvm.org

Compile following code with 

opt -codegenprepare -mtriple=x86_64-unknown-linux-gnu -S test3.ll

define void @foo(i64* %p64) {
entry:
  %key = load i64, i64* %p64, align 8
  %cond17 = icmp eq i64 %key, 0
  br i1 %cond17, label %true, label %false

false:
  %andval = and i64 %key, 7
  store i64 %andval, i64* %p64
  br label %exit

true:
  %svalue = add i64 %key, -1
  store i64 %svalue, i64* %p64
  br label %exit

exit:
  ret void
}


Then generate code for x86, then I can get


foo:                                    # @foo
        .cfi_startproc
# %bb.0:                                # %entry
        movq    (%rdi), %rax
        movq    %rax, %rcx                        // Extra copy
        subq    $1, %rcx
        jae     .LBB0_1
# %bb.2:                                # %true
        movq    %rcx, (%rdi)
        retq
.LBB0_1:                                # %false
        andl    $7, %eax
        movq    %rax, (%rdi)
        retq
.Lfunc_end0:
        .size   foo, .Lfunc_end0-foo

An extra copy is generated in the entry block. It is needed for a 2-address ISA
like x86, and the operand has other uses. In this case, the extra COPY is
inserted in BB entry, a SUB is eliminated in BB true, BB entry is executed more
times than BB true, so it is always a lose.

-- 
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/20190318/396007bb/attachment.html>


More information about the llvm-bugs mailing list