Skip to content

Commit 0e6aa08

Browse files
committed
[ARM][MVE] Add DoubleWidthResult flag
Add a flag for those instructions which read from the top/bottom halves of their inputs and produce a vector of results with double width elements. Differential Revision: https://reviews.llvm.org/D76762
1 parent bda3dd0 commit 0e6aa08

File tree

4 files changed

+110
-1
lines changed

4 files changed

+110
-1
lines changed

llvm/lib/Target/ARM/ARMInstrFormats.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ class InstTemplate<AddrMode am, int sz, IndexMode im,
410410
bit validForTailPredication = 0;
411411
bit retainsPreviousHalfElement = 0;
412412
bit horizontalReduction = 0;
413+
bit doubleWidthResult = 0;
413414

414415
// If this is a pseudo instruction, mark it isCodeGenOnly.
415416
let isCodeGenOnly = !eq(!cast<string>(f), "Pseudo");
@@ -425,6 +426,7 @@ class InstTemplate<AddrMode am, int sz, IndexMode im,
425426
let TSFlags{20} = validForTailPredication;
426427
let TSFlags{21} = retainsPreviousHalfElement;
427428
let TSFlags{22} = horizontalReduction;
429+
let TSFlags{23} = doubleWidthResult;
428430

429431
let Constraints = cstr;
430432
let Itinerary = itin;

llvm/lib/Target/ARM/ARMInstrMVE.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,6 +2513,7 @@ class MVE_VMOVL<string iname, string suffix, bits<2> sz, bit U, bit top,
25132513
let Inst{11-6} = 0b111101;
25142514
let Inst{4} = 0b0;
25152515
let Inst{0} = 0b0;
2516+
let doubleWidthResult = 1;
25162517
}
25172518

25182519
multiclass MVE_VMOVL_m<bit top, string chr, MVEVectorVTInfo OutVTI,
@@ -2580,6 +2581,8 @@ class MVE_VSHLL_imm<string iname, string suffix, bit U, bit th,
25802581

25812582
// For the MVE_VSHLL_patterns multiclass to refer to
25822583
Operand immediateType = immtype;
2584+
2585+
let doubleWidthResult = 1;
25832586
}
25842587

25852588
// The immediate VSHLL instructions accept shift counts from 1 up to
@@ -2623,6 +2626,7 @@ class MVE_VSHLL_by_lane_width<string iname, string suffix, bits<2> size,
26232626
let Inst{11-6} = 0b111000;
26242627
let Inst{4} = 0b0;
26252628
let Inst{0} = 0b1;
2629+
let doubleWidthResult = 1;
26262630
}
26272631

26282632
multiclass MVE_VSHLL_lw<string iname, string suffix, bits<2> sz, bit U,
@@ -4357,6 +4361,7 @@ class MVE_VMULL<string iname, string suffix, bit bit_28, bits<2> bits_21_20,
43574361
let Inst{7} = Qn{3};
43584362
let Inst{0} = 0b0;
43594363
let validForTailPredication = 1;
4364+
let doubleWidthResult = 1;
43604365
}
43614366

43624367
multiclass MVE_VMULL_m<MVEVectorVTInfo VTI,
@@ -4731,6 +4736,7 @@ class MVE_VQDMULL<string iname, string suffix, bit size, bit T,
47314736
let Inst{7} = Qn{3};
47324737
let Inst{0} = 0b1;
47334738
let validForTailPredication = 1;
4739+
let doubleWidthResult = 1;
47344740
}
47354741

47364742
multiclass MVE_VQDMULL_m<string iname, MVEVectorVTInfo VTI, bit size, bit T,
@@ -4937,6 +4943,7 @@ class MVE_VQDMULL_qr<string iname, string suffix, bit size,
49374943
let Inst{8} = 0b1;
49384944
let Inst{5} = 0b1;
49394945
let validForTailPredication = 1;
4946+
let doubleWidthResult = 1;
49404947
}
49414948

49424949
multiclass MVE_VQDMULL_qr_m<string iname, MVEVectorVTInfo VTI, bit size,

