Skip to content

Commit 270096e

Browse files
committed
[Xtensa] Implement Xtensa Mul and Div Options.
Implement Xtensa Mul16, Mul32, Mul32High and Div32 Options. Also fix callw test.
1 parent dda4b96 commit 270096e

File tree

10 files changed

+1034
-39
lines changed

10 files changed

+1034
-39
lines changed

llvm/lib/Target/Xtensa/XtensaFeatures.td

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,23 @@ def FeatureMINMAX : SubtargetFeature<"minmax", "HasMINMAX", "true",
4747
"Enable Xtensa MINMAX option">;
4848
def HasMINMAX : Predicate<"Subtarget->hasMINMAX()">,
4949
AssemblerPredicate<(all_of FeatureMINMAX)>;
50+
51+
def FeatureMul16 : SubtargetFeature<"mul16", "HasMul16", "true",
52+
"Enable Xtensa Mul16 option">;
53+
def HasMul16 : Predicate<"Subtarget->hasMul16()">,
54+
AssemblerPredicate<(all_of FeatureMul16)>;
55+
56+
def FeatureMul32 : SubtargetFeature<"mul32", "HasMul32", "true",
57+
"Enable Xtensa Mul32 option">;
58+
def HasMul32 : Predicate<"Subtarget->hasMul32()">,
59+
AssemblerPredicate<(all_of FeatureMul32)>;
60+
61+
def FeatureMul32High : SubtargetFeature<"mul32high", "HasMul32High", "true",
62+
"Enable Xtensa Mul32High option">;
63+
def HasMul32High : Predicate<"Subtarget->hasMul32High()">,
64+
AssemblerPredicate<(all_of FeatureMul32High)>;
65+
66+
def FeatureDiv32 : SubtargetFeature<"div32", "HasDiv32", "true",
67+
"Enable Xtensa Div32 option">;
68+
def HasDiv32 : Predicate<"Subtarget->hasDiv32()">,
69+
AssemblerPredicate<(all_of FeatureDiv32)>;

llvm/lib/Target/Xtensa/XtensaISelLowering.cpp

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

118-
setOperationAction(ISD::MUL, MVT::i32, Expand);
119-
setOperationAction(ISD::MULHU, MVT::i32, Expand);
120-
setOperationAction(ISD::MULHS, MVT::i32, Expand);
118+
if (Subtarget.hasMul32())
119+
setOperationAction(ISD::MUL, MVT::i32, Legal);
120+
else
121+
setOperationAction(ISD::MUL, MVT::i32, Expand);
122+
123+
if (Subtarget.hasMul32High()) {
124+
setOperationAction(ISD::MULHU, MVT::i32, Legal);
125+
setOperationAction(ISD::MULHS, MVT::i32, Legal);
126+
} else {
127+
setOperationAction(ISD::MULHU, MVT::i32, Expand);
128+
setOperationAction(ISD::MULHS, MVT::i32, Expand);
129+
}
130+
121131
setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand);
122132
setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand);
123133

124-
setOperationAction(ISD::SDIV, MVT::i32, Expand);
125-
setOperationAction(ISD::UDIV, MVT::i32, Expand);
126-
setOperationAction(ISD::SREM, MVT::i32, Expand);
127-
setOperationAction(ISD::UREM, MVT::i32, Expand);
134+
if (Subtarget.hasDiv32()) {
135+
setOperationAction(ISD::SDIV, MVT::i32, Legal);
136+
setOperationAction(ISD::UDIV, MVT::i32, Legal);
137+
setOperationAction(ISD::SREM, MVT::i32, Legal);
138+
setOperationAction(ISD::UREM, MVT::i32, Legal);
139+
} else {
140+
setOperationAction(ISD::SDIV, MVT::i32, Expand);
141+
setOperationAction(ISD::UDIV, MVT::i32, Expand);
142+
setOperationAction(ISD::SREM, MVT::i32, Expand);
143+
setOperationAction(ISD::UREM, MVT::i32, Expand);
144+
}
145+
128146
setOperationAction(ISD::SDIVREM, MVT::i32, Expand);
129147
setOperationAction(ISD::UDIVREM, MVT::i32, Expand);
130148

