Skip to content

Commit ea96040

Browse files
topperctru
authored andcommitted
[Mips] Change vsplat_imm_eq_1 to a ComplexPattern. (#116471)
Resolves a FIXME and avoids needing to workaround #116075. Adding parentheses around the (vsplat_imm_eq_1) fixes the error cited in the FIXME by changing the ComplexPattern from a leaf node to an operator. (cherry picked from commit 2f4572f)
1 parent fb6b195 commit ea96040

File tree

5 files changed

+43
-38
lines changed

5 files changed

+43
-38
lines changed

llvm/lib/Target/Mips/MipsISelDAGToDAG.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ bool MipsDAGToDAGISel::selectVSplatMaskR(SDValue N, SDValue &Imm) const {
220220
return false;
221221
}
222222

223+
bool MipsDAGToDAGISel::selectVSplatImmEq1(SDValue N) const {
224+
llvm_unreachable("Unimplemented function.");
225+
}
226+
223227
/// Convert vector addition with vector subtraction if that allows to encode
224228
/// constant as an immediate and thus avoid extra 'ldi' instruction.
225229
/// add X, <-1, -1...> --> sub X, <1, 1...>

llvm/lib/Target/Mips/MipsISelDAGToDAG.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ class MipsDAGToDAGISel : public SelectionDAGISel {
120120
/// starting at bit zero.
121121
virtual bool selectVSplatMaskR(SDValue N, SDValue &Imm) const;
122122

123+
/// Select constant vector splats whose value is 1.
124+
virtual bool selectVSplatImmEq1(SDValue N) const;
125+
123126
/// Convert vector addition with vector subtraction if that allows to encode
124127
/// constant as an immediate and thus avoid extra 'ldi' instruction.
125128
/// add X, <-1, -1...> --> sub X, <1, 1...>

llvm/lib/Target/Mips/MipsMSAInstrInfo.td

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,8 @@ def vsplati32 : PatFrag<(ops node:$e0),
198198
(v4i32 (build_vector node:$e0, node:$e0,
199199
node:$e0, node:$e0))>;
200200

201-
def vsplati64_imm_eq_1 : PatLeaf<(bitconvert (v4i32 (build_vector))), [{
202-
APInt Imm;
203-
SDNode *BV = N->getOperand(0).getNode();
204-
EVT EltTy = N->getValueType(0).getVectorElementType();
205-
206-
return selectVSplat(BV, Imm, EltTy.getSizeInBits()) &&
207-
Imm.getBitWidth() == EltTy.getSizeInBits() && Imm == 1;
208-
}]>;
201+
// Any build_vector that is a constant splat with a value that equals 1
202+
def vsplat_imm_eq_1 : ComplexPattern<vAny, 0, "selectVSplatImmEq1">;
209203

210204
def vsplati64 : PatFrag<(ops node:$e0),
211205
(v2i64 (build_vector node:$e0, node:$e0))>;
@@ -217,7 +211,7 @@ def vsplati64_splat_d : PatFrag<(ops node:$e0),
217211
node:$e0,
218212
node:$e0,
219213
node:$e0)),
220-
vsplati64_imm_eq_1))))>;
214+
(vsplat_imm_eq_1)))))>;
221215

