Skip to content

Commit 583eed5

Browse files
committed
[Xtensa] Implement Xtensa Mul and Div Options.
Implement Xtensa Mul16, Mul32, Mul32High and Div32 Options.
1 parent 53a395f commit 583eed5

File tree

9 files changed

+1036
-37
lines changed

9 files changed

+1036
-37
lines changed

llvm/lib/Target/Xtensa/XtensaFeatures.td

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,23 @@ def FeatureBoolean : SubtargetFeature<"bool", "HasBoolean", "true",
2222
"Enable Xtensa Boolean extension">;
2323
def HasBoolean : Predicate<"Subtarget->hasBoolean()">,
2424
AssemblerPredicate<(all_of FeatureBoolean)>;
25+
26+
def FeatureMul16 : SubtargetFeature<"mul16", "HasMul16", "true",
27+
"Enable Xtensa Mul16 option">;
28+
def HasMul16 : Predicate<"Subtarget->hasMul16()">,
29+
AssemblerPredicate<(all_of FeatureMul16)>;
30+
31+
def FeatureMul32 : SubtargetFeature<"mul32", "HasMul32", "true",
32+
"Enable Xtensa Mul32 option">;
33+
def HasMul32 : Predicate<"Subtarget->hasMul32()">,
34+
AssemblerPredicate<(all_of FeatureMul32)>;
35+
36+
def FeatureMul32High : SubtargetFeature<"mul32high", "HasMul32High", "true",
37+
"Enable Xtensa Mul32High option">;
38+
def HasMul32High : Predicate<"Subtarget->hasMul32High()">,
39+
AssemblerPredicate<(all_of FeatureMul32High)>;
40+
41+
def FeatureDiv32 : SubtargetFeature<"div32", "HasDiv32", "true",
42+
"Enable Xtensa Div32 option">;
43+
def HasDiv32 : Predicate<"Subtarget->hasDiv32()">,
44+
AssemblerPredicate<(all_of FeatureDiv32)>;

llvm/lib/Target/Xtensa/XtensaISelLowering.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,34 @@ XtensaTargetLowering::XtensaTargetLowering(const TargetMachine &TM,
106106
setCondCodeAction(ISD::SETUGT, MVT::i32, Expand);
107107
setCondCodeAction(ISD::SETULE, MVT::i32, Expand);
108108

109-
setOperationAction(ISD::MUL, MVT::i32, Expand);
110-
setOperationAction(ISD::MULHU, MVT::i32, Expand);
111-
setOperationAction(ISD::MULHS, MVT::i32, Expand);
109+
if (Subtarget.hasMul32())
110+
setOperationAction(ISD::MUL, MVT::i32, Legal);
111+
else
112+
setOperationAction(ISD::MUL, MVT::i32, Expand);
113+
114+
if (Subtarget.hasMul32High()) {
115+
setOperationAction(ISD::MULHU, MVT::i32, Legal);
116+
setOperationAction(ISD::MULHS, MVT::i32, Legal);
117+
} else {
118+
setOperationAction(ISD::MULHU, MVT::i32, Expand);
119+
setOperationAction(ISD::MULHS, MVT::i32, Expand);
120+
}
121+
112122
setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand);
113123
setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand);
114124

115-
setOperationAction(ISD::SDIV, MVT::i32, Expand);
116-
setOperationAction(ISD::UDIV, MVT::i32, Expand);
117-
setOperationAction(ISD::SREM, MVT::i32, Expand);
118-
setOperationAction(ISD::UREM, MVT::i32, Expand);
125+
if (Subtarget.hasDiv32()) {
126+
setOperationAction(ISD::SDIV, MVT::i32, Legal);
127+
setOperationAction(ISD::UDIV, MVT::i32, Legal);
128+
setOperationAction(ISD::SREM, MVT::i32, Legal);
129+
setOperationAction(ISD::UREM, MVT::i32, Legal);
130+
} else {
131+
setOperationAction(ISD::SDIV, MVT::i32, Expand);
132+
setOperationAction(ISD::UDIV, MVT::i32, Expand);
133+
setOperationAction(ISD::SREM, MVT::i32, Expand);
134+
setOperationAction(ISD::UREM, MVT::i32, Expand);
135+
}
136+
119137
setOperationAction(ISD::SDIVREM, MVT::i32, Expand);
120138
setOperationAction(ISD::UDIVREM, MVT::i32, Expand);
121139

llvm/lib/Target/Xtensa/XtensaInstrInfo.td

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,36 @@ let Constraints = "$dr = $r,@earlyclobber $dr" in {
850850
"movt\t$r, $s, $t", []>, Requires<[HasBoolean]>;
851851
}
852852

853+
//===----------------------------------------------------------------------===//
854+
// Mul16 Instructions
855+
//===----------------------------------------------------------------------===//
856+
857+
let Predicates = [HasMul16] in {
858+
def MUL16S : RRR_Inst<0x00, 0x01, 0x0D, (outs AR:$r), (ins AR:$s, AR:$t),
859+
"mul16s\t$r, $s, $t", []>;
860+
def MUL16U : RRR_Inst<0x00, 0x01, 0x0C, (outs AR:$r), (ins AR:$s, AR:$t),
861+
"mul16u\t$r, $s, $t", []>;
862+
}
863+
864+
//===----------------------------------------------------------------------===//
865+
// Mul32 Instructions
866+
//===----------------------------------------------------------------------===//
867+
868+
def MULL : ArithLogic_RRR<0x08, 0x02, "mull", mul, 1>, Requires<[HasMul32]>;
869+
def MULUH : ArithLogic_RRR<0x0A, 0x02, "muluh", mulhu, 1>, Requires<[HasMul32High]>;
870+
def MULSH : ArithLogic_RRR<0x0B, 0x02, "mulsh", mulhs, 1>, Requires<[HasMul32High]>;
871+
872+
//===----------------------------------------------------------------------===//
873+
// Div32 Instructions
874+
//===----------------------------------------------------------------------===//
875+
876+
let Predicates = [HasDiv32] in {
877+
def QUOS : ArithLogic_RRR<0x0D, 0x02, "quos", sdiv>;
878+
def QUOU : ArithLogic_RRR<0x0C, 0x02, "quou", udiv>;
879+
def REMS : ArithLogic_RRR<0x0F, 0x02, "rems", srem>;
880+
def REMU : ArithLogic_RRR<0x0E, 0x02, "remu", urem>;
881+
}
882+
853883
//===----------------------------------------------------------------------===//
854884
// DSP Instructions
855885
//===----------------------------------------------------------------------===//

llvm/lib/Target/Xtensa/XtensaSubtarget.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ class XtensaSubtarget : public XtensaGenSubtargetInfo {
6666

6767
bool hasDensity() const { return HasDensity; }
6868

69+
bool hasMul16() const { return HasMul16; }
70+
71+
bool hasMul32() const { return HasMul32; }
72+
73+
bool hasMul32High() const { return HasMul32High; }
74+
75+
bool hasDiv32() const { return HasDiv32; }
76+
6977
bool hasMAC16() const { return HasMAC16; }
7078

7179
bool hasWindowed() const { return HasWindowed; }

0 commit comments

Comments
 (0)