llvm/lib/Target/ARM/MCTargetDesc/ARMBaseInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,10 @@ namespace ARMII {
403403
// Whether the instruction produces a scalar result from vector operands.
404404
HorizontalReduction = 1 << 22,
405405

406+
// Whether this instruction produces a vector result that is larger than
407+
// its input, typically reading from the top/bottom halves of the input(s).
408+
DoubleWidthResult = 1 << 23,
409+
406410
//===------------------------------------------------------------------===//
407411
// Code ___domain.
408412
DomainShift = 15,

llvm/unittests/Target/ARM/MachineInstrTest.cpp

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,103 @@
1010

1111
using namespace llvm;
1212

13+
TEST(MachineInstructionDoubleWidthResult, IsCorrect) {
14+
using namespace ARM;
15+
16+
auto DoubleWidthResult = [](unsigned Opcode) {
17+
switch (Opcode) {
18+
default:
19+
break;
20+
case MVE_VMULLBp16:
21+
case MVE_VMULLBp8:
22+
case MVE_VMULLBs16:
23+
case MVE_VMULLBs32:
24+
case MVE_VMULLBs8:
25+
case MVE_VMULLBu16:
26+
case MVE_VMULLBu32:
27+
case MVE_VMULLBu8:
28+
case MVE_VMULLTp16:
29+
case MVE_VMULLTp8:
30+
case MVE_VMULLTs16:
31+
case MVE_VMULLTs32:
32+
case MVE_VMULLTs8:
33+
case MVE_VMULLTu16:
34+
case MVE_VMULLTu32:
35+
case MVE_VMULLTu8:
36+
case MVE_VQDMULL_qr_s16bh:
37+
case MVE_VQDMULL_qr_s16th:
38+
case MVE_VQDMULL_qr_s32bh:
39+
case MVE_VQDMULL_qr_s32th:
40+
case MVE_VQDMULLs16bh:
41+
case MVE_VQDMULLs16th:
42+
case MVE_VQDMULLs32bh:
43+
case MVE_VQDMULLs32th:
44+
case MVE_VMOVLs16bh:
45+
case MVE_VMOVLs16th:
46+
case MVE_VMOVLs8bh:
47+
case MVE_VMOVLs8th:
48+
case MVE_VMOVLu16bh:
49+
case MVE_VMOVLu16th:
50+
case MVE_VMOVLu8bh:
51+
case MVE_VMOVLu8th:
52+
case MVE_VSHLL_imms16bh:
53+
case MVE_VSHLL_imms16th:
54+
case MVE_VSHLL_imms8bh:
55+
case MVE_VSHLL_imms8th:
56+
case MVE_VSHLL_immu16bh:
57+
case MVE_VSHLL_immu16th:
58+
case MVE_VSHLL_immu8bh:
59+
case MVE_VSHLL_immu8th:
60+
case MVE_VSHLL_lws16bh:
61+
case MVE_VSHLL_lws16th:
62+
case MVE_VSHLL_lws8bh:
63+
case MVE_VSHLL_lws8th:
64+
case MVE_VSHLL_lwu16bh:
65+
case MVE_VSHLL_lwu16th:
66+
case MVE_VSHLL_lwu8bh:
67+
case MVE_VSHLL_lwu8th:
68+
return true;
69+
}
70+
return false;
71+
};
72+
73+
LLVMInitializeARMTargetInfo();
74+
LLVMInitializeARMTarget();
75+
LLVMInitializeARMTargetMC();
76+
77+
auto TT(Triple::normalize("thumbv8.1m.main-arm-none-eabi"));
78+
std::string Error;
79+
const Target *T = TargetRegistry::lookupTarget(TT, Error);
80+
if (!T) {
81+
dbgs() << Error;
82+
return;
83+
}
84+
85+
TargetOptions Options;
86+
auto TM = std::unique_ptr<LLVMTargetMachine>(
87+
static_cast<LLVMTargetMachine*>(
88+
T->createTargetMachine(TT, "generic", "", Options, None, None,
89+
CodeGenOpt::Default)));
90+
ARMSubtarget ST(TM->getTargetTriple(), std::string(TM->getTargetCPU()),
91+
std::string(TM->getTargetFeatureString()),
92+
*static_cast<const ARMBaseTargetMachine *>(TM.get()), false);
93+
const ARMBaseInstrInfo *TII = ST.getInstrInfo();
94+
auto MII = TM->getMCInstrInfo();
95+
96+
for (unsigned i = 0; i < ARM::INSTRUCTION_LIST_END; ++i) {
97+
const MCInstrDesc &Desc = TII->get(i);
98+
99+
uint64_t Flags = Desc.TSFlags;
100+
if ((Flags & ARMII::DomainMask) != ARMII::DomainMVE)
101+
continue;
102+
103+
bool Valid = (Flags & ARMII::DoubleWidthResult) != 0;
104+
ASSERT_EQ(DoubleWidthResult(i), Valid)
105+
<< MII->getName(i)
106+
<< ": mismatched expectation for tail-predicated safety\n";
107+
}
108+
}
109+
13110
TEST(MachineInstructionHorizontalReduction, IsCorrect) {
14111
using namespace ARM;
15112

@@ -159,7 +256,6 @@ TEST(MachineInstructionHorizontalReduction, IsCorrect) {
159256
uint64_t Flags = Desc.TSFlags;
160257
if ((Flags & ARMII::DomainMask) != ARMII::DomainMVE)
161258
continue;
162-
163259
bool Valid = (Flags & ARMII::HorizontalReduction) != 0;
164260
ASSERT_EQ(HorizontalReduction(i), Valid)
165261
<< MII->getName(i)

0 commit comments

Comments
 (0)