llvm.org GIT mirror llvm / 5cc6baa
Revert [SLP] Look-ahead operand reordering heuristic. This reverts r364478 (git commit 574cb0eb3a7ac95e62d223a60bef891171dfe321) The patch is causing compilation timeouts. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364846 91177308-0d34-0410-b5e6-96231b3b80d8 Jordan Rupprecht 2 months ago
2 changed file(s) with 94 addition(s) and 324 deletion(s). Raw diff Collapse all Expand all
145145 static cl::opt MinTreeSize(
146146 "slp-min-tree-size", cl::init(3), cl::Hidden,
147147 cl::desc("Only vectorize small trees if they are fully vectorizable"));
148
149 // The maximum depth that the look-ahead score heuristic will explore.
150 // The higher this value, the higher the compilation time overhead.
151 static cl::opt LookAheadMaxDepth(
152 "slp-max-look-ahead-depth", cl::init(2), cl::Hidden,
153 cl::desc("The maximum look-ahead depth for operand reordering scores"));
154148
155149 static cl::opt
156150 ViewSLPTree("view-slp-tree", cl::Hidden,
713707
714708 const DataLayout &DL;
715709 ScalarEvolution &SE;
716 const BoUpSLP &R;
717710
718711 /// \returns the operand data at \p OpIdx and \p Lane.
719712 OperandData &getData(unsigned OpIdx, unsigned Lane) {
739732 std::swap(OpsVec[OpIdx1][Lane], OpsVec[OpIdx2][Lane]);
740733 }
741734
742 // The hard-coded scores listed here are not very important. When computing
743 // the scores of matching one sub-tree with another, we are basically
744 // counting the number of values that are matching. So even if all scores
745 // are set to 1, we would still get a decent matching result.
746 // However, sometimes we have to break ties. For example we may have to
747 // choose between matching loads vs matching opcodes. This is what these
748 // scores are helping us with: they provide the order of preference.
749
750 /// Loads from consecutive memory addresses, e.g. load(A[i]), load(A[i+1]).
751 static const int ScoreConsecutiveLoads = 3;
752 /// Constants.
753 static const int ScoreConstants = 2;
754 /// Instructions with the same opcode.
755 static const int ScoreSameOpcode = 2;
756 /// Instructions with alt opcodes (e.g, add + sub).
757 static const int ScoreAltOpcodes = 1;
758 /// Identical instructions (a.k.a. splat or broadcast).
759 static const int ScoreSplat = 1;
760 /// Matching with an undef is preferable to failing.
761 static const int ScoreUndef = 1;
762 /// Score for failing to find a decent match.
763 static const int ScoreFail = 0;
764 /// User exteranl to the vectorized code.
765 static const int ExternalUseCost = 1;
766 /// The user is internal but in a different lane.
767 static const int UserInDiffLaneCost = ExternalUseCost;
768
769 /// \returns the score of placing \p V1 and \p V2 in consecutive lanes.
770 static int getShallowScore(Value *V1, Value *V2, const DataLayout &DL,
771 ScalarEvolution &SE) {
772 auto *LI1 = dyn_cast(V1);
773 auto *LI2 = dyn_cast(V2);
774 if (LI1 && LI2)
775 return isConsecutiveAccess(LI1, LI2, DL, SE)
776 ? VLOperands::ScoreConsecutiveLoads
777 : VLOperands::ScoreFail;
778
779 auto *C1 = dyn_cast(V1);
780 auto *C2 = dyn_cast(V2);
781 if (C1 && C2)
782 return VLOperands::ScoreConstants;
783
784 auto *I1 = dyn_cast(V1);
785 auto *I2 = dyn_cast(V2);
786 if (I1 && I2) {
787 if (I1 == I2)
788 return VLOperands::ScoreSplat;
789 InstructionsState S = getSameOpcode({I1, I2});
790 // Note: Only consider instructions with <= 2 operands to avoid
791 // complexity explosion.
792 if (S.getOpcode() && S.MainOp->getNumOperands() <= 2)
793 return S.isAltShuffle() ? VLOperands::ScoreAltOpcodes
794 : VLOperands::ScoreSameOpcode;
795 }
796
797 if (isa(V2))
798 return VLOperands::ScoreUndef;
799
800 return VLOperands::ScoreFail;
801 }
802
803 /// Holds the values and their lane that are taking part in the look-ahead
804 /// score calculation. This is used in the external uses cost calculation.
805 SmallDenseMap InLookAheadValues;
806
807 /// \Returns the additinal cost due to uses of \p LHS and \p RHS that are
808 /// either external to the vectorized code, or require shuffling.
809 int getExternalUsesCost(const std::pair &LHS,
810 const std::pair &RHS) {
811 int Cost = 0;
812 SmallVector, 2> Values = {LHS, RHS};
813 for (int Idx = 0, IdxE = Values.size(); Idx != IdxE; ++Idx) {
814 Value *V = Values[Idx].first;
815 // Calculate the absolute lane, using the minimum relative lane of LHS
816 // and RHS as base and Idx as the offset.
817 int Ln = std::min(LHS.second, RHS.second) + Idx;
818 assert(Ln >= 0 && "Bad lane calculation");
819 for (User *U : V->users()) {
820 if (const TreeEntry *UserTE = R.getTreeEntry(U)) {
821 // The user is in the VectorizableTree. Check if we need to insert.
822 auto It = llvm::find(UserTE->Scalars, U);
823 assert(It != UserTE->Scalars.end() && "U is in UserTE");
824 int UserLn = std::distance(UserTE->Scalars.begin(), It);
825 assert(UserLn >= 0 && "Bad lane");
826 if (UserLn != Ln)
827 Cost += UserInDiffLaneCost;
828 } else {
829 // Check if the user is in the look-ahead code.
830 auto It2 = InLookAheadValues.find(U);
831 if (It2 != InLookAheadValues.end()) {
832 // The user is in the look-ahead code. Check the lane.
833 if (It2->second != Ln)
834 Cost += UserInDiffLaneCost;
835 } else {
836 // The user is neither in SLP tree nor in the look-ahead code.
837 Cost += ExternalUseCost;
838 }
839 }
840 }
841 }
842 return Cost;
843 }
844
845 /// Go through the operands of \p LHS and \p RHS recursively until \p
846 /// MaxLevel, and return the cummulative score. For example:
847 /// \verbatim
848 /// A[0] B[0] A[1] B[1] C[0] D[0] B[1] A[1]
849 /// \ / \ / \ / \ /
850 /// + + + +
851 /// G1 G2 G3 G4
852 /// \endverbatim
853 /// The getScoreAtLevelRec(G1, G2) function will try to match the nodes at
854 /// each level recursively, accumulating the score. It starts from matching
855 /// the additions at level 0, then moves on to the loads (level 1). The
856 /// score of G1 and G2 is higher than G1 and G3, because {A[0],A[1]} and
857 /// {B[0],B[1]} match with VLOperands::ScoreConsecutiveLoads, while
858 /// {A[0],C[0]} has a score of VLOperands::ScoreFail.
859 /// Please note that the order of the operands does not matter, as we
860 /// evaluate the score of all profitable combinations of operands. In
861 /// other words the score of G1 and G4 is the same as G1 and G2. This
862 /// heuristic is based on ideas described in:
863 /// Look-ahead SLP: Auto-vectorization in the presence of commutative
864 /// operations, CGO 2018 by Vasileios Porpodas, Rodrigo C. O. Rocha,
865 /// Luís F. W. Góes
866 int getScoreAtLevelRec(const std::pair &LHS,
867 const std::pair &RHS, int CurrLevel,
868 int MaxLevel) {
869
870 Value *V1 = LHS.first;
871 Value *V2 = RHS.first;
872 // Get the shallow score of V1 and V2.
873 int ShallowScoreAtThisLevel =
874 std::max((int)ScoreFail, getShallowScore(V1, V2, DL, SE) -
875 getExternalUsesCost(LHS, RHS));
876 int Lane1 = LHS.second;
877 int Lane2 = RHS.second;
878
879 // If reached MaxLevel,
880 // or if V1 and V2 are not instructions,
881 // or if they are SPLAT,
882 // or if they are not consecutive, early return the current cost.
883 auto *I1 = dyn_cast(V1);
884 auto *I2 = dyn_cast(V2);
885 if (CurrLevel == MaxLevel || !(I1 && I2) || I1 == I2 ||
886 ShallowScoreAtThisLevel == VLOperands::ScoreFail ||
887 (isa(I1) && isa(I2) && ShallowScoreAtThisLevel))
888 return ShallowScoreAtThisLevel;
889 assert(I1 && I2 && "Should have early exited.");
890
891 // Keep track of in-tree values for determining the external-use cost.
892 InLookAheadValues[V1] = Lane1;
893 InLookAheadValues[V2] = Lane2;
894
895 // Contains the I2 operand indexes that got matched with I1 operands.
896 SmallSet Op2Used;
897
898 // Recursion towards the operands of I1 and I2. We are trying all possbile
899 // operand pairs, and keeping track of the best score.
900 for (unsigned OpIdx1 = 0, NumOperands1 = I1->getNumOperands();
901 OpIdx1 != NumOperands1; ++OpIdx1) {
902 // Try to pair op1I with the best operand of I2.
903 int MaxTmpScore = 0;
904 unsigned MaxOpIdx2 = 0;
905 bool FoundBest = false;
906 // If I2 is commutative try all combinations.
907 unsigned FromIdx = isCommutative(I2) ? 0 : OpIdx1;
908 unsigned ToIdx = isCommutative(I2)
909 ? I2->getNumOperands()
910 : std::min(I2->getNumOperands(), OpIdx1 + 1);
911 assert(FromIdx <= ToIdx && "Bad index");
912 for (unsigned OpIdx2 = FromIdx; OpIdx2 != ToIdx; ++OpIdx2) {
913 // Skip operands already paired with OpIdx1.
914 if (Op2Used.count(OpIdx2))
915 continue;
916 // Recursively calculate the cost at each level
917 int TmpScore = getScoreAtLevelRec({I1->getOperand(OpIdx1), Lane1},
918 {I2->getOperand(OpIdx2), Lane2},
919 CurrLevel + 1, MaxLevel);
920 // Look for the best score.
921 if (TmpScore > VLOperands::ScoreFail && TmpScore > MaxTmpScore) {
922 MaxTmpScore = TmpScore;
923 MaxOpIdx2 = OpIdx2;
924 FoundBest = true;
925 }
926 }
927 if (FoundBest) {
928 // Pair {OpIdx1, MaxOpIdx2} was found to be best. Never revisit it.
929 Op2Used.insert(MaxOpIdx2);
930 ShallowScoreAtThisLevel += MaxTmpScore;
931 }
932 }
933 return ShallowScoreAtThisLevel;
934 }
935
936 /// \Returns the look-ahead score, which tells us how much the sub-trees
937 /// rooted at \p LHS and \p RHS match, the more they match the higher the
938 /// score. This helps break ties in an informed way when we cannot decide on
939 /// the order of the operands by just considering the immediate
940 /// predecessors.
941 int getLookAheadScore(const std::pair &LHS,
942 const std::pair &RHS) {
943 InLookAheadValues.clear();
944 return getScoreAtLevelRec(LHS, RHS, 1, LookAheadMaxDepth);
945 }
946
947735 // Search all operands in Ops[*][Lane] for the one that matches best
948736 // Ops[OpIdx][LastLane] and return its opreand index.
949737 // If no good match can be found, return None.
961749 // The linearized opcode of the operand at OpIdx, Lane.
962750 bool OpIdxAPO = getData(OpIdx, Lane).APO;
963751
752 const unsigned BestScore = 2;
753 const unsigned GoodScore = 1;
754
964755 // The best operand index and its score.
965756 // Sometimes we have more than one option (e.g., Opcode and Undefs), so we
966757 // are using the score to differentiate between the two.
989780 // Look for an operand that matches the current mode.
990781 switch (RMode) {
991782 case ReorderingMode::Load:
992 case ReorderingMode::Constant:
993 case ReorderingMode::Opcode: {
994 bool LeftToRight = Lane > LastLane;
995 Value *OpLeft = (LeftToRight) ? OpLastLane : Op;
996 Value *OpRight = (LeftToRight) ? Op : OpLastLane;
997 unsigned Score =
998 getLookAheadScore({OpLeft, LastLane}, {OpRight, Lane});
999 if (Score > BestOp.Score) {
1000 BestOp.Idx = Idx;
1001 BestOp.Score = Score;
783 if (isa(Op)) {
784 // Figure out which is left and right, so that we can check for
785 // consecutive loads
786 bool LeftToRight = Lane > LastLane;
787 Value *OpLeft = (LeftToRight) ? OpLastLane : Op;
788 Value *OpRight = (LeftToRight) ? Op : OpLastLane;
789 if (isConsecutiveAccess(cast(OpLeft),
790 cast(OpRight), DL, SE))
791 BestOp.Idx = Idx;
1002792 }
1003793 break;
1004 }
794 case ReorderingMode::Opcode:
795 // We accept both Instructions and Undefs, but with different scores.
796 if ((isa(Op) && isa(OpLastLane) &&
797 cast(Op)->getOpcode() ==
798 cast(OpLastLane)->getOpcode()) ||
799 (isa(OpLastLane) && isa(Op)) ||
800 isa(Op)) {
801 // An instruction has a higher score than an undef.
802 unsigned Score = (isa(Op)) ? GoodScore : BestScore;
803 if (Score > BestOp.Score) {
804 BestOp.Idx = Idx;
805 BestOp.Score = Score;
806 }
807 }
808 break;
809 case ReorderingMode::Constant:
810 if (isa(Op)) {
811 unsigned Score = (isa(Op)) ? GoodScore : BestScore;
812 if (Score > BestOp.Score) {
813 BestOp.Idx = Idx;
814 BestOp.Score = Score;
815 }
816 }
817 break;
1005818 case ReorderingMode::Splat:
1006819 if (Op == OpLastLane)
1007820 BestOp.Idx = Idx;
1132945 public:
1133946 /// Initialize with all the operands of the instruction vector \p RootVL.
1134947 VLOperands(ArrayRef RootVL, const DataLayout &DL,
1135 ScalarEvolution &SE, const BoUpSLP &R)
1136 : DL(DL), SE(SE), R(R) {
948 ScalarEvolution &SE)
949 : DL(DL), SE(SE) {
1137950 // Append all the operands of RootVL.
1138951 appendOperandsOfVL(RootVL);
1139952 }
13551168 SmallVectorImpl &Left,
13561169 SmallVectorImpl &Right,
13571170 const DataLayout &DL,
1358 ScalarEvolution &SE,
1359 const BoUpSLP &R);
1171 ScalarEvolution &SE);
13601172 struct TreeEntry {
13611173 using VecTreeTy = SmallVector, 8>;
13621174 TreeEntry(VecTreeTy &Container) : Container(Container) {}
25582370 // Commutative predicate - collect + sort operands of the instructions
25592371 // so that each side is more likely to have the same opcode.
25602372 assert(P0 == SwapP0 && "Commutative Predicate mismatch");
2561 reorderInputsAccordingToOpcode(VL, Left, Right, *DL, *SE, *this);
2373 reorderInputsAccordingToOpcode(VL, Left, Right, *DL, *SE);
25622374 } else {
25632375 // Collect operands - commute if it uses the swapped predicate.
25642376 for (Value *V : VL) {
26032415 // have the same opcode.
26042416 if (isa(VL0) && VL0->isCommutative()) {
26052417 ValueList Left, Right;
2606 reorderInputsAccordingToOpcode(VL, Left, Right, *DL, *SE, *this);
2418 reorderInputsAccordingToOpcode(VL, Left, Right, *DL, *SE);
26072419 buildTree_rec(Left, Depth + 1, {TE, 0});
26082420 buildTree_rec(Right, Depth + 1, {TE, 1});
26092421 return;
27722584 // Reorder operands if reordering would enable vectorization.
27732585 if (isa(VL0)) {
27742586 ValueList Left, Right;
2775 reorderInputsAccordingToOpcode(VL, Left, Right, *DL, *SE, *this);
2587 reorderInputsAccordingToOpcode(VL, Left, Right, *DL, *SE);
27762588 buildTree_rec(Left, Depth + 1, {TE, 0});
27772589 buildTree_rec(Right, Depth + 1, {TE, 1});
27782590 return;
34893301
34903302 // Perform operand reordering on the instructions in VL and return the reordered
34913303 // operands in Left and Right.
3492 void BoUpSLP::reorderInputsAccordingToOpcode(ArrayRef VL,
3493 SmallVectorImpl &Left,
3494 SmallVectorImpl &Right,
3495 const DataLayout &DL,
3496 ScalarEvolution &SE,
3497 const BoUpSLP &R) {
3304 void BoUpSLP::reorderInputsAccordingToOpcode(
3305 ArrayRef VL, SmallVectorImpl &Left,
3306 SmallVectorImpl &Right, const DataLayout &DL,
3307 ScalarEvolution &SE) {
34983308 if (VL.empty())
34993309 return;
3500 VLOperands Ops(VL, DL, SE, R);
3310 VLOperands Ops(VL, DL, SE);
35013311 // Reorder the operands in place.
35023312 Ops.reorder();
35033313 Left = Ops.getVL(0);
2626 ; CHECK-NEXT: [[IDX5:%.*]] = getelementptr inbounds double, double* [[ARRAY]], i64 5
2727 ; CHECK-NEXT: [[IDX6:%.*]] = getelementptr inbounds double, double* [[ARRAY]], i64 6
2828 ; CHECK-NEXT: [[IDX7:%.*]] = getelementptr inbounds double, double* [[ARRAY]], i64 7
29 ; CHECK-NEXT: [[TMP0:%.*]] = bitcast double* [[IDX0]] to <2 x double>*
30 ; CHECK-NEXT: [[TMP1:%.*]] = load <2 x double>, <2 x double>* [[TMP0]], align 8
31 ; CHECK-NEXT: [[TMP2:%.*]] = bitcast double* [[IDX2]] to <2 x double>*
32 ; CHECK-NEXT: [[TMP3:%.*]] = load <2 x double>, <2 x double>* [[TMP2]], align 8
33 ; CHECK-NEXT: [[TMP4:%.*]] = bitcast double* [[IDX4]] to <2 x double>*
34 ; CHECK-NEXT: [[TMP5:%.*]] = load <2 x double>, <2 x double>* [[TMP4]], align 8
35 ; CHECK-NEXT: [[TMP6:%.*]] = bitcast double* [[IDX6]] to <2 x double>*
36 ; CHECK-NEXT: [[TMP7:%.*]] = load <2 x double>, <2 x double>* [[TMP6]], align 8
37 ; CHECK-NEXT: [[TMP8:%.*]] = fsub fast <2 x double> [[TMP1]], [[TMP3]]
38 ; CHECK-NEXT: [[TMP9:%.*]] = fsub fast <2 x double> [[TMP5]], [[TMP7]]
39 ; CHECK-NEXT: [[TMP10:%.*]] = fadd fast <2 x double> [[TMP8]], [[TMP9]]
40 ; CHECK-NEXT: [[TMP11:%.*]] = bitcast double* [[IDX0]] to <2 x double>*
41 ; CHECK-NEXT: store <2 x double> [[TMP10]], <2 x double>* [[TMP11]], align 8
29 ; CHECK-NEXT: [[A_0:%.*]] = load double, double* [[IDX0]], align 8
30 ; CHECK-NEXT: [[A_1:%.*]] = load double, double* [[IDX1]], align 8
31 ; CHECK-NEXT: [[B_0:%.*]] = load double, double* [[IDX2]], align 8
32 ; CHECK-NEXT: [[B_1:%.*]] = load double, double* [[IDX3]], align 8
33 ; CHECK-NEXT: [[C_0:%.*]] = load double, double* [[IDX4]], align 8
34 ; CHECK-NEXT: [[C_1:%.*]] = load double, double* [[IDX5]], align 8
35 ; CHECK-NEXT: [[D_0:%.*]] = load double, double* [[IDX6]], align 8
36 ; CHECK-NEXT: [[D_1:%.*]] = load double, double* [[IDX7]], align 8
37 ; CHECK-NEXT: [[SUBAB_0:%.*]] = fsub fast double [[A_0]], [[B_0]]
38 ; CHECK-NEXT: [[SUBCD_0:%.*]] = fsub fast double [[C_0]], [[D_0]]
39 ; CHECK-NEXT: [[SUBAB_1:%.*]] = fsub fast double [[A_1]], [[B_1]]
40 ; CHECK-NEXT: [[SUBCD_1:%.*]] = fsub fast double [[C_1]], [[D_1]]
41 ; CHECK-NEXT: [[ADDABCD_0:%.*]] = fadd fast double [[SUBAB_0]], [[SUBCD_0]]
42 ; CHECK-NEXT: [[ADDCDAB_1:%.*]] = fadd fast double [[SUBCD_1]], [[SUBAB_1]]
43 ; CHECK-NEXT: store double [[ADDABCD_0]], double* [[IDX0]], align 8
44 ; CHECK-NEXT: store double [[ADDCDAB_1]], double* [[IDX1]], align 8
4245 ; CHECK-NEXT: ret void
4346 ;
4447 entry:
160163 ; CHECK-NEXT: [[IDX5:%.*]] = getelementptr inbounds double, double* [[ARRAY]], i64 5
161164 ; CHECK-NEXT: [[IDX6:%.*]] = getelementptr inbounds double, double* [[ARRAY]], i64 6
162165 ; CHECK-NEXT: [[IDX7:%.*]] = getelementptr inbounds double, double* [[ARRAY]], i64 7
163 ; CHECK-NEXT: [[TMP0:%.*]] = bitcast double* [[IDX0]] to <2 x double>*
164 ; CHECK-NEXT: [[TMP1:%.*]] = load <2 x double>, <2 x double>* [[TMP0]], align 8
165 ; CHECK-NEXT: [[TMP2:%.*]] = bitcast double* [[IDX2]] to <2 x double>*
166 ; CHECK-NEXT: [[TMP3:%.*]] = load <2 x double>, <2 x double>* [[TMP2]], align 8
167 ; CHECK-NEXT: [[TMP4:%.*]] = bitcast double* [[IDX4]] to <2 x double>*
168 ; CHECK-NEXT: [[TMP5:%.*]] = load <2 x double>, <2 x double>* [[TMP4]], align 8
169 ; CHECK-NEXT: [[TMP6:%.*]] = bitcast double* [[IDX6]] to <2 x double>*
170 ; CHECK-NEXT: [[TMP7:%.*]] = load <2 x double>, <2 x double>* [[TMP6]], align 8
171 ; CHECK-NEXT: [[TMP8:%.*]] = fsub fast <2 x double> [[TMP5]], [[TMP7]]
172 ; CHECK-NEXT: [[TMP9:%.*]] = fadd fast <2 x double> [[TMP5]], [[TMP7]]
173 ; CHECK-NEXT: [[TMP10:%.*]] = shufflevector <2 x double> [[TMP8]], <2 x double> [[TMP9]], <2 x i32>
174 ; CHECK-NEXT: [[TMP11:%.*]] = fadd fast <2 x double> [[TMP1]], [[TMP3]]
175 ; CHECK-NEXT: [[TMP12:%.*]] = fsub fast <2 x double> [[TMP1]], [[TMP3]]
176 ; CHECK-NEXT: [[TMP13:%.*]] = shufflevector <2 x double> [[TMP11]], <2 x double> [[TMP12]], <2 x i32>
177 ; CHECK-NEXT: [[TMP14:%.*]] = fadd fast <2 x double> [[TMP13]], [[TMP10]]
178 ; CHECK-NEXT: [[TMP15:%.*]] = bitcast double* [[IDX0]] to <2 x double>*
179 ; CHECK-NEXT: store <2 x double> [[TMP14]], <2 x double>* [[TMP15]], align 8
166 ; CHECK-NEXT: [[A_0:%.*]] = load double, double* [[IDX0]], align 8
167 ; CHECK-NEXT: [[A_1:%.*]] = load double, double* [[IDX1]], align 8
168 ; CHECK-NEXT: [[B_0:%.*]] = load double, double* [[IDX2]], align 8
169 ; CHECK-NEXT: [[B_1:%.*]] = load double, double* [[IDX3]], align 8
170 ; CHECK-NEXT: [[C_0:%.*]] = load double, double* [[IDX4]], align 8
171 ; CHECK-NEXT: [[C_1:%.*]] = load double, double* [[IDX5]], align 8
172 ; CHECK-NEXT: [[D_0:%.*]] = load double, double* [[IDX6]], align 8
173 ; CHECK-NEXT: [[D_1:%.*]] = load double, double* [[IDX7]], align 8
174 ; CHECK-NEXT: [[ADDAB_0:%.*]] = fadd fast double [[A_0]], [[B_0]]
175 ; CHECK-NEXT: [[SUBCD_0:%.*]] = fsub fast double [[C_0]], [[D_0]]
176 ; CHECK-NEXT: [[ADDCD_1:%.*]] = fadd fast double [[C_1]], [[D_1]]
177 ; CHECK-NEXT: [[SUBAB_1:%.*]] = fsub fast double [[A_1]], [[B_1]]
178 ; CHECK-NEXT: [[ADDABCD_0:%.*]] = fadd fast double [[ADDAB_0]], [[SUBCD_0]]
179 ; CHECK-NEXT: [[ADDCDAB_1:%.*]] = fadd fast double [[ADDCD_1]], [[SUBAB_1]]
180 ; CHECK-NEXT: store double [[ADDABCD_0]], double* [[IDX0]], align 8
181 ; CHECK-NEXT: store double [[ADDCDAB_1]], double* [[IDX1]], align 8
180182 ; CHECK-NEXT: ret void
181183 ;
182184 entry:
236238 ; CHECK-NEXT: [[IDXB2:%.*]] = getelementptr inbounds double, double* [[B]], i64 2
237239 ; CHECK-NEXT: [[IDXA2:%.*]] = getelementptr inbounds double, double* [[A]], i64 2
238240 ; CHECK-NEXT: [[IDXB1:%.*]] = getelementptr inbounds double, double* [[B]], i64 1
239 ; CHECK-NEXT: [[A0:%.*]] = load double, double* [[IDXA0]], align 8
241 ; CHECK-NEXT: [[B0:%.*]] = load double, double* [[IDXB0]], align 8
240242 ; CHECK-NEXT: [[C0:%.*]] = load double, double* [[IDXC0]], align 8
241243 ; CHECK-NEXT: [[D0:%.*]] = load double, double* [[IDXD0]], align 8
242 ; CHECK-NEXT: [[A1:%.*]] = load double, double* [[IDXA1]], align 8
244 ; CHECK-NEXT: [[TMP0:%.*]] = bitcast double* [[IDXA0]] to <2 x double>*
245 ; CHECK-NEXT: [[TMP1:%.*]] = load <2 x double>, <2 x double>* [[TMP0]], align 8
243246 ; CHECK-NEXT: [[B2:%.*]] = load double, double* [[IDXB2]], align 8
244247 ; CHECK-NEXT: [[A2:%.*]] = load double, double* [[IDXA2]], align 8
245 ; CHECK-NEXT: [[TMP0:%.*]] = bitcast double* [[IDXB0]] to <2 x double>*
246 ; CHECK-NEXT: [[TMP1:%.*]] = load <2 x double>, <2 x double>* [[TMP0]], align 8
247 ; CHECK-NEXT: [[TMP2:%.*]] = insertelement <2 x double> undef, double [[C0]], i32 0
248 ; CHECK-NEXT: [[TMP3:%.*]] = insertelement <2 x double> [[TMP2]], double [[A1]], i32 1
249 ; CHECK-NEXT: [[TMP4:%.*]] = insertelement <2 x double> undef, double [[D0]], i32 0
250 ; CHECK-NEXT: [[TMP5:%.*]] = insertelement <2 x double> [[TMP4]], double [[B2]], i32 1
251 ; CHECK-NEXT: [[TMP6:%.*]] = fsub fast <2 x double> [[TMP3]], [[TMP5]]
252 ; CHECK-NEXT: [[TMP7:%.*]] = insertelement <2 x double> undef, double [[A0]], i32 0
253 ; CHECK-NEXT: [[TMP8:%.*]] = insertelement <2 x double> [[TMP7]], double [[A2]], i32 1
254 ; CHECK-NEXT: [[TMP9:%.*]] = fsub fast <2 x double> [[TMP8]], [[TMP1]]
255 ; CHECK-NEXT: [[TMP10:%.*]] = fadd fast <2 x double> [[TMP9]], [[TMP6]]
248 ; CHECK-NEXT: [[B1:%.*]] = load double, double* [[IDXB1]], align 8
249 ; CHECK-NEXT: [[TMP2:%.*]] = insertelement <2 x double> undef, double [[B0]], i32 0
250 ; CHECK-NEXT: [[TMP3:%.*]] = insertelement <2 x double> [[TMP2]], double [[B2]], i32 1
251 ; CHECK-NEXT: [[TMP4:%.*]] = fsub fast <2 x double> [[TMP1]], [[TMP3]]
252 ; CHECK-NEXT: [[TMP5:%.*]] = insertelement <2 x double> undef, double [[C0]], i32 0
253 ; CHECK-NEXT: [[TMP6:%.*]] = insertelement <2 x double> [[TMP5]], double [[A2]], i32 1
254 ; CHECK-NEXT: [[TMP7:%.*]] = insertelement <2 x double> undef, double [[D0]], i32 0
255 ; CHECK-NEXT: [[TMP8:%.*]] = insertelement <2 x double> [[TMP7]], double [[B1]], i32 1
256 ; CHECK-NEXT: [[TMP9:%.*]] = fsub fast <2 x double> [[TMP6]], [[TMP8]]
257 ; CHECK-NEXT: [[TMP10:%.*]] = fadd fast <2 x double> [[TMP4]], [[TMP9]]
256258 ; CHECK-NEXT: [[IDXS0:%.*]] = getelementptr inbounds double, double* [[S:%.*]], i64 0
257259 ; CHECK-NEXT: [[IDXS1:%.*]] = getelementptr inbounds double, double* [[S]], i64 1
258260 ; CHECK-NEXT: [[TMP11:%.*]] = bitcast double* [[IDXS0]] to <2 x double>*
259261 ; CHECK-NEXT: store <2 x double> [[TMP10]], <2 x double>* [[TMP11]], align 8
260 ; CHECK-NEXT: store double [[A1]], double* [[EXT1:%.*]], align 8
262 ; CHECK-NEXT: [[TMP12:%.*]] = extractelement <2 x double> [[TMP1]], i32 1
263 ; CHECK-NEXT: store double [[TMP12]], double* [[EXT1:%.*]], align 8
261264 ; CHECK-NEXT: ret void
262265 ;
263266 entry:
300303 store double %A1, double *%Ext1, align 8
301304 ret void
302305 }
303
304
305 ; This checks that the lookahead code does not crash when instructions with the same opcodes have different numbers of operands (in this case the calls).
306
307 %Class = type { i8 }
308 declare double @_ZN1i2ayEv(%Class*)
309 declare double @_ZN1i2axEv()
310
311 define void @lookahead_crash(double* %A, double *%S, %Class *%Arg0) {
312 ; CHECK-LABEL: @lookahead_crash(
313 ; CHECK-NEXT: [[IDXA0:%.*]] = getelementptr inbounds double, double* [[A:%.*]], i64 0
314 ; CHECK-NEXT: [[IDXA1:%.*]] = getelementptr inbounds double, double* [[A]], i64 1
315 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast double* [[IDXA0]] to <2 x double>*
316 ; CHECK-NEXT: [[TMP2:%.*]] = load <2 x double>, <2 x double>* [[TMP1]], align 8
317 ; CHECK-NEXT: [[C0:%.*]] = call double @_ZN1i2ayEv(%Class* [[ARG0:%.*]])
318 ; CHECK-NEXT: [[C1:%.*]] = call double @_ZN1i2axEv()
319 ; CHECK-NEXT: [[TMP3:%.*]] = insertelement <2 x double> undef, double [[C0]], i32 0
320 ; CHECK-NEXT: [[TMP4:%.*]] = insertelement <2 x double> [[TMP3]], double [[C1]], i32 1
321 ; CHECK-NEXT: [[TMP5:%.*]] = fadd fast <2 x double> [[TMP2]], [[TMP4]]
322 ; CHECK-NEXT: [[IDXS0:%.*]] = getelementptr inbounds double, double* [[S:%.*]], i64 0
323 ; CHECK-NEXT: [[IDXS1:%.*]] = getelementptr inbounds double, double* [[S]], i64 1
324 ; CHECK-NEXT: [[TMP6:%.*]] = bitcast double* [[IDXS0]] to <2 x double>*
325 ; CHECK-NEXT: store <2 x double> [[TMP5]], <2 x double>* [[TMP6]], align 8
326 ; CHECK-NEXT: ret void
327 ;
328 %IdxA0 = getelementptr inbounds double, double* %A, i64 0
329 %IdxA1 = getelementptr inbounds double, double* %A, i64 1
330
331 %A0 = load double, double *%IdxA0, align 8
332 %A1 = load double, double *%IdxA1, align 8
333
334 %C0 = call double @_ZN1i2ayEv(%Class *%Arg0)
335 %C1 = call double @_ZN1i2axEv()
336
337 %add0 = fadd fast double %A0, %C0
338 %add1 = fadd fast double %A1, %C1
339
340 %IdxS0 = getelementptr inbounds double, double* %S, i64 0
341 %IdxS1 = getelementptr inbounds double, double* %S, i64 1
342 store double %add0, double *%IdxS0, align 8
343 store double %add1, double *%IdxS1, align 8
344 ret void
345 }