DJ Delorie <d...@redhat.com> writes:
>> > - if (GET_MODE_BITSIZE (GET_MODE (op0)) < GET_MODE_BITSIZE (GET_MODE
>> > (op1)))
>> > +         /* Don't try to sign-extend SImode to PSImode, for example.  */
>> > + if (GET_MODE_BITSIZE (GET_MODE (op0)) <= GET_MODE_BITSIZE
>> > (GET_MODE (op1)))
>> 
>> Can't you do just nothing if
>> GET_MODE_BITSIZE (GET_MODE (op0)) == GET_MODE_BITSIZE (GET_MODE (op1))?
>
> Truncating SImode to PSImode is a real operation on the MSP430, so I
> can't just "do nothing".

It looks like the patch also treats PSImode->SImode as a truncation though.
That doesn't sound right: both directions can't be truncations.

This comes back to the same thing that were talking about for m32c
(note that the build failure that Bernd pointed out is still there).
If the target really wants to see TRUNCATE rtxes rather than SUBREG
rtxes then it needs to define TRULY_NOOP_TRUNCATION, probably
changing/improving its interface in order to handle partial modes.
But it looks like you handle both TRUNCATE and SUBREG:

+; This pattern is identical to the truncsipsi2 pattern except
+; that it uses a SUBREG instead of a TRUNC.  It is needed in
+; order to prevent reload from converting (set:SI (SUBREG:PSI (SI)))
+; into (SET:PSI (PSI)).
+;
+; Note: using POPM.A #1 is two bytes smaller than using POPX.A....
+
+(define_insn "movsipsi2"
+  [(set (match_operand:PSI            0 "register_operand" "=r")
+       (subreg:PSI (match_operand:SI 1 "register_operand" "r") 0))]
+  "TARGET_LARGE"
+  "PUSH.W %H1 { PUSH.W %1 { POPM.A #1, %0"
+)

+; See the movsipsi2 pattern above for another way that GCC performs this
+; conversion.
+(define_insn "truncsipsi2"
+  [(set (match_operand:PSI              0 "register_operand" "=r")
+       (truncate:PSI (match_operand:SI 1 "register_operand" "r")))]
+  ""
+  "PUSH.W %H1 { PUSH.W %1 { POPM.A #1, %0"
+)

(I think the comment could do with some cleanup: SETs don't have modes)

I realise the patch is to expand_debug_expr and so .md patterns don't
really matter, but it doesn't seem consistent for general rtl to allow
both subreg and truncate SI->PSI, but not debug exprs.

BTW, if SImode->PSImode is so expensive, MODES_TIEABLE_P should probably
return false for that pair of modes.  That'll discourage -- but not prevent --
the rtl optimisers from replacing (reg:PSI ...) operands with
(subreg:PSI (reg:SI ...)) ones.

Thanks,
Richard

Reply via email to