Recently I have started playing with machine descriptions in the context of PR109324 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109324). I have nodified MDs (see the attached patch) and got following ICE when I tried to build gcc:

/d/Works/xcomp/gcc-build-stage1/./gcc/xgcc -B/d/Works/xcomp/gcc-build-stage1/./gcc/ -B/usr/local/h8300-elf/bin/ -B/usr/local/h8300-elf/lib/normal/ -isystem /usr/local/h8300-elf/include -isystem /usr/local/h8300-elf/sys-include --sysroot=/d/Works/xcomp/sysroot -g -O2 -mn -O2 -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -W -Wall -Wno-error=narrowing -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -DDF=SF -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -Dinhibit_libc -DDF=SF -I. -I. -I../../.././gcc -I../../../../../gcc/libgcc -I../../../../../gcc/libgcc/. -I../../../../../gcc/libgcc/../gcc -I../../../../../gcc/libgcc/../include -o _powisf2.o -MT _powisf2.o -MD -MP -MF _powisf2.dep -DL_powisf2 -c ../../../../../gcc/libgcc/libgcc2.c -fvisibility=hidden -DHIDE_EXPORTS
D:/Works/gcc/libgcc/libgcc2.c: In function '__powisf2':
D:/Works/gcc/libgcc/libgcc2.c:2574:1: error: unrecognizable insn:
 2574 | }
      | ^
(insn 249 113 250 16 (set (reg:CCZ 12 cc)
        (eq (zero_extract:SI (reg:SI 6 r6 [orig:22 n+-2 ] [22])
                (const_int 1 [0x1])
                (const_int 0 [0]))
            (const_int 0 [0]))) "D:/Works/gcc/libgcc/libgcc2.c":2570:10 -1
     (nil))
during RTL pass: split2
D:/Works/gcc/libgcc/libgcc2.c:2574:1: internal compiler error: in extract_insn, at recog.cc:2882
0x411d6587 internal_error(char const*, ...)
        ../../../gcc/gcc/diagnostic-global-context.cc:517
0x413cf141 fancy_abort(char const*, int, char const*)
        ../../../gcc/gcc/diagnostic.cc:1810
0x413a9562 _fatal_insn(char const*, rtx_def const*, char const*, int, char const*)
        ../../../gcc/gcc/rtl-error.cc:108
0x413a9587 _fatal_insn_not_found(rtx_def const*, char const*, int, char const*)
        ../../../gcc/gcc/rtl-error.cc:116
0x413a84b3 extract_insn(rtx_insn*)
        ../../../gcc/gcc/recog.cc:2882
0x405ef448 extract_insn_cached(rtx_insn*)
        ../../../gcc/gcc/recog.cc:2771
0x402ab098 cleanup_subreg_operands(rtx_insn*)
        ../../../gcc/gcc/final.cc:3068
0x405ed31b split_insn
        ../../../gcc/gcc/recog.cc:3515
0x405f2d97 split_all_insns()
        ../../../gcc/gcc/recog.cc:3583
0x405f2e18 execute
        ../../../gcc/gcc/recog.cc:4507
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
make[4]: *** [Makefile:512: _powisf2.o] Error 1
make[4]: Leaving directory '/d/Works/xcomp/gcc-build-stage1/h8300-elf/normal/libgcc'
make[3]: *** [Makefile:1228: multi-do] Error 1
make[3]: Leaving directory '/d/Works/xcomp/gcc-build-stage1/h8300-elf/libgcc'
make[2]: *** [Makefile:128: all-multi] Error 2
make[2]: Leaving directory '/d/Works/xcomp/gcc-build-stage1/h8300-elf/libgcc'
make[1]: *** [Makefile:12875: all-target-libgcc] Error 2
make[1]: Leaving directory '/d/Works/xcomp/gcc-build-stage1'
make: *** [Makefile:1059: all] Error 2

After a short investigation I have found the offending code:

