Index: llvm/lib/Target/RISCV/RISCVInstrInfo.td =================================================================== --- llvm/lib/Target/RISCV/RISCVInstrInfo.td +++ llvm/lib/Target/RISCV/RISCVInstrInfo.td @@ -896,6 +896,10 @@ return N->hasOneUse(); }]>; +def mul_oneuse : PatFrag<(ops node:$A, node:$B), (mul node:$A, node:$B), [{ + return N->hasOneUse(); +}]>; + /// Simple arithmetic operations def : PatGprGpr; Index: llvm/lib/Target/RISCV/RISCVInstrInfoB.td =================================================================== --- llvm/lib/Target/RISCV/RISCVInstrInfoB.td +++ llvm/lib/Target/RISCV/RISCVInstrInfoB.td @@ -971,23 +971,23 @@ def : Pat<(add (shl GPR:$rs1, (XLenVT 3)), GPR:$rs2), (SH3ADD GPR:$rs1, GPR:$rs2)>; -def : Pat<(add (mul GPR:$rs1, (XLenVT 6)), GPR:$rs2), +def : Pat<(add (mul_oneuse GPR:$rs1, (XLenVT 6)), GPR:$rs2), (SH1ADD (SH1ADD GPR:$rs1, GPR:$rs1), GPR:$rs2)>; -def : Pat<(add (mul GPR:$rs1, (XLenVT 10)), GPR:$rs2), +def : Pat<(add (mul_oneuse GPR:$rs1, (XLenVT 10)), GPR:$rs2), (SH1ADD (SH2ADD GPR:$rs1, GPR:$rs1), GPR:$rs2)>; -def : Pat<(add (mul GPR:$rs1, (XLenVT 18)), GPR:$rs2), +def : Pat<(add (mul_oneuse GPR:$rs1, (XLenVT 18)), GPR:$rs2), (SH1ADD (SH3ADD GPR:$rs1, GPR:$rs1), GPR:$rs2)>; -def : Pat<(add (mul GPR:$rs1, (XLenVT 12)), GPR:$rs2), +def : Pat<(add (mul_oneuse GPR:$rs1, (XLenVT 12)), GPR:$rs2), (SH2ADD (SH1ADD GPR:$rs1, GPR:$rs1), GPR:$rs2)>; -def : Pat<(add (mul GPR:$rs1, (XLenVT 20)), GPR:$rs2), +def : Pat<(add (mul_oneuse GPR:$rs1, (XLenVT 20)), GPR:$rs2), (SH2ADD (SH2ADD GPR:$rs1, GPR:$rs1), GPR:$rs2)>; -def : Pat<(add (mul GPR:$rs1, (XLenVT 36)), GPR:$rs2), +def : Pat<(add (mul_oneuse GPR:$rs1, (XLenVT 36)), GPR:$rs2), (SH2ADD (SH3ADD GPR:$rs1, GPR:$rs1), GPR:$rs2)>; -def : Pat<(add (mul GPR:$rs1, (XLenVT 24)), GPR:$rs2), +def : Pat<(add (mul_oneuse GPR:$rs1, (XLenVT 24)), GPR:$rs2), (SH3ADD (SH1ADD GPR:$rs1, GPR:$rs1), GPR:$rs2)>; -def : Pat<(add (mul GPR:$rs1, (XLenVT 40)), GPR:$rs2), +def : Pat<(add (mul_oneuse GPR:$rs1, (XLenVT 40)), GPR:$rs2), (SH3ADD (SH2ADD GPR:$rs1, GPR:$rs1), GPR:$rs2)>; -def : Pat<(add (mul GPR:$rs1, (XLenVT 72)), GPR:$rs2), +def : Pat<(add (mul_oneuse GPR:$rs1, (XLenVT 72)), GPR:$rs2), (SH3ADD (SH3ADD GPR:$rs1, GPR:$rs1), GPR:$rs2)>; } // Predicates = [HasStdExtZba]