llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

X86CmovConversion ineffective when debug info is enabled

Open ormris opened this issue 9 years ago • 4 comments

Bugzilla Link 34565
Resolution FIXED
Resolved on Oct 15, 2017 04:02
Version trunk
OS Linux
Attachments LLVM IR repro with debug info, LLVM IR repro without debug info, C++ test case used to generate the IR repros
CC @chandlerc,@RKSimon,@pogo59,@rotateright,@wjristow

Extended Description

rL308142 added a new optimization that converts cmov instructions to combinations of branch and mov instructions when the branch is well predicted

Some of our internal testing highlighted a case where this optimization is ineffective when debug info is generated. That is, when debug info is enabled, the cmov instruction is still generated.

A reduced IR repro is attached, both with and without debug info. Also, I've included the C++ file that was used to generate both of them.

Reproduce using: $ clang -O2 -c g.ll ; objdump -d --no-show-raw-insn g.o > g.dis $ clang -O2 -c no_g.ll ; objdump -d --no-show-raw-insn no_g.o > no_g.dis $ sdiff -w74 g.dis no_g.dis

g.o:     file format elf64-x86-64   |   no_g.o:     file format elf64-x86-


Disassembly of section .text.main:      Disassembly of section .text.main:

0000000000000000 <main>:                0000000000000000 <main>:
   0:   push   %rbp                        0:   push   %rbp
   1:   mov    %rsp,%rbp                   1:   mov    %rsp,%rbp
   4:   push   %r15                        4:   push   %r15
   6:   push   %r14                        6:   push   %r14
   8:   push   %r12                        8:   push   %r12
   a:   push   %rbx                        a:   push   %rbx
   b:   mov    $0xa,%r14d           |      b:   mov    $0xa,%r15d
  11:   xor    %ebx,%ebx            |     11:   xor    %r12d,%r12d
  13:   lea    0x0(%rip),%r15       |     14:   lea    0x0(%rip),%r14
  1a:   nopw   0x0(%rax,%rax,1)     |     1b:   nopl   0x0(%rax,%rax,1)
  20:   lea    (%r14,%rbx,1),%r12d  |     20:   lea    (%r15,%r12,1),%ebx
  24:   callq  29 <main+0x29>             24:   callq  29 <main+0x29>
  29:   cltq                              29:   cltq

2b: cmp %rax,(%r15,%r12,8) | 2b: cmp %rax,(%r14,%rbx,8) 2f: cmovae %r12d,%r14d | 2f: jb 40 <main+0x40> 33: cmovb %r12d,%ebx | 31: mov %ebx,%r15d 37: cmp %r14d,%ebx | 34: cmp %r15d,%r12d 3a: jb 20 <main+0x20> | 37: jb 20 <main+0x20> 3c: xor %eax,%eax | 39: jmp 48 <main+0x48> 3e: pop %rbx | 3b: nopl 0x0(%rax,%rax,1) 3f: pop %r12 | 40: mov %ebx,%r12d 41: pop %r14 | 43: cmp %r15d,%r12d 43: pop %r15 | 46: jb 20 <main+0x20> 45: pop %rbp | 48: xor %eax,%eax 46: retq | 4a: pop %rbx > 4b: pop %r12 > 4d: pop %r14 > 4f: pop %r15 > 51: pop %rbp > 52: retq $

ormris avatar Sep 12 '17 00:09 ormris

Fix was committed: https://reviews.llvm.org/rL315851

llvmbot avatar Oct 15 '17 11:10 llvmbot

Thanks! I'll take a look.

ormris avatar Sep 30 '17 00:09 ormris

Fix was uploaded for review in https://reviews.llvm.org/D38359.

llvmbot avatar Sep 28 '17 14:09 llvmbot

The reason is that when -g is enabled DBG instructions were generated between the two CMOV instructions. The X86-CMOV-converter pass does not support non-consecutive CMOV instructions that uses/belong to the same EFLAGS value.

%vreg2<def,tied1> = CMOVB32rr %vreg6, %vreg1, %EFLAGS DBG_VALUE %vreg2, %noreg, !"b", ; GR32:%vreg2 line no:7 DBG_VALUE %vreg2, %noreg, !"b", ; GR32:%vreg2 line no:7 %vreg3<def,tied1> = CMOVB32rr %vreg0, %vreg6, %EFLAGS

I will check if we can actually ignore these DBG instructions and apply the optimization in such case as well.

Thanks for reporting the issue.

llvmbot avatar Sep 13 '17 10:09 llvmbot