diff --git a/gcc/config/h8300/testcompare.md b/gcc/config/h8300/testcompare.md
index 694c9e60d4e..3b43381e64a 100644
--- a/gcc/config/h8300/testcompare.md
+++ b/gcc/config/h8300/testcompare.md
@@ -28,7 +28,7 @@
 ;;
 (define_insn ""
   [(set (reg:CCZ CC_REG)
-       (eq (zero_extract:HSI (match_operand:HSI 0 "register_operand" "r")
+       (eq:CCZ (zero_extract:HSI (match_operand:HSI 0 "register_operand" "r")
                              (const_int 1)
                              (match_operand 1 "const_int_operand" "n"))
            (const_int 0)))]

Other changes seem to be fine, i.e. I am able to build gcc and the same set of test cases pases/fails as for unmodified compiler.

MD is a completely new topic to me so I am looking for some hints how to debug the issue. Is it possible that this particular MD is not fully complete?

As a side note I can say that unmodified gcc indeed emits "bit test" instruction for line 2570:
;# ../../../../../gcc/libgcc/libgcc2.c:2570:       if (n % 2)
.LM28:
        btst    #0,r6l  ;#, n
        beq     .L8             ;#,

Best regards,
Jan
 gcc/config/h8300/addsub.md      |  2 +-
 gcc/config/h8300/jumpcall.md    |  8 ++++----
 gcc/config/h8300/testcompare.md | 26 +++++++++++++-------------
 3 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/gcc/config/h8300/addsub.md b/gcc/config/h8300/addsub.md
index 32eba9df67a..f15362594d4 100644
--- a/gcc/config/h8300/addsub.md
+++ b/gcc/config/h8300/addsub.md
@@ -271,7 +271,7 @@ (define_insn "*uaddv"
                             (match_operand:QHSI 2 "register_operand" "r"))
                (match_dup 1)))
    (set (match_operand:QHSI 0 "register_operand" "=r")
-       (plus (match_dup 1) (match_dup 2)))
+       (plus:QHSI (match_dup 1) (match_dup 2)))
    (clobber (reg:CC CC_REG))]
   ""
 {
diff --git a/gcc/config/h8300/jumpcall.md b/gcc/config/h8300/jumpcall.md
index 4e634085130..3c8527e3a68 100644
--- a/gcc/config/h8300/jumpcall.md
+++ b/gcc/config/h8300/jumpcall.md
@@ -288,7 +288,7 @@ (define_expand "call"
   })
 
 (define_insn "call_insn_<mode>"
-  [(call (mem:QI (match_operand 0 "call_insn_operand" "Cr"))
+  [(call (mem:QI (match_operand:P 0 "call_insn_operand" "Cr"))
                 (match_operand:P 1 "general_operand" "g"))]
   "!SIBLING_CALL_P (insn)"
 {
@@ -326,7 +326,7 @@ (define_expand "call_value"
 
 (define_insn "call_value_insn_<mode>"
   [(set (match_operand 0 "" "=r")
-       (call (mem:QI (match_operand 1 "call_insn_operand" "Cr"))
+       (call (mem:QI (match_operand:P 1 "call_insn_operand" "Cr"))
                      (match_operand:P 2 "general_operand" "g")))]
   "!SIBLING_CALL_P (insn)"
 {
@@ -358,7 +358,7 @@ (define_expand "sibcall"
   })
 
 (define_insn "sibcall_insn_<mode>"
-  [(call (mem:QI (match_operand 0 "call_insn_operand" "Cr"))
+  [(call (mem:QI (match_operand:P 0 "call_insn_operand" "Cr"))
                 (match_operand:P 1 "general_operand" "g"))]
   "SIBLING_CALL_P (insn)"
 {
@@ -396,7 +396,7 @@ (define_expand "sibcall_value"
 
 (define_insn "sibcall_value_insn_<mode>"
   [(set (match_operand 0 "" "=r")
-       (call (mem:QI (match_operand 1 "call_insn_operand" "Cr"))
+       (call (mem:QI (match_operand:P 1 "call_insn_operand" "Cr"))
                      (match_operand:P 2 "general_operand" "g")))]
   "SIBLING_CALL_P (insn)"
 {
diff --git a/gcc/config/h8300/testcompare.md b/gcc/config/h8300/testcompare.md
index 694c9e60d4e..3b43381e64a 100644
--- a/gcc/config/h8300/testcompare.md
+++ b/gcc/config/h8300/testcompare.md
@@ -28,7 +28,7 @@
 ;;
 (define_insn ""
   [(set (reg:CCZ CC_REG)
-       (eq (zero_extract:HSI (match_operand:HSI 0 "register_operand" "r")
+       (eq:CCZ (zero_extract:HSI (match_operand:HSI 0 "register_operand" "r")
                              (const_int 1)
                              (match_operand 1 "const_int_operand" "n"))
            (const_int 0)))]
@@ -54,7 +54,7 @@ (define_insn "*tst<mode>"
 
 (define_insn "*tsthi_upper"
   [(set (reg:CCZN CC_REG)
-       (compare (and:HI (match_operand:HI 0 "register_operand" "r")
+       (compare:CCZN (and:HI (match_operand:HI 0 "register_operand" "r")
                         (const_int -256))
                 (const_int 0)))]
   "reload_completed"
@@ -63,7 +63,7 @@ (define_insn "*tsthi_upper"
 
 (define_insn "*tsthi_upper_z"
   [(set (reg:CCZ CC_REG)
-       (compare (and:HI (match_operand:HI 0 "register_operand" "r")
+       (compare:CCZ (and:HI (match_operand:HI 0 "register_operand" "r")
                         (const_int -256))
                 (const_int 0)))]
   "reload_completed"
@@ -72,7 +72,7 @@ (define_insn "*tsthi_upper_z"
 
 (define_insn "*tstsi_upper"
   [(set (reg:CCZN CC_REG)
-       (compare (and:SI (match_operand:SI 0 "register_operand" "r")
+       (compare:CCZN (and:SI (match_operand:SI 0 "register_operand" "r")
                         (const_int -65536))
                 (const_int 0)))]
   "reload_completed"
@@ -81,7 +81,7 @@ (define_insn "*tstsi_upper"
 
 (define_insn "*cmp<mode>_c"
   [(set (reg:CCC CC_REG)
-       (ltu (match_operand:QHSI 0 "h8300_dst_operand" "rQ")
+       (ltu:CCC (match_operand:QHSI 0 "h8300_dst_operand" "rQ")
             (match_operand:QHSI 1 "h8300_src_operand" "rQi")))]
   "reload_completed"
   {
@@ -97,7 +97,7 @@ (define_insn "*cmp<mode>_c"
 
 (define_insn "*cmpqi_z"
   [(set (reg:CCZ CC_REG)
-       (eq (match_operand:QI 0 "h8300_dst_operand" "rQ")
+       (eq:CCZ (match_operand:QI 0 "h8300_dst_operand" "rQ")
            (match_operand:QI 1 "h8300_src_operand" "rQi")))]
   "reload_completed"
   { return "cmp.b      %X1,%X0"; }
@@ -105,7 +105,7 @@ (define_insn "*cmpqi_z"
 
 (define_insn "*cmphi_z"
   [(set (reg:CCZ CC_REG)
-       (eq (match_operand:HI 0 "h8300_dst_operand" "rQ")
+       (eq:CCZ (match_operand:HI 0 "h8300_dst_operand" "rQ")
            (match_operand:HI 1 "h8300_src_operand" "rQi")))]
   "reload_completed"
   { return "cmp.w      %T1,%T0"; }
@@ -113,7 +113,7 @@ (define_insn "*cmphi_z"
 
 (define_insn "*cmpsi_z"
   [(set (reg:CCZ CC_REG)
-       (eq (match_operand:SI 0 "h8300_dst_operand" "rQ")
+       (eq:CCZ (match_operand:SI 0 "h8300_dst_operand" "rQ")
            (match_operand:SI 1 "h8300_src_operand" "rQi")))]
   "reload_completed"
   { return "cmp.l      %S1,%S0"; }
@@ -121,7 +121,7 @@ (define_insn "*cmpsi_z"
 
 (define_insn "*cmpqi"
   [(set (reg:CC CC_REG)
-       (compare (match_operand:QI 0 "h8300_dst_operand" "rQ")
+       (compare:CC (match_operand:QI 0 "h8300_dst_operand" "rQ")
                 (match_operand:QI 1 "h8300_src_operand" "rQi")))]
   "reload_completed"
   "cmp.b       %X1,%X0"
@@ -129,7 +129,7 @@ (define_insn "*cmpqi"
 
 (define_insn "*cmphi"
   [(set (reg:CC CC_REG)
-       (compare (match_operand:HI 0 "h8300_dst_operand" "rU,rQ")
+       (compare:CC (match_operand:HI 0 "h8300_dst_operand" "rU,rQ")
                 (match_operand:HI 1 "h8300_src_operand" "P3>X,rQi")))]
   "reload_completed"
 {
@@ -150,7 +150,7 @@ (define_insn "*cmphi"
 
 (define_insn "cmpsi"
   [(set (reg:CC CC_REG)
-       (compare (match_operand:SI 0 "h8300_dst_operand" "r,rQ")
+       (compare:CC (match_operand:SI 0 "h8300_dst_operand" "r,rQ")
                 (match_operand:SI 1 "h8300_src_operand" "P3>X,rQi")))]
   "reload_completed"
 {
@@ -176,7 +176,7 @@ (define_insn "cmpsi"
 (define_peephole2
   [(match_scratch:QHSI 1 "r")
    (set (reg:CC CC_REG)
-       (compare (match_operand:QHSI 0 "memory_operand" "")
+       (compare:CC (match_operand:QHSI 0 "memory_operand" "")
                 (const_int 0)))]
   "!mode_dependent_address_p (XEXP (operands[0], 0), MEM_ADDR_SPACE 
(operands[0]))"
   [(parallel [(set (reg:CCZN CC_REG) (compare:CCZN (match_dup 0) (const_int 
0)))
@@ -187,7 +187,7 @@ (define_peephole2
 (define_peephole2
   [(match_scratch:QHSI 1 "r")
    (set (reg:CC CC_REG)
-       (compare (match_operand:QHSI 0 "memory_operand" "")
+       (compare:CC (match_operand:QHSI 0 "memory_operand" "")
                 (const_int 0)))]
   "mode_dependent_address_p (XEXP (operands[0], 0), MEM_ADDR_SPACE 
(operands[0]))"
   [(parallel [(set (match_dup 1) (match_dup 0)) (clobber (reg:CC CC_REG))])

Reply via email to