https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87817
Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> --- The important question is if ZERO_EXTRACT is well defined with zero SIZE and what it means. And another question is if SIGN_EXTRACT is well defined with zero SIZE and if yes, how would we define it. If it is defined, we could do something like: --- gcc/combine.c.jj 2018-11-12 16:18:28.656552899 +0100 +++ gcc/combine.c 2018-11-13 13:08:38.776716046 +0100 @@ -7271,6 +7271,15 @@ expand_compound_operation (rtx x) if (len + pos > GET_MODE_PRECISION (inner_mode)) return x; + if (len == 0) + { + /* Extracting no bits for ZERO_EXTRACT always yields 0. */ + if (unsignedp) + return CONST0_RTX (GET_MODE (x)); + /* For SIGN_EXTRACT it is undefined. */ + return x; + } + if (BITS_BIG_ENDIAN) pos = GET_MODE_PRECISION (inner_mode) - len - pos; which fixes this PR, but we have other spots that would need tweaking, e.g. simplify-rtx.c, another spot in the combiner etc. Another possibility is to say that both are UB with zero SIZE and define the pattern differently.