llvm.org GIT mirror llvm / 2674d3c
[AVR] Fix a backend bug that left extraneous operands after expansion This patch fixes a bug in the AVR FRMIDX expansion logic. The expansion would leave a leftover operand from the original FRMIDX, but now attached to a MOVWRdRr instruction. The MOVWRdRr instruction did not expect this operand and so LLVM rejected the machine instruction. This would trigger an assertion: Assertion failed: ((isImpReg || Op.isRegMask() || MCID->isVariadic() || OpNo < MCID->getNumOperands() || isMetaDataOp) && "Trying to add an operand to a machine instr that is already done!"), function addOperand, file llvm/lib/CodeGen/MachineInstr.cpp Tim fixed this so that now the FRMIDX is expanded correctly into a well-formed MOVWRdRr. Patch by Tim Neumann git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346117 91177308-0d34-0410-b5e6-96231b3b80d8 Dylan McKay 2 years ago
2 changed file(s) with 49 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
151151 if (MI.getOpcode() == AVR::FRMIDX) {
152152 MI.setDesc(TII.get(AVR::MOVWRdRr));
153153 MI.getOperand(FIOperandNum).ChangeToRegister(AVR::R29R28, false);
154 MI.RemoveOperand(2);
154155
155156 assert(Offset > 0 && "Invalid offset");
156157
0 ; RUN: llc < %s -march=avr | FileCheck %s
1
2 ; The avr-rust bug can be found here:
3 ; https://github.com/avr-rust/rust/issues/112
4 ;
5 ; In this test, the codegen stage generates a FRMIDX
6 ; instruction. Later in the pipeline, the frame index
7 ; gets expanded into a 16-bit MOVWRdRr instruction.
8 ;
9 ; There was a bug in the FRMIDX->MOVWRdRr expansion logic
10 ; that could leave the MOVW instruction with an extraneous
11 ; operand, left over from the original FRMIDX.
12 ;
13 ; This would trigger an assertion:
14 ;
15 ; Assertion failed: ((isImpReg || Op.isRegMask() || MCID->isVariadic() ||
16 ; OpNo < MCID->getNumOperands() || isMetaDataOp) &&
17 ; "Trying to add an operand to a machine instr that is already done!"),
18 ; function addOperand, file llvm/lib/CodeGen/MachineInstr.cpp
19 ;
20 ; The logic has since been fixed.
21
22 ; CHECK-LABEL: "core::str::slice_error_fail"
23 define void @"core::str::slice_error_fail"(i16 %arg) personality i32 (...) addrspace(1)* @rust_eh_personality {
24 start:
25 %char_range = alloca { i16, i16 }, align 1
26 br i1 undef, label %">::unwrap.exit.thread", label %bb11.i.i
27
28 ">::unwrap.exit.thread":
29 br label %"core::char::methods::::len_utf8.exit"
30
31 bb11.i.i:
32 %tmp = bitcast { i16, i16 }* %char_range to i8*
33 %tmp1 = icmp ult i32 undef, 65536
34 %..i = select i1 %tmp1, i16 3, i16 4
35 br label %"core::char::methods::::len_utf8.exit"
36
37 "core::char::methods::::len_utf8.exit":
38 %tmp2 = phi i8* [ %tmp, %bb11.i.i ], [ undef, %">::unwrap.exit.thread" ]
39 %_0.0.i12 = phi i16 [ %..i, %bb11.i.i ], [ 1, %">::unwrap.exit.thread" ]
40 %tmp3 = add i16 %_0.0.i12, %arg
41 store i16 %tmp3, i16* undef, align 1
42 store i8* %tmp2, i8** undef, align 1
43 unreachable
44 }
45
46 declare i32 @rust_eh_personality(...) addrspace(1)
47