222216
def vsplatf32 : PatFrag<(ops node:$e0),
223217
(v4f32 (build_vector node:$e0, node:$e0,
@@ -352,46 +346,35 @@ def vsplat_maskr_bits_uimm6
352346
: SplatComplexPattern<vsplat_uimm6, vAny, 1, "selectVSplatMaskR",
353347
[build_vector, bitconvert]>;
354348

355-
// Any build_vector that is a constant splat with a value that equals 1
356-
// FIXME: These should be a ComplexPattern but we can't use them because the
357-
// ISel generator requires the uses to have a name, but providing a name
358-
// causes other errors ("used in pattern but not operand list")
359-
def vsplat_imm_eq_1 : PatLeaf<(build_vector), [{
360-
APInt Imm;
361-
EVT EltTy = N->getValueType(0).getVectorElementType();
362-
363-
return selectVSplat(N, Imm, EltTy.getSizeInBits()) &&
364-
Imm.getBitWidth() == EltTy.getSizeInBits() && Imm == 1;
365-
}]>;
366349

367350
def vbclr_b : PatFrag<(ops node:$ws, node:$wt),
368-
(and node:$ws, (vnot (shl vsplat_imm_eq_1, node:$wt)))>;
351+
(and node:$ws, (vnot (shl (vsplat_imm_eq_1), node:$wt)))>;
369352
def vbclr_h : PatFrag<(ops node:$ws, node:$wt),
370-
(and node:$ws, (vnot (shl vsplat_imm_eq_1, node:$wt)))>;
353+
(and node:$ws, (vnot (shl (vsplat_imm_eq_1), node:$wt)))>;
371354
def vbclr_w : PatFrag<(ops node:$ws, node:$wt),
372-
(and node:$ws, (vnot (shl vsplat_imm_eq_1, node:$wt)))>;
355+
(and node:$ws, (vnot (shl (vsplat_imm_eq_1), node:$wt)))>;
373356
def vbclr_d : PatFrag<(ops node:$ws, node:$wt),
374-
(and node:$ws, (vnot (shl (v2i64 vsplati64_imm_eq_1),
357+
(and node:$ws, (vnot (shl (v2i64 (vsplat_imm_eq_1)),
375358
node:$wt)))>;
376359

377360
def vbneg_b : PatFrag<(ops node:$ws, node:$wt),
378-
(xor node:$ws, (shl vsplat_imm_eq_1, node:$wt))>;
361+
(xor node:$ws, (shl (vsplat_imm_eq_1), node:$wt))>;
379362
def vbneg_h : PatFrag<(ops node:$ws, node:$wt),
380-
(xor node:$ws, (shl vsplat_imm_eq_1, node:$wt))>;
363+
(xor node:$ws, (shl (vsplat_imm_eq_1), node:$wt))>;
381364
def vbneg_w : PatFrag<(ops node:$ws, node:$wt),
382-
(xor node:$ws, (shl vsplat_imm_eq_1, node:$wt))>;
365+
(xor node:$ws, (shl (vsplat_imm_eq_1), node:$wt))>;
383366
def vbneg_d : PatFrag<(ops node:$ws, node:$wt),
384-
(xor node:$ws, (shl (v2i64 vsplati64_imm_eq_1),
367+
(xor node:$ws, (shl (v2i64 (vsplat_imm_eq_1)),
385368
node:$wt))>;
386369

387370
def vbset_b : PatFrag<(ops node:$ws, node:$wt),
388-
(or node:$ws, (shl vsplat_imm_eq_1, node:$wt))>;
371+
(or node:$ws, (shl (vsplat_imm_eq_1), node:$wt))>;
389372
def vbset_h : PatFrag<(ops node:$ws, node:$wt),
390-
(or node:$ws, (shl vsplat_imm_eq_1, node:$wt))>;
373+
(or node:$ws, (shl (vsplat_imm_eq_1), node:$wt))>;
391374
def vbset_w : PatFrag<(ops node:$ws, node:$wt),
392-
(or node:$ws, (shl vsplat_imm_eq_1, node:$wt))>;
375+
(or node:$ws, (shl (vsplat_imm_eq_1), node:$wt))>;
393376
def vbset_d : PatFrag<(ops node:$ws, node:$wt),
394-
(or node:$ws, (shl (v2i64 vsplati64_imm_eq_1),
377+
(or node:$ws, (shl (v2i64 (vsplat_imm_eq_1)),
395378
node:$wt))>;
396379

397380
def muladd : PatFrag<(ops node:$wd, node:$ws, node:$wt),
@@ -3842,7 +3825,7 @@ class MSAShiftPat<SDNode Node, ValueType VT, MSAInst Insn, dag Vec> :
38423825
(VT (Insn VT:$ws, VT:$wt))>;
38433826

38443827
class MSABitPat<SDNode Node, ValueType VT, MSAInst Insn, PatFrag Frag> :
3845-
MSAPat<(VT (Node VT:$ws, (shl vsplat_imm_eq_1, (Frag VT:$wt)))),
3828+
MSAPat<(VT (Node VT:$ws, (shl (vsplat_imm_eq_1), (Frag VT:$wt)))),
38463829
(VT (Insn VT:$ws, VT:$wt))>;
38473830

38483831
multiclass MSAShiftPats<SDNode Node, string Insn> {
@@ -3861,7 +3844,7 @@ multiclass MSABitPats<SDNode Node, string Insn> {
38613844
def : MSABitPat<Node, v16i8, !cast<MSAInst>(Insn#_B), vsplati8imm7>;
38623845
def : MSABitPat<Node, v8i16, !cast<MSAInst>(Insn#_H), vsplati16imm15>;
38633846
def : MSABitPat<Node, v4i32, !cast<MSAInst>(Insn#_W), vsplati32imm31>;
3864-
def : MSAPat<(Node v2i64:$ws, (shl (v2i64 vsplati64_imm_eq_1),
3847+
def : MSAPat<(Node v2i64:$ws, (shl (v2i64 (vsplat_imm_eq_1)),
38653848
(vsplati64imm63 v2i64:$wt))),
38663849
(v2i64 (!cast<MSAInst>(Insn#_D) v2i64:$ws, v2i64:$wt))>;
38673850
}
@@ -3872,16 +3855,16 @@ defm : MSAShiftPats<sra, "SRA">;
38723855
defm : MSABitPats<xor, "BNEG">;
38733856
defm : MSABitPats<or, "BSET">;
38743857

3875-
def : MSAPat<(and v16i8:$ws, (vnot (shl vsplat_imm_eq_1,
3858+
def : MSAPat<(and v16i8:$ws, (vnot (shl (vsplat_imm_eq_1),
38763859
(vsplati8imm7 v16i8:$wt)))),
38773860
(v16i8 (BCLR_B v16i8:$ws, v16i8:$wt))>;
3878-
def : MSAPat<(and v8i16:$ws, (vnot (shl vsplat_imm_eq_1,
3861+
def : MSAPat<(and v8i16:$ws, (vnot (shl (vsplat_imm_eq_1),
38793862
(vsplati16imm15 v8i16:$wt)))),
38803863
(v8i16 (BCLR_H v8i16:$ws, v8i16:$wt))>;
3881-
def : MSAPat<(and v4i32:$ws, (vnot (shl vsplat_imm_eq_1,
3864+
def : MSAPat<(and v4i32:$ws, (vnot (shl (vsplat_imm_eq_1),
38823865
(vsplati32imm31 v4i32:$wt)))),
38833866
(v4i32 (BCLR_W v4i32:$ws, v4i32:$wt))>;
3884-
def : MSAPat<(and v2i64:$ws, (vnot (shl (v2i64 vsplati64_imm_eq_1),
3867+
def : MSAPat<(and v2i64:$ws, (vnot (shl (v2i64 (vsplat_imm_eq_1)),
38853868
(vsplati64imm63 v2i64:$wt)))),
38863869
(v2i64 (BCLR_D v2i64:$ws, v2i64:$wt))>;
38873870

llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,18 @@ bool MipsSEDAGToDAGISel::selectVSplatUimmInvPow2(SDValue N,
730730
return false;
731731
}
732732

733+
// Select const vector splat of 1.
734+
bool MipsSEDAGToDAGISel::selectVSplatImmEq1(SDValue N) const {
735+
APInt ImmValue;
736+
EVT EltTy = N->getValueType(0).getVectorElementType();
737+
738+
if (N->getOpcode() == ISD::BITCAST)
739+
N = N->getOperand(0);
740+
741+
return selectVSplat(N.getNode(), ImmValue, EltTy.getSizeInBits()) &&
742+
ImmValue.getBitWidth() == EltTy.getSizeInBits() && ImmValue == 1;
743+
}
744+
733745
bool MipsSEDAGToDAGISel::trySelect(SDNode *Node) {
734746
unsigned Opcode = Node->getOpcode();
735747
SDLoc DL(Node);

llvm/lib/Target/Mips/MipsSEISelDAGToDAG.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ class MipsSEDAGToDAGISel : public MipsDAGToDAGISel {
124124
/// starting at bit zero.
125125
bool selectVSplatMaskR(SDValue N, SDValue &Imm) const override;
126126

127+
/// Select constant vector splats whose value is 1.
128+
bool selectVSplatImmEq1(SDValue N) const override;
129+
127130
bool trySelect(SDNode *Node) override;
128131

129132
// Emits proper ABI for _mcount profiling calls.

0 commit comments

Comments
 (0)