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

r164281 introduces a lot of errors to X86 atomic lowering

Open llvmbot opened this issue 13 years ago • 8 comments

Bugzilla Link 15355
Resolution FIXED
Resolved on Mar 08, 2013 22:35
Version trunk
OS All
Reporter LLVM Bugzilla Contributor
CC @darkbuck

Extended Description

The following tests show errors with the verifier turned on:

LLVM :: CodeGen/X86/atomic-dagsched.ll
LLVM :: CodeGen/X86/atomic-load-store-wide.ll
LLVM :: CodeGen/X86/atomic-minmax-i6432.ll
LLVM :: CodeGen/X86/atomic16.ll
LLVM :: CodeGen/X86/atomic32.ll
LLVM :: CodeGen/X86/atomic64.ll
LLVM :: CodeGen/X86/atomic6432.ll
LLVM :: CodeGen/X86/atomic8.ll
LLVM :: CodeGen/X86/atomic_op.ll

Here's an example from atomic64.ll:

After ExpandISelPseudos

Machine code for function atomic_fetch_and64: SSA

BB#0: derived from LLVM BB %0 %vreg0 = MOV64ri64i32 5; GR64:%vreg0 %vreg1 = MOV64rm %RIP, 1, %noreg, ga:@sc64[TF=5], %noreg; mem:LD8[GOT] GR64:%vreg1 LOCK_AND64mi8 %vreg1, 1, %noreg, 0, %noreg, 3, %EFLAGS<imp-def,dead>; mem:Volatile LDST8[@sc64] GR64:%vreg1 %RAX = MOV64rm %vreg1, 1, %noreg, 0, %noreg; mem:Volatile LDST8[@sc64] GR64:%vreg1 Successors according to CFG: BB#1

BB#1: derived from LLVM BB %0 Live Ins: %RAX Predecessors according to CFG: BB#0 BB#1 %vreg3 = COPY %RAX; GR64:%vreg3 %vreg4<def,tied1> = AND64rr %vreg0, %vreg3, %EFLAGS; GR64:%vreg4,%vreg0,%vreg3 %RAX = COPY %vreg3; GR64:%vreg3 LCMPXCHG64 %vreg1, 1, %noreg, 0, %noreg, %vreg4, %RAX, %EFLAGS, %RAX; mem:Volatile LDST8[@sc64] GR64:%vreg1,%vreg4 JNE_4 <BB#1>, %EFLAGS Successors according to CFG: BB#1 BB#2

BB#2: derived from LLVM BB %0 Live Ins: %RAX Predecessors according to CFG: BB#1 %vreg2 = COPY %RAX; GR64:%vreg2 LOCK_AND64mr %vreg1, 1, %noreg, 0, %noreg, %vreg2, %EFLAGS<imp-def,dead>; mem:Volatile LDST8[@sc64] GR64:%vreg1,%vreg2 RET

End machine code for function atomic_fetch_and64.

*** Bad machine code: Missing mayStore flag ***

  • function: atomic_fetch_and64
  • basic block: BB#0 (0x7fdff182ffa0)
  • instruction: %RAX = MOV64rm %vreg1, 1, %noreg, 0, %noreg; mem:Volatile LDST8[@sc64] GR64:%vreg1

*** Bad machine code: MBB has allocable live-in, but isn't entry or landing-pad. ***

  • function: atomic_fetch_and64
  • basic block: BB#1 (0x7fdff1830830)

*** Bad machine code: MBB has allocable live-in, but isn't entry or landing-pad. ***

  • function: atomic_fetch_and64
  • basic block: BB#2 (0x7fdff18308d8) LLVM ERROR: Found 3 machine code errors.

llvmbot avatar Feb 25 '13 22:02 llvmbot

fixed in r176538 and r176580.

darkbuck avatar Mar 09 '13 06:03 darkbuck

revised patch is submitted at http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130304/167520.html for review

extra register copies are removed in the revised patch.

darkbuck avatar Mar 05 '13 01:03 darkbuck

Cloned to rdar://13333663.

llvmbot avatar Mar 04 '13 01:03 llvmbot

The register allocator is not required to respect live-ins/outs of allocable physical registers that are inserted prior to register allocator, hence the verifier error.

llvmbot avatar Feb 26 '13 00:02 llvmbot

Hi Cameron

I don't understand the rule of "bad machine code". Why a live in register cannot be added in MBB if the generated code guarantee all BBs into it will prepare that live in register?

darkbuck avatar Feb 25 '13 23:02 darkbuck

I didn't actually run any execution tests with this patch. Adding the extra copies in also regresses codegen quality slightly.

llvmbot avatar Feb 25 '13 22:02 llvmbot

Proposed patch

llvmbot avatar Feb 25 '13 22:02 llvmbot

