【发布时间】:2020-07-16 19:33:21
【问题描述】:
我正在为新架构编写 GCC 后端。当我尝试使用-O0 编译以下简单程序时(注意:启用优化时不会出现此错误):
int main()
{
int a = 10;
a++;
}
我收到此错误:
test.c: In function ‘main’:
test.c:5:1: error: insn does not satisfy its constraints:
5 | }
| ^
(insn 8 7 9 (set (reg:SI 12)
(plus:SI (reg:SI 13)
(const_int 1 [0x1]))) "test.c":4:6 1 {addsi3}
(nil))
during RTL pass: final
test.c:5:1: internal compiler error: in final_scan_insn_1, at final.c:3012
0x65f4b2 _fatal_insn(char const*, rtx_def const*, char const*, int, char const*)
../../gcc/gcc/rtl-error.c:108
0x65f4d8 _fatal_insn_not_found(rtx_def const*, char const*, int, char const*)
../../gcc/gcc/rtl-error.c:118
0x5e2fc8 final_scan_insn_1
../../gcc/gcc/final.c:3012
0xa23e0b final_scan_insn(rtx_insn*, _IO_FILE*, int, int, int*)
../../gcc/gcc/final.c:3152
0xa24099 final_1
../../gcc/gcc/final.c:2020
0xa249f2 rest_of_handle_final
../../gcc/gcc/final.c:4658
0xa249f2 execute
../../gcc/gcc/final.c:4736
根据错误消息的内容,问题似乎与addsi3 中的约束有关。这里是addsi3的定义:
(define_insn "addsi3"
[(set (match_operand:SI 0 "register_operand" "=r,r")
(plus:SI (match_operand:SI 1 "register_operand" "r,r")
(match_operand:SI 2 "reg_or_imm_operand" "r,I")))]
"1"
"@
add %0 %1 %2
addi %0 %1 %2")
如果addsi3 的定义中的约束被删除,则程序编译成功。这是I 约束的定义:
(define_constraint "I"
"A 30-bit immediate."
(and (match_code "const_int")
(match_test "ival >= -536870912 && ival <= 536870911")))
这是reg_or_imm_operand谓词的定义。
(define_predicate "reg_or_imm_operand"
(ior (and (match_code "const_int")
(match_test "IN_RANGE (INTVAL (op), -536870912, 536870911)"))
(match_operand 0 "register_operand")))
如果需要更具体的信息,请告诉我,我会编辑问题。
提前致谢。 :)
【问题讨论】:
标签: gcc compilation compiler-construction cross-compiling porting