gcc-xtensa icon indicating copy to clipboard operation
gcc-xtensa copied to clipboard

ICE, insn does not satisfy its constraints

Open igrr opened this issue 5 years ago • 14 comments
trafficstars

Recently we ran into this issue on a couple of programs, when compiling code which uses floating point at -O2 optimization level:

$ xtensa-esp32-elf-gcc -c test.c  -mlongcalls -O2 -Wall -Werror -Wextra -Wpedantic -fdump-rtl-all
test.c: In function 'd':
test.c:15:1: error: insn does not satisfy its constraints:
 }
 ^
(insn 74 27 19 4 (set (reg:SF 19 f0 [orig:43 iftmp$0_6 ] [43])
        (mem/u/c:SF (symbol_ref/u:SI ("*.LC0") [flags 0x2]) [0  S4 A32])) "test.c":11 47 {movsf_internal}
     (nil))
during RTL pass: postreload
dump file: test.c.279r.postreload
test.c:15:1: internal compiler error: in extract_constrain_insn, at recog.c:2210

test.c (as minimal as i could c-reduce it):

extern unsigned char a();
extern float b;
extern unsigned char c, h;

void d(signed char unused)
{
  (void) unused;
  const unsigned char e = a();
  for (unsigned char f = c; f; f++) {
    for (unsigned char g = 0; g <= h; g++) {
      b = e ? b : 0;
      d(f);
    }
  }
}

I'm slowly learning my way through the RTL dumps, hoping to find the cause, but wanted to post just in case there is any obvious issue here.

GCC branch I'm using is https://github.com/espressif/gcc/tree/esp_based_on_8_4_0 (a few patches on top of GCC 8.4).

igrr avatar Nov 20 '20 20:11 igrr

Thanks for the report and reproducer. I can reproduce it. Looking at it.

jcmvbkbc avatar Nov 20 '20 20:11 jcmvbkbc

AFAICS movsf_internal pattern for xtensa does not have suitable constraints to match loading SF mode constant from a literal pool into an FP register, that's what offending RTL pattern tries to do. I'm not sure how to fix it properly yet. I guess movsf_internal need to be split into patterns with more restrictive predicates that don't allow loading FP registers from memory designated by symbol. Looking into it...

jcmvbkbc avatar Nov 22 '20 19:11 jcmvbkbc

Hi, is there any update on this? I've also faced this when compiling ulab transform.c:67, movsf_internal, with esp-idf 3.3.5

Thank you.

bhcuong2008 avatar Aug 12 '21 04:08 bhcuong2008

Facing the same issue with ESP-IDF v5.2.1 when trying to compile ThorVG for ESP32-S3.

kisvegabor avatar Mar 13 '24 14:03 kisvegabor

@kisvegabor As a workaround, please try adding -fno-if-conversion (https://github.com/espressif/esp-idf/issues/11696#issuecomment-1596208414)

igrr avatar Mar 13 '24 18:03 igrr

I didn't help in my case, however https://github.com/espressif/esp-idf/issues/11696#issuecomment-1596208414 suggests that it's any optimization issue. So I added

set_source_files_properties(components/lvgl/src/libts/thorvg/tvgSwImage.cpp PROPERTIES COMPILE_FLAGS "-O0")

but it didn't help either.

However with -O0 optimization in menuconfig it worked. It seems set_source_files_properties has no affect. I've tried with absolute path too.

kisvegabor avatar Mar 13 '24 21:03 kisvegabor

Most likely you are not using the set_source_files_properties command in the same directory where the library containing the file is defined.

From CMake manual:

By default, source file properties are only visible to targets added in the same directory (CMakeLists.txt).

If you give a pointer to the branch where you have tried using set_source_files_properties, I can suggest a way to fix this.

igrr avatar Mar 13 '24 23:03 igrr

Most likely you are not using the set_source_files_properties command in the same directory where the library containing the file is defined.

Ah, I didn't know that. Here is my lvgl forg with ThorVG included: https://github.com/kisvegabor/lvgl_upstream/tree/demo/ebike

It's required to add add_compile_options("-Wno-dangling-pointer") due to a ThorVG warning.

kisvegabor avatar Mar 14 '24 13:03 kisvegabor