https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66768
--- Comment #8 from amker at gcc dot gnu.org ---
So address space info is kept and checked in base object's type of MEM_REF. As
in function expand_expr_real_1:
case TARGET_MEM_REF:
{
addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
enum insn_code icode;
unsigned int align;
The AVR ICE happens when base of MEM_REF[base:0, index:(sizetype)ivtmp] has
__memx address space attribute. Since pointer to memory object in __memx
address space (PSImode) has 24 bits type length, while the type of index is
sizetype(Pmode == HImode in this case), which has 16 bits type length. The
expression "(sizetype)ivtmp" is expanded into (subreg:HI (reg:PSI 40) 0).
So I still think IVO should distribute ivtmp as base part of MEM_REF since it
stands for a memory object. Otherwise, we have below IVOed code:
<bb 3>:
# total_10 = PHI <total_5(4), 0(2)>
# ivtmp.7_8 = PHI <ivtmp.7_7(4), 4660(2)>
_12 = (sizetype) ivtmp.7_8;
_4 = MEM[base: 0B, index: _12, offset: 0B];
total_5 = _4 + total_10;
ivtmp.7_7 = ivtmp.7_8 + 2;
if (ivtmp.7_7 != 4700)
goto <bb 4>;
else
goto <bb 5>;
<bb 4>:
goto <bb 3>;
This is wrong since truncation of ivtmp.7_8 to sizetype could result in wrong
address.
Thanks.