> What's exceedingly weird is T_N_T_M_P (DImode, SImode) isn't actually a > truncation! The output precision is first, the input precision is second. > The docs > explicitly state the output precision should be smaller than the input > precision > (which makes sense for truncation). > > That's where I'd start with trying to untangle this mess.
Thanks (both) for correcting my misunderstanding. At the very least might I suggest that we introduce a new TRULY_NOOP_EXTENSION_MODES_P target hook that MIPS can use for this purpose? It'd help reduce confusion, and keep the documentation/function naming correct. When Richard Sandiford "hookized" truly_noop_truncation in 2017 https://gcc.gnu.org/legacy-ml/gcc-patches/2017-09/msg00836.html he mentions the inprec/outprec confusion [deciding not to add a gcc_assert outprec < inprec here, which might be a good idea]. The next question is whether this is just TRULY_NOOP_SIGN_EXTENSION_MODES_P or whether there are any targets that usefully ensure some modes are zero-extended forms of others. TRULY_NOOP_ZERO_EXTENSION... My vote is that a DINS instruction that updates the most significant bit of an SImode value should then expand or define_insn_and_split with an explicit following sign-extension operation. To avoid this being eliminated by the RTL optimizers/combine the DINS should return a DImode result, with the following extension truncating it to canonical SImode form. This preserves the required backend invariant (and doesn't require tweaking machine-independent code in combine). SImode DINS instructions that don't/can't affect the MSB, can be a single SImode instruction. Cheers, Roger --