`insn does not satisfy its constraints` when compiling a simple program.

2020-04-18 Thread Joe via Gcc

Hello,

I am working on writing a backend for a new architecture but I have 
encountered a problem.


When I try to compile the following simple program with -O0 (note: this 
problem does not occur when optimizations are enabled):


int main()
{
int a = 10;
a++;
}

I get this error:

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

Based on what the error message says the problem seems to be with the 
constraints in the definition of addsi3. Here is the definition of 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")

Here is the definition for the 'I' constraint:

(define_constraint "I"
  "A 30-bit immediate."
  (and (match_code "const_int")
   (match_test "ival >= -536870912 && ival <= 536870911")))

The program compiles successfully if the constraints in the definition 
of addsi3 are removed.


If more specific information is needed please let me know and I will try 
provide it.


Sorry if this is not the best place to ask this question, I was not sure 
where to ask it. I had previously asked it on StackOverflow but with no 
luck.


Thanks in advance.

Joe Legg


Re: `insn does not satisfy its constraints` when compiling a simple program.

2020-04-23 Thread Joe via Gcc
Hi, thanks for the response, I've given debugging it a try but I cannot 
figure out what is causing it to fail. It's probably just my 
inexperience. Thanks for the input, it's very much appreciated.


Cheers,
Joe

On 20/04/2020 19:43, Jim Wilson wrote:

On Sat, Apr 18, 2020 at 8:45 AM Joe via Gcc  wrote:

test.c: In function ‘main’:
test.c:5:1: error: insn does not satisfy its constraints:


The constrain_operands function is failing to match the insn to its
constraints.  Try putting a breakpoint there, and stepping through the
code to see what is going wrong.  The function is likely called many
times, so you might need to figure out which call is the failing one
first and only step through that one.

Jim