This is a tentative patch to fix PR46779 and hopefully also related issues like PR45291. In the present version of avr_hard_regno_mode_ok, QImode is forbidden in r29/r28. If a 16-bit value or composite is allocated to r28, this can lead to odd subregs like (set (subreg:QI (reg:HI r28) 0) ...) These subregs are produced by IRA and reload treats the subreg with a RELOAD_WRITE. As reload spills r28 to another hard reg that can access QI, there will be no input reload. Therefore, if r29 already contains data that data will get garbaged. See also the discussion around http://gcc.gnu.org/ml/gcc/2011-06/msg00005.html Tested with two regressions less compared to unpatched compiler. Testcases that now pass are: * gcc.target/avr/pr46779-1.c * gcc.target/avr/pr46779-2.c Johann -- PR target/46779 * config/avr/avr.c (avr_hard_regno_mode_ok): Rewrite. In particular, allow 8-bit values in r28 and r29. (avr_hard_regno_scratch_ok): Disallow any register that might be part of the frame pointer. (avr_hard_regno_rename_ok): Same.