https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124955
--- Comment #2 from Jeffrey A. Law <law at gcc dot gnu.org> --- I think avoiding the sign_extract form would be better. As a spitter I would target generating something like this for the new RTL: (set (match_dup 0) (and (match_dup 1) (const_int -2)) (set (match_dup 0) (sign_extend:DI(ashift (match_dup 0) (const_int 12)) Or something along those lines. There's some obvious type changes in there, but that's the basic idea. The key is realizing the field from the sign_extract N bits long, starting at 0 and fed into a shift by M bits, where N + M == 32. That's a natural match for slliw. Then we just need to handle the logical and, which we can do first or second in the generated RTL. In the case where the mask doesn't fit andi we can generate th two shift form. One shifts LSB bits off, the second moves the remaining bits into position. Again we'd be using slliw, so we'll get the proper sign extension.
