I am writing a new backend and I met some problem.
I want to support in IR: sdiv v32i16 %a, %b. But the target only support sdiv v16i32 %a, %b natively.
Could I promote v32i16 to v32i32, split v32i32 to two v16i32 , truncate v16i32 to v16i16 and merge two v16i16 into one v32i16?
Is this way possible?
I saw the code fragment in TargetLowering.h:
Those are the actions for the type legalizer. They specify how to legalize a type that has no supported operations and isn’t assigned to any register class by your target. The action will be applied to every operation on that type.
I assume v32i16 is otherwise supported for your target and only division is missing. If that’s the case you’ll need to define a Custom lowering operation for your target. So you’ll need to call setOperationAction(ISD::SDIV, v32i16, Custom) from your TargetLowering constructor. Then write custom code in LowerOperation to custom handle v32i16 ISD::SDIV. From there you can split the operands, SIGN_EXTEND each to v16i32 do the SDIV, TRUNCATE the results back to v16i16, and use a CONCAT_VECTORS to join them back to v32i16.