Skip to content
This repository was archived by the owner on Sep 2, 2018. It is now read-only.

Assertion failure during compilation to assembly #75

Closed
seanmkauffman opened this issue Apr 22, 2015 · 5 comments
Closed

Assertion failure during compilation to assembly #75

seanmkauffman opened this issue Apr 22, 2015 · 5 comments

Comments

@seanmkauffman
Copy link

llc fourierf.ll -mtriple avr-none -o fourierf.s
llc: /home/seanmk/workspace/llvm/lib/Target/AVR/AVRISelLowering.cpp:1137: virtual llvm::SDValue llvm::AVRTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &, SmallVectorImpl<llvm::SDValue> &) const: Assertion `Mask && "Missing call preserved mask for calling convention"' failed.
#0 0x1ffb4ae llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/seanmk/workspace/llvm/lib/Support/Unix/Signals.inc:424:15
#1 0x1ffc509 PrintStackTraceSignalHandler(void*) /home/seanmk/workspace/llvm/lib/Support/Unix/Signals.inc:483:1
#2 0x1fff5a4 SignalHandler(int) /home/seanmk/workspace/llvm/lib/Support/Unix/Signals.inc:199:60
#3 0x7fb68080a250 __restore_rt (/lib64/libpthread.so.0+0x11250)
#4 0x7fb67f80d795 gsignal (/lib64/libc.so.6+0x38795)
#5 0x7fb67f80ec18 abort (/lib64/libc.so.6+0x39c18)
#6 0x7fb67f806812 (/lib64/libc.so.6+0x31812)
#7 0x7fb67f8068c2 (/lib64/libc.so.6+0x318c2)
#8 0xbdf3cb llvm::AVRTargetLowering::LowerCall(llvm::TargetLowering::CallLoweringInfo&, llvm::SmallVectorImpl<llvm::SDValue>&) const /home/seanmk/workspace/llvm/lib/Target/AVR/AVRISelLowering.cpp:1137:3
#9 0x146f9d8 llvm::TargetLowering::LowerCallTo(llvm::TargetLowering::CallLoweringInfo&) const /home/seanmk/workspace/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:7309:15
#10 0x1471307 llvm::SelectionDAGBuilder::lowerInvokable(llvm::TargetLowering::CallLoweringInfo&, llvm::MachineBasicBlock*) /home/seanmk/workspace/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:5484:3
#11 0x1455a0f llvm::SelectionDAGBuilder::LowerCallTo(llvm::ImmutableCallSite, llvm::SDValue, bool, llvm::MachineBasicBlock*) /home/seanmk/workspace/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:5550:39
#12 0x1443740 llvm::SelectionDAGBuilder::visitCall(llvm::CallInst const&) /home/seanmk/workspace/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:6086:1
#13 0x143ad2e llvm::SelectionDAGBuilder::visit(unsigned int, llvm::User const&) /home/seanmk/workspace/llvm/include/llvm/IR/Instruction.def:165:1
#14 0x143a223 llvm::SelectionDAGBuilder::visit(llvm::Instruction const&) /home/seanmk/workspace/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:967:3
#15 0x149f95c llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::Instruction const>, llvm::ilist_iterator<llvm::Instruction const>, bool&) /home/seanmk/workspace/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:601:5
#16 0x149f3e1 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) /home/seanmk/workspace/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1328:5
#17 0x149d287 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) /home/seanmk/workspace/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:464:33
#18 0xbd041b (anonymous namespace)::AVRDAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) /home/seanmk/workspace/llvm/lib/Target/AVR/AVRISelDAGToDAG.cpp:70:14
#19 0x170d2ee llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /home/seanmk/workspace/llvm/lib/CodeGen/MachineFunctionPass.cpp:40:10
#20 0x1f31100 llvm::FPPassManager::runOnFunction(llvm::Function&) /home/seanmk/workspace/llvm/lib/IR/LegacyPassManager.cpp:1538:23
#21 0x1f31408 llvm::FPPassManager::runOnModule(llvm::Module&) /home/seanmk/workspace/llvm/lib/IR/LegacyPassManager.cpp:1558:16
#22 0x1f31adc (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/seanmk/workspace/llvm/lib/IR/LegacyPassManager.cpp:1616:23
#23 0x1f316be llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/seanmk/workspace/llvm/lib/IR/LegacyPassManager.cpp:1723:16
#24 0x1f320a1 llvm::legacy::PassManager::run(llvm::Module&) /home/seanmk/workspace/llvm/lib/IR/LegacyPassManager.cpp:1756:10
#25 0x751cb0 compileModule(char**, llvm::LLVMContext&) /home/seanmk/workspace/llvm/tools/llc/llc.cpp:351:3
#26 0x750bf2 main /home/seanmk/workspace/llvm/tools/llc/llc.cpp:200:22
#27 0x7fb67f7f9db5 __libc_start_main (/lib64/libc.so.6+0x24db5)
#28 0x74e3c9 _start (/home/seanmk/workspace/avr-work-newer/bin/llc+0x74e3c9)
Stack dump:
0.  Program arguments: /home/seanmk/workspace/avr-work-newer/bin/llc -mtriple=avr-none fourierf.ll -o fourierf.s 
1.  Running pass 'Function Pass Manager' on module 'fourierf.ll'.
2.  Running pass 'AVR DAG->DAG Instruction Selection' on function '@fft_float'

fourierf.ll:

; ModuleID = 'fourierf.c'
target datalayout = "e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8-i64:8:8-f32:8:8-f64:8:8-n8"
target triple = "avr-none-none"

%struct.__file = type { i8*, i8, i8, i16, i16, i16 (i8, %struct.__file*)*, i16 (%struct.__file*)*, i8* }

@.str = private unnamed_addr constant [7 x i8] c"RealIn\00", align 1
@.str1 = private unnamed_addr constant [8 x i8] c"RealOut\00", align 1
@.str2 = private unnamed_addr constant [8 x i8] c"ImagOut\00", align 1
@__iob = external global [0 x %struct.__file*]
@.str3 = private unnamed_addr constant [35 x i8] c"Error in fft_float():  %s == NULL\0A\00", align 1

; Function Attrs: nounwind
define void @fft_float(i16 %NumSamples, i16 %InverseTransform, float* readonly %RealIn, float* readonly %ImagIn, float* %RealOut, float* %ImagOut) #0 {
entry:
  %tobool = icmp ne i16 %InverseTransform, 0
  %. = select i1 %tobool, double 0xC01921FB54442D18, double 0x401921FB54442D18
  %0 = bitcast float* %RealIn to i8*
  tail call fastcc void @CheckPointer(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i16 0, i16 0))
  %1 = bitcast float* %RealOut to i8*
  tail call fastcc void @CheckPointer(i8* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str1, i16 0, i16 0))
  %2 = bitcast float* %ImagOut to i8*
  tail call fastcc void @CheckPointer(i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str2, i16 0, i16 0))
  %call = tail call i16 @NumberOfBitsNeeded(i16 %NumSamples) #4
  %cmp195 = icmp eq i16 %NumSamples, 0
  br i1 %cmp195, label %for.end94, label %for.body.lr.ph

for.body.lr.ph:                                   ; preds = %entry
  %cmp3 = icmp eq float* %ImagIn, null
  br label %for.body

for.cond7.preheader:                              ; preds = %cond.end
  %cmp8191 = icmp ult i16 %NumSamples, 2
  br i1 %cmp8191, label %for.end94, label %for.body10

for.body:                                         ; preds = %for.body.lr.ph, %cond.end
  %i.0196 = phi i16 [ 0, %for.body.lr.ph ], [ %inc, %cond.end ]
  %call1 = tail call i16 @ReverseBits(i16 %i.0196, i16 %call) #4
  %arrayidx = getelementptr inbounds float, float* %RealIn, i16 %i.0196
  %3 = load float, float* %arrayidx, align 4, !tbaa !1
  %arrayidx2 = getelementptr inbounds float, float* %RealOut, i16 %call1
  store float %3, float* %arrayidx2, align 4, !tbaa !1
  br i1 %cmp3, label %cond.end, label %cond.false

cond.false:                                       ; preds = %for.body
  %arrayidx4 = getelementptr inbounds float, float* %ImagIn, i16 %i.0196
  %4 = load float, float* %arrayidx4, align 4, !tbaa !1
  %conv = fpext float %4 to double
  br label %cond.end

cond.end:                                         ; preds = %for.body, %cond.false
  %cond = phi double [ %conv, %cond.false ], [ 0.000000e+00, %for.body ]
  %conv5 = fptrunc double %cond to float
  %arrayidx6 = getelementptr inbounds float, float* %ImagOut, i16 %call1
  store float %conv5, float* %arrayidx6, align 4, !tbaa !1
  %inc = add nuw i16 %i.0196, 1
  %cmp = icmp ult i16 %inc, %NumSamples
  br i1 %cmp, label %for.body, label %for.cond7.preheader

for.body10:                                       ; preds = %for.cond7.preheader, %for.end92
  %BlockSize.0193 = phi i16 [ %shl, %for.end92 ], [ 2, %for.cond7.preheader ]
  %BlockEnd.0192 = phi i16 [ %BlockSize.0193, %for.end92 ], [ 1, %for.cond7.preheader ]
  %conv11 = uitofp i16 %BlockSize.0193 to double
  %div = fdiv double %., %conv11
  %mul = fmul double %div, -2.000000e+00
  %call12 = tail call double @sin(double %mul) #5
  %sub13 = fsub double -0.000000e+00, %div
  %call14 = tail call double @sin(double %sub13) #5
  %call16 = tail call double @cos(double %mul) #5
  %cos = tail call double @cos(double %div)
  %mul19 = fmul double %cos, 2.000000e+00
  %cmp29182 = icmp eq i16 %BlockEnd.0192, 0
  br label %for.cond28.preheader

for.cond28.preheader:                             ; preds = %for.body10, %for.inc90
  %i.1190 = phi i16 [ 0, %for.body10 ], [ %add91, %for.inc90 ]
  br i1 %cmp29182, label %for.inc90, label %for.body31

for.body31:                                       ; preds = %for.cond28.preheader, %for.body31
  %j.0188 = phi i16 [ %inc87, %for.body31 ], [ %i.1190, %for.cond28.preheader ]
  %ai.sroa.4.0187 = phi double [ %sub44, %for.body31 ], [ %call14, %for.cond28.preheader ]
  %ai.sroa.8.0186 = phi double [ %ai.sroa.4.0187, %for.body31 ], [ %call12, %for.cond28.preheader ]
  %n.0185 = phi i16 [ %inc88, %for.body31 ], [ 0, %for.cond28.preheader ]
  %ar.sroa.4.0184 = phi double [ %sub35, %for.body31 ], [ %cos, %for.cond28.preheader ]
  %ar.sroa.8.0183 = phi double [ %ar.sroa.4.0184, %for.body31 ], [ %call16, %for.cond28.preheader ]
  %mul33 = fmul double %mul19, %ar.sroa.4.0184
  %sub35 = fsub double %mul33, %ar.sroa.8.0183
  %mul42 = fmul double %mul19, %ai.sroa.4.0187
  %sub44 = fsub double %mul42, %ai.sroa.8.0186
  %add = add i16 %j.0188, %BlockEnd.0192
  %arrayidx51 = getelementptr inbounds float, float* %RealOut, i16 %add
  %5 = load float, float* %arrayidx51, align 4, !tbaa !1
  %conv52 = fpext float %5 to double
  %mul53 = fmul double %sub35, %conv52
  %arrayidx55 = getelementptr inbounds float, float* %ImagOut, i16 %add
  %6 = load float, float* %arrayidx55, align 4, !tbaa !1
  %conv56 = fpext float %6 to double
  %mul57 = fmul double %sub44, %conv56
  %sub58 = fsub double %mul53, %mul57
  %mul62 = fmul double %sub35, %conv56
  %mul66 = fmul double %sub44, %conv52
  %add67 = fadd double %mul66, %mul62
  %arrayidx68 = getelementptr inbounds float, float* %RealOut, i16 %j.0188
  %7 = load float, float* %arrayidx68, align 4, !tbaa !1
  %conv69 = fpext float %7 to double
  %sub70 = fsub double %conv69, %sub58
  %conv71 = fptrunc double %sub70 to float
  store float %conv71, float* %arrayidx51, align 4, !tbaa !1
  %arrayidx73 = getelementptr inbounds float, float* %ImagOut, i16 %j.0188
  %8 = load float, float* %arrayidx73, align 4, !tbaa !1
  %conv74 = fpext float %8 to double
  %sub75 = fsub double %conv74, %add67
  %conv76 = fptrunc double %sub75 to float
  store float %conv76, float* %arrayidx55, align 4, !tbaa !1
  %9 = load float, float* %arrayidx68, align 4, !tbaa !1
  %conv79 = fpext float %9 to double
  %add80 = fadd double %sub58, %conv79
  %conv81 = fptrunc double %add80 to float
  store float %conv81, float* %arrayidx68, align 4, !tbaa !1
  %10 = load float, float* %arrayidx73, align 4, !tbaa !1
  %conv83 = fpext float %10 to double
  %add84 = fadd double %add67, %conv83
  %conv85 = fptrunc double %add84 to float
  store float %conv85, float* %arrayidx73, align 4, !tbaa !1
  %inc87 = add i16 %j.0188, 1
  %inc88 = add nuw i16 %n.0185, 1
  %cmp29 = icmp ult i16 %inc88, %BlockEnd.0192
  br i1 %cmp29, label %for.body31, label %for.inc90

for.inc90:                                        ; preds = %for.body31, %for.cond28.preheader
  %add91 = add i16 %i.1190, %BlockSize.0193
  %cmp21 = icmp ult i16 %add91, %NumSamples
  br i1 %cmp21, label %for.cond28.preheader, label %for.end92

for.end92:                                        ; preds = %for.inc90
  %shl = shl i16 %BlockSize.0193, 1
  %cmp8 = icmp ugt i16 %shl, %NumSamples
  br i1 %cmp8, label %for.end94, label %for.body10

for.end94:                                        ; preds = %for.end92, %entry, %for.cond7.preheader
  br i1 %tobool, label %if.then96, label %if.end113

if.then96:                                        ; preds = %for.end94
  %conv97 = uitofp i16 %NumSamples to double
  %cmp99180 = icmp eq i16 %NumSamples, 0
  br i1 %cmp99180, label %if.end113, label %for.body101

for.body101:                                      ; preds = %if.then96, %for.body101
  %i.2181 = phi i16 [ %inc111, %for.body101 ], [ 0, %if.then96 ]
  %arrayidx102 = getelementptr inbounds float, float* %RealOut, i16 %i.2181
  %11 = load float, float* %arrayidx102, align 4, !tbaa !1
  %conv103 = fpext float %11 to double
  %div104 = fdiv double %conv103, %conv97
  %conv105 = fptrunc double %div104 to float
  store float %conv105, float* %arrayidx102, align 4, !tbaa !1
  %arrayidx106 = getelementptr inbounds float, float* %ImagOut, i16 %i.2181
  %12 = load float, float* %arrayidx106, align 4, !tbaa !1
  %conv107 = fpext float %12 to double
  %div108 = fdiv double %conv107, %conv97
  %conv109 = fptrunc double %div108 to float
  store float %conv109, float* %arrayidx106, align 4, !tbaa !1
  %inc111 = add nuw i16 %i.2181, 1
  %cmp99 = icmp ult i16 %inc111, %NumSamples
  br i1 %cmp99, label %for.body101, label %if.end113

if.end113:                                        ; preds = %for.body101, %if.then96, %for.end94
  ret void
}

; Function Attrs: nounwind
define internal fastcc void @CheckPointer(i8* readnone %p, i8* %name) #0 {
entry:
  %cmp = icmp eq i8* %p, null
  br i1 %cmp, label %if.then, label %if.end

if.then:                                          ; preds = %entry
  %0 = load %struct.__file*, %struct.__file** getelementptr inbounds ([0 x %struct.__file*], [0 x %struct.__file*]* @__iob, i16 0, i16 2), align 2, !tbaa !5
  %call = tail call i16 (%struct.__file*, i8*, ...)* @fprintf(%struct.__file* %0, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str3, i16 0, i16 0), i8* %name) #4
  tail call void @exit(i16 1) #6
  unreachable

if.end:                                           ; preds = %entry
  ret void
}

declare i16 @NumberOfBitsNeeded(i16) #1

declare i16 @ReverseBits(i16, i16) #1

; Function Attrs: nounwind readnone
declare double @sin(double) #2

; Function Attrs: nounwind readnone
declare double @cos(double) #2

; Function Attrs: nounwind
declare i16 @fprintf(%struct.__file* nocapture, i8* nocapture readonly, ...) #0

; Function Attrs: noreturn
declare void @exit(i16) #3

attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #2 = { nounwind readnone "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #3 = { noreturn "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #4 = { nounwind }
attributes #5 = { nounwind readnone }
attributes #6 = { noreturn nounwind }

!llvm.ident = !{!0}

!0 = !{!"clang version 3.7.0 (https://github.com/avr-llvm/clang.git 00a0b3863ac817790d9b344da4fc499b71140a7a) (llvm/llvm.git 70f966eb9eb5e2cae5d4f62ae213ae035677efee)"}
!1 = !{!2, !2, i64 0}
!2 = !{!"float", !3, i64 0}
!3 = !{!"omnipotent char", !4, i64 0}
!4 = !{!"Simple C/C++ TBAA"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !3, i64 0}
@seanmkauffman seanmkauffman changed the title Crash during compilation to assembly Assertion failure during compilation to assembly Apr 22, 2015
@dylanmckay
Copy link
Member

This was caused because the AVRRegisterInfo::getCallPreservedMask function was not actually overriding the virtual function it should have been, because the signature had been changed and AVRRegisterInfo::getCallPreservedMask was not qualified with the override keyword, so the problem happened silently.

I have audited all classes in the backend, and added missing override keywords where they were needed.

@dylanmckay
Copy link
Member

Note that when compiling your test case, compilation fails with another error: "instruction selection failed".

This is presumably because the MCU targeted (by default, avr2) does not support the operations used (such as multiplication/division, I'm not sure which).

If you select one of the higher end MCUs (such as avrxmega7, by using llc fourierf.ll -march=avr -mcpu=avrxmega7), instruction selection completes, but another error is hit - #37.

@dylanmckay
Copy link
Member

I have opened up an issue for the instruction selection error - #76.

@seanmkauffman
Copy link
Author

Thanks for the help. FYI, avr-llvm will not compile right now due to an error in the clang branch. I filed an issue. avr-llvm/clang#3

@dylanmckay
Copy link
Member

Now that #37 is fixed, I can run llc on fourierf.ll and it succeeds.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants