avr-llvm / llvm

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

llc: Invalid type for expanded integer failed #220

Closed ghost closed 7 years ago

ghost commented 8 years ago

I'm getting the message:

llc -filetype=asm -march=avr -mcpu=atmega328p output.ll -o output.s

llc output:

lib/CodeGen/SelectionDAG/LegalizeTypes.cpp:824
void llvm::DAGTypeLegalizer::SetExpandedInteger(llvm::SDValue, llvm::SDValue, llvm::SDValue): Assertion `Lo.getValueType() == TLI.getTypeToTransformTo(*DAG.getContext(), Op.getValueType()) && Hi.getValueType() == Lo.getValueType() && "Invalid type for expanded integer"' failed.

output_1.ll code:

; ModuleID = 'mmodule'

define i16 @main() {
entry:
  call void @pinModeO(i16 6)
  %value = alloca i16
  store i16 0, i16* %value
  %0 = load i16, i16* %value
  %cmptmp = icmp eq i16 %0, 255
  %booltmp = uitofp i1 %cmptmp to double
  %1 = fcmp one double 0.000000e+00, %booltmp
  br i1 %1, label %then, label %ifcont

then:                                             ; preds = %entry
  store i16 0, i16* %value
  br label %ifcont

ifcont:                                           ; preds = %then, %entry
  %2 = load i16, i16* %value
  %cmptmp1 = icmp eq i16 %2, 255
  %booltmp2 = uitofp i1 %cmptmp1 to double
  %3 = fcmp one double 0.000000e+00, %booltmp2
  br i1 %3, label %then3, label %ifcont4

then3:                                            ; preds = %ifcont
  store i16 0, i16* %value
  br label %ifcont4

ifcont4:                                          ; preds = %then3, %ifcont
  ret i16 0
}

declare void @pinModeO(i16)

But with this code the error disappear (the second "if" is removed). The output_1.ll is OK when I use x86 llc.

output_2.ll code:

; ModuleID = 'mmodule'

define i16 @main() {
entry:
  call void @pinModeO(i16 6)
  %value = alloca i16
  store i16 0, i16* %value
  %0 = load i16, i16* %value
  %cmptmp = icmp eq i16 %0, 255
  %booltmp = uitofp i1 %cmptmp to double
  %1 = fcmp one double 0.000000e+00, %booltmp
  br i1 %1, label %then, label %ifcont

then:                                             ; preds = %entry
  store i16 0, i16* %value
  br label %ifcont

ifcont:                                           ; preds = %then, %entry
  ret i16 0
}

declare void @pinModeO(i16)

Does anybody know what's the problem?

dylanmckay commented 8 years ago

Would you be able to post the full stacktrace for the assertion error?

dylanmckay commented 8 years ago

Minimised testcase

define void @foo(i16 %a) {
ifcont:
  %cmp_result = icmp eq i16 %a, 255
  %bool_result = uitofp i1 %cmp_result to double
  %result = fcmp one double 0.000000e+00, %bool_result
  br i1 %result, label %then, label %else
then:
  ret void
else:
  ret void
}

An empty stacktrace is given when I run this locally.

dylanmckay commented 8 years ago

Added the testcase in tree

bd648d0c890dfcae4fbf7532d9f6afd9abaaf74b

dylanmckay commented 7 years ago

Looking at llc in a debugger, the operation it is failing on:

t26: i64 = select_cc t2, Constant:i16<255>, Constant:i64<4607182418800017408>, Constant:i64<0>, seteq:ch
dylanmckay commented 7 years ago
(lldb) print Lo.getValueType()
(llvm::EVT) $2 = {
  V = (SimpleTy = i64)
  LLVMTy = 0x0000000000000000
}
(lldb) print Hi.getValueType()
(llvm::EVT) $3 = {
  V = (SimpleTy = Glue)
  LLVMTy = 0x00000000000000
dylanmckay commented 7 years ago

It looks like we are emitting this out of our custom lowering hook.

dylanmckay commented 7 years ago

Fixed in r288905.