llvm.org GIT mirror llvm / 1c86ce8
[IR] add shuffle query for vector concatenation This can be used for combining and in the vectorizers/cost models. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342653 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 1 year, 27 days ago
3 changed file(s) with 67 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
25122512 /// source vector.
25132513 bool isIdentityWithExtract() const;
25142514
2515 /// Return true if this shuffle concatenates its 2 source vectors. This
2516 /// returns false if either input is undefined. In that case, the shuffle is
2517 /// is better classified as an identity with padding operation.
2518 bool isConcat() const;
2519
25152520 /// Return true if this shuffle mask chooses elements from its source vectors
25162521 /// without lane crossings. A shuffle using this mask would be
25172522 /// equivalent to a vector select with a constant condition operand.
17981798 return false;
17991799
18001800 return isIdentityMaskImpl(getShuffleMask(), NumOpElts);
1801 }
1802
1803 bool ShuffleVectorInst::isConcat() const {
1804 // Vector concatenation is differentiated from identity with padding.
1805 if (isa(Op<0>()) || isa(Op<1>()))
1806 return false;
1807
1808 int NumOpElts = Op<0>()->getType()->getVectorNumElements();
1809 int NumMaskElts = getType()->getVectorNumElements();
1810 if (NumMaskElts != NumOpElts * 2)
1811 return false;
1812
1813 // Use the mask length rather than the operands' vector lengths here. We
1814 // already know that the shuffle returns a vector twice as long as the inputs,
1815 // and neither of the inputs are undef vectors. If the mask picks consecutive
1816 // elements from both inputs, then this is a concatenation of the inputs.
1817 return isIdentityMaskImpl(getShuffleMask(), NumMaskElts);
18011818 }
18021819
18031820 //===----------------------------------------------------------------------===//
847847 EXPECT_TRUE(Id1->isIdentity());
848848 EXPECT_FALSE(Id1->isIdentityWithPadding());
849849 EXPECT_FALSE(Id1->isIdentityWithExtract());
850 EXPECT_FALSE(Id1->isConcat());
850851 delete Id1;
851852
852853 // Result has less elements than operands.
855856 EXPECT_FALSE(Id2->isIdentity());
856857 EXPECT_FALSE(Id2->isIdentityWithPadding());
857858 EXPECT_TRUE(Id2->isIdentityWithExtract());
859 EXPECT_FALSE(Id2->isConcat());
858860 delete Id2;
859861
860862 // Result has less elements than operands; choose from Op1.
863865 EXPECT_FALSE(Id3->isIdentity());
864866 EXPECT_FALSE(Id3->isIdentityWithPadding());
865867 EXPECT_TRUE(Id3->isIdentityWithExtract());
868 EXPECT_FALSE(Id3->isConcat());
866869 delete Id3;
867870
868871 // Result has less elements than operands; choose from Op0 and Op1 is not identity.
871874 EXPECT_FALSE(Id4->isIdentity());
872875 EXPECT_FALSE(Id4->isIdentityWithPadding());
873876 EXPECT_FALSE(Id4->isIdentityWithExtract());
877 EXPECT_FALSE(Id4->isConcat());
874878 delete Id4;
875879
876880 // Result has more elements than operands, and extra elements are undef.
879883 EXPECT_FALSE(Id5->isIdentity());
880884 EXPECT_TRUE(Id5->isIdentityWithPadding());
881885 EXPECT_FALSE(Id5->isIdentityWithExtract());
886 EXPECT_FALSE(Id5->isConcat());
882887 delete Id5;
883888
884889 // Result has more elements than operands, and extra elements are undef; choose from Op1.
887892 EXPECT_FALSE(Id6->isIdentity());
888893 EXPECT_TRUE(Id6->isIdentityWithPadding());
889894 EXPECT_FALSE(Id6->isIdentityWithExtract());
895 EXPECT_FALSE(Id6->isConcat());
890896 delete Id6;
891897
892898 // Result has more elements than operands, but extra elements are not undef.
895901 EXPECT_FALSE(Id7->isIdentity());
896902 EXPECT_FALSE(Id7->isIdentityWithPadding());
897903 EXPECT_FALSE(Id7->isIdentityWithExtract());
904 EXPECT_FALSE(Id7->isConcat());
898905 delete Id7;
899906
900907 // Result has more elements than operands; choose from Op0 and Op1 is not identity.
903910 EXPECT_FALSE(Id8->isIdentity());
904911 EXPECT_FALSE(Id8->isIdentityWithPadding());
905912 EXPECT_FALSE(Id8->isIdentityWithExtract());
913 EXPECT_FALSE(Id8->isConcat());
906914 delete Id8;
915
916 // Result has twice as many elements as operands; choose consecutively from Op0 and Op1 is concat.
917 ShuffleVectorInst *Id9 = new ShuffleVectorInst(V0, V1,
918 ConstantVector::get({C0, CU, C2, C3, CU, CU, C6, C7}));
919 EXPECT_FALSE(Id9->isIdentity());
920 EXPECT_FALSE(Id9->isIdentityWithPadding());
921 EXPECT_FALSE(Id9->isIdentityWithExtract());
922 EXPECT_TRUE(Id9->isConcat());
923 delete Id9;
924
925 // Result has less than twice as many elements as operands, so not a concat.
926 ShuffleVectorInst *Id10 = new ShuffleVectorInst(V0, V1,
927 ConstantVector::get({C0, CU, C2, C3, CU, CU, C6}));
928 EXPECT_FALSE(Id10->isIdentity());
929 EXPECT_FALSE(Id10->isIdentityWithPadding());
930 EXPECT_FALSE(Id10->isIdentityWithExtract());
931 EXPECT_FALSE(Id10->isConcat());
932 delete Id10;
933
934 // Result has more than twice as many elements as operands, so not a concat.
935 ShuffleVectorInst *Id11 = new ShuffleVectorInst(V0, V1,
936 ConstantVector::get({C0, CU, C2, C3, CU, CU, C6, C7, CU}));
937 EXPECT_FALSE(Id11->isIdentity());
938 EXPECT_FALSE(Id11->isIdentityWithPadding());
939 EXPECT_FALSE(Id11->isIdentityWithExtract());
940 EXPECT_FALSE(Id11->isConcat());
941 delete Id11;
942
943 // If an input is undef, it's not a concat.
944 // TODO: IdentityWithPadding should be true here even though the high mask values are not undef.
945 ShuffleVectorInst *Id12 = new ShuffleVectorInst(V0, ConstantVector::get({CU, CU, CU, CU}),
946 ConstantVector::get({C0, CU, C2, C3, CU, CU, C6, C7}));
947 EXPECT_FALSE(Id12->isIdentity());
948 EXPECT_FALSE(Id12->isIdentityWithPadding());
949 EXPECT_FALSE(Id12->isIdentityWithExtract());
950 EXPECT_FALSE(Id12->isConcat());
951 delete Id12;
907952 }
908953
909954 TEST(InstructionsTest, SkipDebug) {