I’m trying to define a multiclass for arithmetic instructions (ADD and SUB), which should handle both 8,16 and 32 bits values.
Now, I found an issue while developing the ri
pattern:
multiclass ArithmeticInst<bits<8> op, string OpcStr, SDNode OpNode, RegisterClass RC, ValueType RegSize, Operand ImmSize> {
...
def ri : MyInst<op, (outs RC:$rd), (ins RC:$rs1, i32imm:$immSrc),
!strconcat(OpcStr, " $rs1 $immSrc"),
[(set RegSize:$rd, (OpNode RegSize:$rs1, (RegSize imm:$immSrc)))]>;
defm ADD8 : ArithmeticInst<24, "add", add, GR8, i8, i8imm>;
defm ADD16 : ArithmeticInst<24, "add", add, GR16, i16, i16imm>;
defm ADD32 : ArithmeticInst<24, "add", add, GR32, i32, i32imm>;
The problem is, my backend will only generate 32-bit constant values for immidiates, so 8 and 16 bits cannot be selected like that.
I tried to add trunc
to the pattern, but then the 32 bit was ruined.
Is there a way to do it right?