https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97417
--- Comment #36 from Levy <admin at levyhsu dot com> --- It seems get_si_mem_base_reg() were called repeatly FOR_BB_INSNS from both pass_shorten_memrefs::analyze and pass_shorten_memrefs::transform Correct me if I'm wrong: It seems we need some data structure (a linked list should work) to store the zero/sign extend when we strip it off like: if (GET_CODE (mem) == ZERO_EXTEND || GET_CODE (mem) == SIGN_EXTEND) mem = XEXP (mem, 0); in each insns. Then in pass_shorten_memrefs::transform(), each time get_si_mem_base_reg() is called, we check whether if we need to put it back.