Skip to content

Commit

Permalink
Recommit r355224 "[TableGen][SelectionDAG][X86] Add specific isel mat…
Browse files Browse the repository at this point in the history
…chers for immAllZerosV/immAllOnesV. Remove bitcasts from X86 patterns that are no longer necessary."

Includes a fix to emit a CheckOpcode for build_vector when immAllZerosV/immAllOnesV is used as a pattern root. This means it can't be used to look through bitcasts when used as a root, but that's probably ok. This extra CheckOpcode will ensure that the first match in the isel table will be a SwitchOpcode which is needed by the caching optimization in the ISel Matcher.

Original commit message:

Previously we had build_vector PatFrags that called ISD::isBuildVectorAllZeros/Ones. Internally the ISD::isBuildVectorAllZeros/Ones look through bitcasts, but we aren't able to take advantage of that in isel. Instead of we have to canonicalize the types of the all zeros/ones build_vectors and insert bitcasts. Then we have to pattern match those exact bitcasts.

By emitting specific matchers for these 2 nodes, we can make isel look through any bitcasts without needing to explicitly match them. We should also be able to remove the canonicalization to vXi32 from lowering, but I've left that for a follow up.

This removes something like 40,000 bytes from the X86 isel table.

Differential Revision: https://reviews.llvm.org/D58595

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355784 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
topperc committed Mar 10, 2019
1 parent 4daee4c commit 7f41540
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 68 deletions.
2 changes: 2 additions & 0 deletions include/llvm/CodeGen/SelectionDAGISel.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class SelectionDAGISel : public MachineFunctionPass {
OPC_CheckValueType,
OPC_CheckComplexPat,
OPC_CheckAndImm, OPC_CheckOrImm,
OPC_CheckImmAllOnesV,
OPC_CheckImmAllZerosV,
OPC_CheckFoldableChainNode,

OPC_EmitInteger,
Expand Down
13 changes: 5 additions & 8 deletions include/llvm/Target/TargetSelectionDAG.td
Original file line number Diff line number Diff line change
Expand Up @@ -782,14 +782,11 @@ class FPImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm>
def vtInt : PatLeaf<(vt), [{ return N->getVT().isInteger(); }]>;
def vtFP : PatLeaf<(vt), [{ return N->getVT().isFloatingPoint(); }]>;

def immAllOnesV: PatLeaf<(build_vector), [{
return ISD::isBuildVectorAllOnes(N);
}]>;
def immAllZerosV: PatLeaf<(build_vector), [{
return ISD::isBuildVectorAllZeros(N);
}]>;


// Use ISD::isBuildVectorAllOnes or ISD::isBuildVectorAllZeros to look for
// the corresponding build_vector. Will look through bitcasts except when used
// as a pattern root.
def immAllOnesV; // ISD::isBuildVectorAllOnes
def immAllZerosV; // ISD::isBuildVectorAllZeros

// Other helper fragments.
def not : PatFrag<(ops node:$in), (xor node:$in, -1)>;
Expand Down
6 changes: 6 additions & 0 deletions lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3393,6 +3393,12 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
case OPC_CheckOrImm:
if (!::CheckOrImm(MatcherTable, MatcherIndex, N, *this)) break;
continue;
case OPC_CheckImmAllOnesV:
if (!ISD::isBuildVectorAllOnes(N.getNode())) break;
continue;
case OPC_CheckImmAllZerosV:
if (!ISD::isBuildVectorAllZeros(N.getNode())) break;
continue;

case OPC_CheckFoldableChainNode: {
assert(NodeStack.size() != 1 && "No parent node");
Expand Down
20 changes: 10 additions & 10 deletions lib/Target/SystemZ/SystemZOperators.td
Original file line number Diff line number Diff line change
Expand Up @@ -735,13 +735,13 @@ def z_vlef64 : z_vle<f64, load>;
// zeroed vector.
class z_vllez<ValueType scalartype, SDPatternOperator load, int index>
: PatFrag<(ops node:$addr),
(z_vector_insert (immAllZerosV),
(z_vector_insert immAllZerosV,
(scalartype (load node:$addr)), (i32 index))>;
def z_vllezi8 : z_vllez<i32, anyextloadi8, 7>;
def z_vllezi16 : z_vllez<i32, anyextloadi16, 3>;
def z_vllezi32 : z_vllez<i32, load, 1>;
def z_vllezi64 : PatFrags<(ops node:$addr),
[(z_vector_insert (immAllZerosV),
[(z_vector_insert immAllZerosV,
(i64 (load node:$addr)), (i32 0)),
(z_join_dwords (i64 (load node:$addr)), (i64 0))]>;
// We use high merges to form a v4f32 from four f32s. Propagating zero
Expand All @@ -755,11 +755,11 @@ def z_vllezf32 : PatFrag<(ops node:$addr),
(v4f32 (scalar_to_vector
(f32 (load node:$addr)))))))),
(v2i64
(bitconvert (v4f32 (immAllZerosV)))))>;
(bitconvert (v4f32 immAllZerosV))))>;
def z_vllezf64 : PatFrag<(ops node:$addr),
(z_merge_high
(v2f64 (scalar_to_vector (f64 (load node:$addr)))),
(immAllZerosV))>;
immAllZerosV)>;

// Similarly for the high element of a zeroed vector.
def z_vllezli32 : z_vllez<i32, load, 0>;
Expand All @@ -770,9 +770,9 @@ def z_vllezlf32 : PatFrag<(ops node:$addr),
(z_merge_high
(v4f32 (scalar_to_vector
(f32 (load node:$addr)))),
(v4f32 (immAllZerosV))))),
(v4f32 immAllZerosV)))),
(v2i64
(bitconvert (v4f32 (immAllZerosV)))))>;
(bitconvert (v4f32 immAllZerosV))))>;

// Store one element of a vector.
class z_vste<ValueType scalartype, SDPatternOperator store>
Expand All @@ -787,16 +787,16 @@ def z_vstef32 : z_vste<f32, store>;
def z_vstef64 : z_vste<f64, store>;

// Arithmetic negation on vectors.
def z_vneg : PatFrag<(ops node:$x), (sub (immAllZerosV), node:$x)>;
def z_vneg : PatFrag<(ops node:$x), (sub immAllZerosV, node:$x)>;

// Bitwise negation on vectors.
def z_vnot : PatFrag<(ops node:$x), (xor node:$x, (immAllOnesV))>;
def z_vnot : PatFrag<(ops node:$x), (xor node:$x, immAllOnesV)>;

// Signed "integer greater than zero" on vectors.
def z_vicmph_zero : PatFrag<(ops node:$x), (z_vicmph node:$x, (immAllZerosV))>;
def z_vicmph_zero : PatFrag<(ops node:$x), (z_vicmph node:$x, immAllZerosV)>;

// Signed "integer less than zero" on vectors.
def z_vicmpl_zero : PatFrag<(ops node:$x), (z_vicmph (immAllZerosV), node:$x)>;
def z_vicmpl_zero : PatFrag<(ops node:$x), (z_vicmph immAllZerosV, node:$x)>;

// Integer absolute on vectors.
class z_viabs<int shift>
Expand Down
Loading

0 comments on commit 7f41540

Please sign in to comment.