On the wide atomics there is another problem of kill flags being duplicated, e.g. from atomic-load-store-wide.ll:

After ExpandISelPseudos

Machine code for function test1: SSA

Frame Objects: fi#-3: size=4, align=8, fixed, at location [SP+12] fi#-2: size=4, align=4, fixed, at location [SP+8] fi#-1: size=4, align=16, fixed, at location [SP+4]

BB#0: derived from LLVM BB %0 %vreg0 = MOV32rm <fi#-2>, 1, %noreg, 0, %noreg; mem:LD4[FixedStack-2] GR32:%vreg0 %vreg1 = MOV32rm <fi#-2>, 1, %noreg, 4, %noreg; mem:LD4[FixedStack-2+4] GR32:%vreg1 %vreg2 = MOV32rm <fi#-1>, 1, %noreg, 0, %noreg; mem:LD4FixedStack-1 GR32:%vreg2 %EAX = MOV32rm %vreg2, 1, %noreg, 0, %noreg; mem:Volatile ST8[%ptr] GR32:%vreg2 %EDX = MOV32rm %vreg2, 1, %noreg, 4, %noreg; mem:Volatile ST8[%ptr] GR32:%vreg2 Successors according to CFG: BB#1

BB#1: derived from LLVM BB %0 Live Ins: %EAX %EDX Predecessors according to CFG: BB#0 BB#1 %vreg5 = COPY %EAX; GR32:%vreg5 %vreg6 = COPY %EDX; GR32:%vreg6 %vreg7 = MOV32rr %vreg0; GR32:%vreg7,%vreg0 %vreg8 = MOV32rr %vreg1; GR32:%vreg8,%vreg1 %EAX = COPY %vreg5; GR32:%vreg5 %EDX = COPY %vreg6; GR32:%vreg6 %EBX = COPY %vreg7; GR32:%vreg7 %ECX = COPY %vreg8; GR32:%vreg8 LCMPXCHG8B %vreg2, 1, %noreg, 0, %noreg, %EAX, %EDX, %EFLAGS, %EAX, %EBX, %ECX, %EDX; mem:Volatile ST8[%ptr] GR32:%vreg2 JNE_4 <BB#1>, %EFLAGS Successors according to CFG: BB#1 BB#2

BB#2: derived from LLVM BB %0 Live Ins: %EAX %EDX Predecessors according to CFG: BB#1 %vreg4 = COPY %EDX; GR32:%vreg4 %vreg3 = COPY %EAX; GR32:%vreg3 RET

End machine code for function test1.

*** Bad machine code: Missing mayStore flag ***

  • function: test1
  • basic block: BB#0 (0x7fa319033ba0)
  • instruction: %EAX = MOV32rm %vreg2, 1, %noreg, 0, %noreg; mem:Volatile ST8[%ptr] GR32:%vreg2

*** Bad machine code: Missing mayStore flag ***

  • function: test1
  • basic block: BB#0 (0x7fa319033ba0)
  • instruction: %EDX = MOV32rm %vreg2, 1, %noreg, 4, %noreg; mem:Volatile ST8[%ptr] GR32:%vreg2

*** Bad machine code: Using a killed virtual register ***

  • function: test1
  • basic block: BB#0 (0x7fa319033ba0)
  • instruction: %EDX = MOV32rm %vreg2, 1, %noreg, 4, %noreg; mem:Volatile ST8[%ptr] GR32:%vreg2
  • operand 1: %vreg2

*** Bad machine code: MBB has allocable live-in, but isn't entry or landing-pad. ***

  • function: test1
  • basic block: BB#1 (0x7fa319034470)

*** Bad machine code: MBB has allocable live-in, but isn't entry or landing-pad. ***

  • function: test1
  • basic block: BB#1 (0x7fa319034470)

*** Bad machine code: MBB has allocable live-in, but isn't entry or landing-pad. ***

  • function: test1
  • basic block: BB#2 (0x7fa319034518)

*** Bad machine code: MBB has allocable live-in, but isn't entry or landing-pad. ***

  • function: test1
  • basic block: BB#2 (0x7fa319034518)

*** Bad machine code: Virtual register killed in block, but needed live out. ***

  • function: test1
  • basic block: BB#0 (0x7fa319033ba0) Virtual register %vreg2 is used after the block.

*** Bad machine code: Virtual register killed in block, but needed live out. ***

  • function: test1
  • basic block: BB#1 (0x7fa319034470) Virtual register %vreg2 is used after the block.

*** Bad machine code: Virtual register def doesn't dominate all uses. ***

  • function: test1
  • basic block: BB#0 (0x7fa319033ba0)
  • instruction: %vreg2 = MOV32rm <fi#-1>, 1, %noreg, 0, %noreg; mem:LD4FixedStack-1 GR32:%vreg2

llvmbot avatar Feb 25 '13 22:02 llvmbot