This is an archive of the discontinued LLVM Phabricator instance.

[TableGen][SelectionDAG][X86] Add specific isel matchers for immAllZerosV/immAllOnesV. Remove bitcasts from X86 patterns that are no longer necessary.
ClosedPublic

Authored by craig.topper on Feb 24 2019, 11:57 AM.

Details

Summary

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.

Diff Detail

Event Timeline

craig.topper created this revision.Feb 24 2019, 11:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 24 2019, 11:57 AM
Herald added a subscriber: wdng. · View Herald Transcript
RKSimon added inline comments.Feb 25 2019, 3:56 AM
utils/TableGen/CodeGenDAGPatterns.cpp
1335

Add a comment describing the size?

Add comment about size.

LGTM but I'd prefer someone with more tblgen knowledge review it as well.

kparzysz accepted this revision.Mar 1 2019, 8:36 AM

Looks ok to me.

This revision is now accepted and ready to land.Mar 1 2019, 8:36 AM
This revision was automatically updated to reflect the committed changes.
shchenz added a subscriber: shchenz.Mar 5 2019, 8:12 AM

After accpet this patch, the elem MatcherTable[0] in lib/Target/PowerPC/PPCGenDAGISel.inc (same as X86GenDAGISel.inc) is not OPC_SwitchOpcode any more, it becomes OPC_Scope instead.

MatcherTable[0] sets to OPC_Scope makes container OpcodeOffset in function SelectCodeCommon() always empty, so it needs to match from the very beginning for every time matching in ISEL phase.

Maybe above issus is caused by generating of lib/Target/PowerPC/PPCGenDAGISel.inc meets crash after accept this patch.

/gsa/tlbgsa/projects/x/xlcmpbld/run/clang/main_trunk/linux_leppc/daily/latest/bin/llvm-tblgen -gen-dag-isel -I=~/llvm-project/llvm/include/ -I=./ PPC.td 
/home/czhengsz/llvm_dev/llvm-project/llvm/include//llvm/Target/TargetSelectionDAG.td:782:1: error: In vtInt: Unknown node flavor used in pattern: immAllZerosV
def vtInt      : PatLeaf<(vt),  [{ return N->getVT().isInteger(); }]>;
^
Unknown leaf kind: immAllZerosV:{ *:[v4i32] }
 #0 0x00000000102a29c4 PrintStackTraceSignalHandler(void*) (/gsa/tlbgsa/projects/x/xlcmpbld/run/clang/main_trunk/linux_leppc/daily/latest/bin/llvm-tblgen+0x102a29c4)
 #1 0x00000000102a0038 llvm::sys::RunSignalHandlers() (/gsa/tlbgsa/projects/x/xlcmpbld/run/clang/main_trunk/linux_leppc/daily/latest/bin/llvm-tblgen+0x102a0038)
 #2 0x00000000102a3140 SignalHandler(int) (/gsa/tlbgsa/projects/x/xlcmpbld/run/clang/main_trunk/linux_leppc/daily/latest/bin/llvm-tblgen+0x102a3140)
 #3 0x00003fffb5650478  0x478 __GI_abort
 #4 0x00003fffb5650478 
 #5 0x00003fffb5650478 (anonymous namespace)::MatcherGen::EmitMatchCode(llvm::TreePatternNode const*, llvm::TreePatternNode*, unsigned int) (+0x478)
 #6 0x00003fffb50a072c llvm::ConvertPatternToMatcher(llvm::PatternToMatch const&, unsigned int, llvm::CodeGenDAGPatterns const&) (/lib64/power8/libc.so.6+0x4072c)
 #7 0x0000000010122710 llvm::EmitDAGISel(llvm::RecordKeeper&, llvm::raw_ostream&) (/gsa/tlbgsa/projects/x/xlcmpbld/run/clang/main_trunk/linux_leppc/daily/latest/bin/llvm-tblgen+0x10122710)
 #8 0x000000001011f7b0 (anonymous namespace)::LLVMTableGenMain(llvm::raw_ostream&, llvm::RecordKeeper&) (/gsa/tlbgsa/projects/x/xlcmpbld/run/clang/main_trunk/linux_leppc/daily/latest/bin/llvm-tblgen+0x1011f7b0)
 #9 0x000000001010f038 llvm::TableGenMain(char*, bool (*)(llvm::raw_ostream&, llvm::RecordKeeper&)) (/gsa/tlbgsa/projects/x/xlcmpbld/run/clang/main_trunk/linux_leppc/daily/latest/bin/llvm-tblgen+0x1010f038)
#10 0x000000001023c384 main (/gsa/tlbgsa/projects/x/xlcmpbld/run/clang/main_trunk/linux_leppc/daily/latest/bin/llvm-tblgen+0x1023c384)

I think we should re-think this patch as it seems to massively increase the number of failed attempts the instruction selector makes when selecting code. Below is a trivial example:

$ cat trivial.ll 
define dso_local void @foo() {
entry:
  ret void
}

$ llc trivial.ll -debug-only=isel -mtriple=x86_64-unknown-unknown 2>&1 | grep -c 'Skipped scope entry'
106

$ pre-patch-llc trivial.ll -debug-only=isel -mtriple=x86_64-unknown-unknown 2>&1 | grep -c 'Skipped scope entry'
0

$ llc trivial.ll -debug-only=isel -mtriple=powerpc64le-unknown-unknown 2>&1 | grep -c 'Skipped scope entry'
86

$ pre-patch-llc trivial.ll -debug-only=isel -mtriple=powerpc64le-unknown-unknown 2>&1 | grep -c 'Skipped scope entry'
1

It would stand to reason that this issue would compound with real-world size code and lead to significant increases in compile time.

I'll revert the patch.