llvm/lib/Target/Xtensa/XtensaInstrInfo.td

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,36 @@ def LOOPNEZ : RRI8_Inst<0x06, (outs), (ins AR:$s, ltarget:$target),
956956

957957
def : InstAlias<"_loopnez\t$s, $target", (LOOPNEZ AR:$s, ltarget:$target)>;
958958

959+
//===----------------------------------------------------------------------===//
960+
// Mul16 Instructions
961+
//===----------------------------------------------------------------------===//
962+
963+
let Predicates = [HasMul16] in {
964+
def MUL16S : RRR_Inst<0x00, 0x01, 0x0D, (outs AR:$r), (ins AR:$s, AR:$t),
965+
"mul16s\t$r, $s, $t", []>;
966+
def MUL16U : RRR_Inst<0x00, 0x01, 0x0C, (outs AR:$r), (ins AR:$s, AR:$t),
967+
"mul16u\t$r, $s, $t", []>;
968+
}
969+
970+
//===----------------------------------------------------------------------===//
971+
// Mul32 Instructions
972+
//===----------------------------------------------------------------------===//
973+
974+
def MULL : ArithLogic_RRR<0x08, 0x02, "mull", mul, 1>, Requires<[HasMul32]>;
975+
def MULUH : ArithLogic_RRR<0x0A, 0x02, "muluh", mulhu, 1>, Requires<[HasMul32High]>;
976+
def MULSH : ArithLogic_RRR<0x0B, 0x02, "mulsh", mulhs, 1>, Requires<[HasMul32High]>;
977+
978+
//===----------------------------------------------------------------------===//
979+
// Div32 Instructions
980+
//===----------------------------------------------------------------------===//
981+
982+
let Predicates = [HasDiv32] in {
983+
def QUOS : ArithLogic_RRR<0x0D, 0x02, "quos", sdiv>;
984+
def QUOU : ArithLogic_RRR<0x0C, 0x02, "quou", udiv>;
985+
def REMS : ArithLogic_RRR<0x0F, 0x02, "rems", srem>;
986+
def REMU : ArithLogic_RRR<0x0E, 0x02, "remu", urem>;
987+
}
988+
959989
//===----------------------------------------------------------------------===//
960990
// DSP Instructions
961991
//===----------------------------------------------------------------------===//

llvm/lib/Target/Xtensa/XtensaSubtarget.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ class XtensaSubtarget : public XtensaGenSubtargetInfo {
7373
bool hasCLAMPS() const { return HasCLAMPS; }
7474
bool hasNSA() const { return HasNSA; }
7575
bool hasMINMAX() const { return HasMINMAX; }
76+
bool hasMul16() const { return HasMul16; }
77+
bool hasMul32() const { return HasMul32; }
78+
bool hasMul32High() const { return HasMul32High; }
79+
bool hasDiv32() const { return HasDiv32; }
7680
bool isWindowedABI() const { return hasWindowed(); }
7781

7882
// Automatically generated by tblgen.

llvm/test/CodeGen/Xtensa/callw.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ define i32 @test_call_external(i32 %a) nounwind {
77
; CHECK-LABEL: test_call_external:
88
; CHECK: # %bb.0:
99
; CHECK-NEXT: entry a1, 32
10-
; CHECK-NEXT: l32r a8, .LCPI0_0
1110
; CHECK-NEXT: or a10, a2, a2
11+
; CHECK-NEXT: l32r a8, .LCPI0_0
1212
; CHECK-NEXT: callx8 a8
1313
; CHECK-NEXT: or a2, a10, a10
1414
; CHECK-NEXT: retw
@@ -30,8 +30,8 @@ define i32 @test_call_defined(i32 %a) nounwind {
3030
; CHECK-LABEL: test_call_defined:
3131
; CHECK: # %bb.0:
3232
; CHECK-NEXT: entry a1, 32
33-
; CHECK-NEXT: l32r a8, .LCPI2_0
3433
; CHECK-NEXT: or a10, a2, a2
34+
; CHECK-NEXT: l32r a8, .LCPI2_0
3535
; CHECK-NEXT: callx8 a8
3636
; CHECK-NEXT: or a2, a10, a10
3737
; CHECK-NEXT: retw

0 commit comments

Comments
 (0)