[Bug target/105753] New: [avr] ICE: in add_clobbers, at config/avr/avr-dimode.md:2705

2022-05-27 Thread filip.hejsek at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105753

Bug ID: 105753
   Summary: [avr] ICE: in add_clobbers, at
config/avr/avr-dimode.md:2705
   Product: gcc
   Version: 13.0
Status: UNCONFIRMED
  Keywords: ice-on-valid-code
  Severity: normal
  Priority: P3
 Component: target
  Assignee: unassigned at gcc dot gnu.org
  Reporter: filip.hejsek at gmail dot com
  Target Milestone: ---
Target: avr

GCC fails when compiling the following C program for AVR (with at least -O1):

int digit_sum(unsigned long n) {
  int sum = 0;

  do {
int x = n % 10;
n /= 10;
sum += x;
  } while(n);

  return sum;
}

I have tested both GCC 12.1.0 form Arch Linux and a development version (GCC
13.0.0) compiled from git sources.

Here is the compiler output:

$ ~/avr_gcc_install/bin/avr-gcc -c -O1 bug.c
during RTL pass: combine
bug.c: In function ‘digit_sum’:
bug.c:13:1: internal compiler error: in add_clobbers, at
config/avr/avr-dimode.md:2705
   13 | }
  | ^
0x770d30 add_clobbers(rtx_def*, int)
../../gcc/gcc/config/avr/avr-dimode.md:2705
0x1645c94 recog_for_combine_1
../../gcc/gcc/combine.cc:11422
0x164979e recog_for_combine
../../gcc/gcc/combine.cc:11622
0x165aef7 try_combine
../../gcc/gcc/combine.cc:3543
0x165e72f combine_instructions
../../gcc/gcc/combine.cc:1266
0x165e72f rest_of_handle_combine
../../gcc/gcc/combine.cc:14976
0x165e72f execute
../../gcc/gcc/combine.cc:15021
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
$ ~/avr_gcc_install/bin/avr-gcc -v
Using built-in specs.
Reading specs from
/home/filiph/avr_gcc_install/lib/gcc/avr/13.0.0/device-specs/specs-avr2
COLLECT_GCC=/home/filiph/avr_gcc_install/bin/avr-gcc
COLLECT_LTO_WRAPPER=/home/filiph/avr_gcc_install/libexec/gcc/avr/13.0.0/lto-wrapper
Target: avr
Configured with: ../gcc/configure --prefix=/home/filiph/avr_gcc_install
--target=avr --enable-languages=c --with-as=/usr/bin/avr-as --with-gnu-as
--with-ld=/usr/bin/avr-ld --with-gnu-ld
Thread model: single
Supported LTO compression algorithms: zlib zstd
gcc version 13.0.0 20220525 (experimental) [master -gda2c56ee6] (GCC) 

$ avr-gcc -c -O1 bug.c
during RTL pass: combine
bug.c: In function 'digit_sum':
bug.c:13:1: internal compiler error: in add_clobbers, at
config/avr/avr-dimode.md:2705
   13 | }
  | ^
0x140115b diagnostic_impl(rich_location*, diagnostic_metadata const*, int, char
const*, __va_list_tag (*) [1], diagnostic_t)
???:0
0x140209d internal_error(char const*, ...)
???:0
0x5bafbc fancy_abort(char const*, int, char const*)
???:0
0x5b1839 add_clobbers(rtx_def*, int) [clone .cold]
???:0
0x1213b97 recog_for_combine_1(rtx_def**, rtx_insn*, rtx_def**)
???:0
0x1215e8e recog_for_combine(rtx_def**, rtx_insn*, rtx_def**)
???:0
0x1228da5 try_combine(rtx_insn*, rtx_insn*, rtx_insn*, rtx_insn*, int*,
rtx_insn*)
???:0
0x122c0a4 (anonymous namespace)::pass_combine::execute(function*)
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
$ avr-gcc -v
Using built-in specs.
Reading specs from /usr/lib/gcc/avr/12.1.0/device-specs/specs-avr2
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/avr/12.1.0/lto-wrapper
Target: avr
Configured with: /build/avr-gcc/src/gcc-12.1.0/configure
--disable-install-libiberty --disable-libssp --disable-libstdcxx-pch
--disable-libunwind-exceptions --disable-linker-build-id --disable-nls
--disable-werror --disable-__cxa_atexit --enable-checking=release
--enable-clocale=gnu --enable-gnu-unique-object --enable-gold
--enable-languages=c,c++ --enable-ld=default --enable-lto --enable-plugin
--enable-shared --infodir=/usr/share/info --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --prefix=/usr --target=avr
--with-as=/usr/bin/avr-as --with-gnu-as --with-gnu-ld --with-ld=/usr/bin/avr-ld
--with-plugin-ld=ld.gold --with-system-zlib --with-isl
--enable-gnu-indirect-function
Thread model: single
Supported LTO compression algorithms: zlib zstd
gcc version 12.1.0 (GCC) 

(This bug seems to be similar to bug 88051, but that one was on i386.)

[Bug target/105753] [avr] ICE: in add_clobbers, at config/avr/avr-dimode.md:2705

2022-05-27 Thread filip.hejsek at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105753

--- Comment #1 from Filip Hejsek  ---
Not that i would really understand the machine description files, but the
problem seems to be caused by this instruction definition:

(define_insn_and_split "udivmodsi4"
  [(parallel [(set (match_operand:SI 0 "pseudo_register_operand" "")
   (udiv:SI (match_operand:SI 1 "pseudo_register_operand" "")
   (match_operand:SI 2 "pseudo_register_operand" "")))
  (set (match_operand:SI 3 "pseudo_register_operand" "")
   (umod:SI (match_dup 1) (match_dup 2)))
  (clobber (reg:SI 18))
  (clobber (reg:SI 22))
  (clobber (reg:HI 26))
  (clobber (reg:HI 30))])]
  ""
  "this udivmodsi4 pattern should have been splitted;"
  ""
  [(set (reg:SI 22) (match_dup 1))
   (set (reg:SI 18) (match_dup 2))
   (parallel [(set (reg:SI 18) (udiv:SI (reg:SI 22) (reg:SI 18)))
  (set (reg:SI 22) (umod:SI (reg:SI 22) (reg:SI 18)))
  (clobber (reg:HI 26))
  (clobber (reg:HI 30))])
   (set (match_dup 0) (reg:SI 18))
   (set (match_dup 3) (reg:SI 22))])

Just as in bug 88051, the instruction is missing from the generated switch in
add_clobbers and removing pararllel from the definition fixes the problem. (I
don't understand enough to know if it's the correct fix though.)

There are 4 instructions with parallel in the definition: divmodpsi4,
udivmodpsi4, divmodsi4, udivmodsi4.

[Bug target/105753] [avr] ICE: in add_clobbers, at config/avr/avr-dimode.md:2705

2022-06-12 Thread filip.hejsek at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105753

Filip Hejsek  changed:

   What|Removed |Added

  Known to fail||12.1.0
  Known to work||10.1.0

--- Comment #3 from Filip Hejsek  ---
This is a regression, 10.1 compiled this program without problem. Using git
bisect, i found this was broken in 3ba781d3b5c8efadb60866c9743b657e8f0eb222.