avr-llvm / llvm

[MERGED UPSTREAM] AVR backend for the LLVM compiler library
220 stars 21 forks source link

Multiplication instruction selection failure #141

Closed dylanmckay closed 9 years ago

dylanmckay commented 9 years ago

When compiling WMath.cpp from the Arduino core, instruction selection fails with the message:

LLVM ERROR: Cannot select: 0x24bea90: i16 = mulhu 0x24cf830, 0x24cbe10 [ORD=4] [ID=59]
  0x24cf830: i16,glue = subc 0x24cc2d0, 0x24cc660 [ORD=3] [ID=50]
    0x24cc2d0: i16,ch = load 0x24b0480, 0x24c2f40, 0x24c5fb0<LD2[FixedStack-1](align=1)> [ORD=1] [ID=37]
      0x24c2f40: i16 = FrameIndex<-1> [ID=9]
      0x24c5fb0: i16 = undef [ID=10]
    0x24cc660: i16,ch = CopyFromReg 0x24b0480, 0x24c5c20 [ORD=1] [ID=35]
      0x24c5c20: i16 = Register %vreg6 [ID=7]
  0x24cbe10: i16,glue = subc 0x24ca640, 0x24c5e80 [ORD=2] [ID=42]
    0x24ca640: i16,ch = CopyFromReg 0x24b0480, 0x24cab00 [ORD=1] [ID=29]
      0x24cab00: i16 = Register %vreg0 [ID=1]
    0x24c5e80: i16,ch = CopyFromReg 0x24b0480, 0x24c3660 [ORD=1] [ID=31]
      0x24c3660: i16 = Register %vreg2 [ID=3]
In function: _Z3maplllll

WMath.ll.

Compiled with:

llc -march=avr -mcpu=atmega328p -filetype=obj -O0 -o WMath.o WMath.ll 

Tested with aaab572fc38b4438e769e2fd6b91963be11db7b2.

dylanmckay commented 9 years ago

Fixed in 7bdaae542e749df493f8ca35a9858d4b3805f01e.

Now MULHU and MULHS nodes are expanded into UMUL_LOHI and SMUL_LOHI respectively.