https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117699
Bug ID: 117699
Summary: Scratch from peephole2 overlaps operands
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: gjl at gcc dot gnu.org
Target Milestone: ---
Created attachment 59641
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59641&action=edit
bogus-peep2.diff
THIS PR REQUIRES A PATCH bogus-peep2.diff AS ATTACHED TO REPRODUCE
The required patch is atop 2024-11-19 current trunk
b222ee10045db06655d2a9f0d87e25c5083d98c8
On an early work-in-progress, peephole2 produces the following insn:
$ avr-gcc bogus-peep2.c -S -Os -da
long ashl32_7 (int i, long x)
{
return x << 7;
}
$ cat bogus-peep2.c.333r.peephole2
Splitting with gen_peephole2_100 (avr.md:5387)
...
(insn 24 8 15 2 (parallel [
(set (reg:SI 22 r22 [orig:47 _3 ] [47])
(ashift:SI (reg:SI 20 r20 [orig:48 x ] [48])
(const_int 7 [0x7])))
(clobber (reg:QI 24 r24))
(clobber (reg:CC 36 cc))
]) "bogus-peep2.c":3:14 -1
(nil))
Output reg22:SI extends from r22...r25 and scratch r24:QI overlaps it.
This is the RTL peephole avr.md:5387:
(define_peephole2
[(match_scratch:QI 3 "d")
(parallel [(set (match_operand:ALL4 0 "register_operand" "")
(ashift:ALL4 (match_operand:ALL4 1 "register_operand" "")
(match_operand:QI 2 "const_int_operand" "")))
(clobber (reg:CC REG_CC))])]
""
[(parallel [(set (match_dup 0)
(ashift:ALL4 (match_dup 1)
(match_dup 2)))
(clobber (match_dup 3))
(clobber (reg:CC REG_CC))])])
Target: avr
Configured with: ../../source/gcc-master/configure --target=avr --disable-nls
--with-dwarf2 --with-gnu-as --with-gnu-ld --disable-shared
--enable-languages=c,c++
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 15.0.0 20241119 (experimental) (GCC)