register allocation problems in trunk with IMPLICIT_DEF


Recently code using IMPLICIT_DEF and INSERT_SUBREG started to break:


%vreg10 = INSERT_SUBREG %vreg9, %vreg1, hi

%vreg12 = sub %vreg10, %vreg11


%vreg10 = IMPLICIT_DEF

%vreg10:hi = COPY %vreg1

%vreg12 = sub %vreg10, %vreg11


%vreg10:hi<def,read-undef> = COPY %vreg1, %vreg10

%vreg12 = sub %vreg10, %vreg11


%vreg10:hi<def,read-undef> = COPY %a1_h

%vreg12 = sub %vreg10, %vreg11


%a2_h = COPY %a1_h

%a2 = sub %a2, %a3

*** Bad machine code: Using an undefined physical register ***

  • function: array

  • basic block: 0x43ac7d0 (BB#0)

  • instruction: %a2 = sub %a2, %a3<kill

  • operand 1: %a2

This all worked well before. Is there a change somewhere in the framework that will make the code on top wrong?


This looks like a bug in the register allocator you are using. There should have been an %a2 operand added to the copy instruction when rewriting virtual registers to physical registers.

Please file a PR, preferably with a test case for an in-target tree. Don’t forget to state which register allocator you are using.


I used llvm-stress to find a similar problem on x86-64. See

BTW, llvm-stress is a great tool!

/Patrik Hägglund

Thanks for the quick respons. Problem solved!