llvm.org GIT mirror llvm / c23172f
GlobalISel: Handle widenScalar of arbitrary G_MERGE_VALUES sources Extract the sources to the GCD of the original size and target size, padding with implicit_def as necessary. Also fix the case where the requested source type is wider than the original result type. This was ignoring the type, and just using the destination. Do the operation in the requested type and truncate back. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366367 91177308-0d34-0410-b5e6-96231b3b80d8 Matt Arsenault 3 months ago
5 changed file(s) with 505 addition(s) and 201 deletion(s). Raw diff Collapse all Expand all
558558 }
559559
560560 /// Return the greatest common divisor of the values using Euclid's algorithm.
561 template
562 inline T greatestCommonDivisor(T A, T B) {
563 while (B) {
564 T Tmp = B;
565 B = A % B;
566 A = Tmp;
567 }
568 return A;
569 }
570
561571 inline uint64_t GreatestCommonDivisor64(uint64_t A, uint64_t B) {
562 while (B) {
563 uint64_t T = B;
564 B = A % B;
565 A = T;
566 }
567 return A;
572 return greatestCommonDivisor(A, B);
568573 }
569574
570575 /// This function takes a 64-bit integer and returns the bit equivalent double.
870870
871871 Register Src1 = MI.getOperand(1).getReg();
872872 LLT SrcTy = MRI.getType(Src1);
873 int NumMerge = DstTy.getSizeInBits() / WideTy.getSizeInBits();
874
875 // Try to turn this into a merge of merges if we can use the requested type as
876 // the source.
877 if (NumMerge > 1) {
878 int PartsPerMerge = WideTy.getSizeInBits() / SrcTy.getSizeInBits();
879 if (WideTy.getSizeInBits() % SrcTy.getSizeInBits() != 0)
880 return UnableToLegalize;
881
882 int RemainderBits = DstTy.getSizeInBits() % WideTy.getSizeInBits();
883 int RemainderParts = RemainderBits / SrcTy.getSizeInBits();
884
885 SmallVector Parts;
886 SmallVector SubMerges;
887
888 for (int I = 0; I != NumMerge; ++I) {
889 for (int J = 0; J != PartsPerMerge; ++J)
890 Parts.push_back(MI.getOperand(I * PartsPerMerge + J + 1).getReg());
891
892 auto SubMerge = MIRBuilder.buildMerge(WideTy, Parts);
893 SubMerges.push_back(SubMerge.getReg(0));
894 Parts.clear();
895 }
896
897 if (RemainderParts == 0) {
898 MIRBuilder.buildMerge(DstReg, SubMerges);
899 MI.eraseFromParent();
900 return Legalized;
901 }
902
903 assert(RemainderParts == 1);
904
905 auto AnyExt = MIRBuilder.buildAnyExt(
906 WideTy, MI.getOperand(MI.getNumOperands() - 1).getReg());
907 SubMerges.push_back(AnyExt.getReg(0));
908
909 LLT WiderDstTy = LLT::scalar(SubMerges.size() * WideTy.getSizeInBits());
910 auto Merge = MIRBuilder.buildMerge(WiderDstTy, SubMerges);
911 MIRBuilder.buildTrunc(DstReg, Merge);
912
913 MI.eraseFromParent();
914 return Legalized;
915 }
873 const int DstSize = DstTy.getSizeInBits();
874 const int SrcSize = SrcTy.getSizeInBits();
875 const int WideSize = WideTy.getSizeInBits();
876 const int NumMerge = (DstSize + WideSize - 1) / WideSize;
916877
917878 unsigned NumOps = MI.getNumOperands();
918879 unsigned NumSrc = MI.getNumOperands() - 1;
919880 unsigned PartSize = DstTy.getSizeInBits() / NumSrc;
920881
921 Register ResultReg = MIRBuilder.buildZExt(DstTy, Src1).getReg(0);
922
923 for (unsigned I = 2; I != NumOps; ++I) {
924 const unsigned Offset = (I - 1) * PartSize;
925
882 if (WideSize >= DstSize) {
883 // Directly pack the bits in the target type.
884 Register ResultReg = MIRBuilder.buildZExt(WideTy, Src1).getReg(0);
885
886 for (unsigned I = 2; I != NumOps; ++I) {
887 const unsigned Offset = (I - 1) * PartSize;
888
889 Register SrcReg = MI.getOperand(I).getReg();
890 assert(MRI.getType(SrcReg) == LLT::scalar(PartSize));
891
892 auto ZextInput = MIRBuilder.buildZExt(WideTy, SrcReg);
893
894 Register NextResult = I + 1 == NumOps && WideSize == DstSize ? DstReg :
895 MRI.createGenericVirtualRegister(WideTy);
896
897 auto ShiftAmt = MIRBuilder.buildConstant(WideTy, Offset);
898 auto Shl = MIRBuilder.buildShl(WideTy, ZextInput, ShiftAmt);
899 MIRBuilder.buildOr(NextResult, ResultReg, Shl);
900 ResultReg = NextResult;
901 }
902
903 if (WideSize > DstSize)
904 MIRBuilder.buildTrunc(DstReg, ResultReg);
905
906 MI.eraseFromParent();
907 return Legalized;
908 }
909
910 // Unmerge the original values to the GCD type, and recombine to the next
911 // multiple greater than the original type.
912 //
913 // %3:_(s12) = G_MERGE_VALUES %0:_(s4), %1:_(s4), %2:_(s4) -> s6
914 // %4:_(s2), %5:_(s2) = G_UNMERGE_VALUES %0
915 // %6:_(s2), %7:_(s2) = G_UNMERGE_VALUES %1
916 // %8:_(s2), %9:_(s2) = G_UNMERGE_VALUES %2
917 // %10:_(s6) = G_MERGE_VALUES %4, %5, %6
918 // %11:_(s6) = G_MERGE_VALUES %7, %8, %9
919 // %12:_(s12) = G_MERGE_VALUES %10, %11
920 //
921 // Padding with undef if necessary:
922 //
923 // %2:_(s8) = G_MERGE_VALUES %0:_(s4), %1:_(s4) -> s6
924 // %3:_(s2), %4:_(s2) = G_UNMERGE_VALUES %0
925 // %5:_(s2), %6:_(s2) = G_UNMERGE_VALUES %1
926 // %7:_(s2) = G_IMPLICIT_DEF
927 // %8:_(s6) = G_MERGE_VALUES %3, %4, %5
928 // %9:_(s6) = G_MERGE_VALUES %6, %7, %7
929 // %10:_(s12) = G_MERGE_VALUES %8, %9
930
931 const int GCD = greatestCommonDivisor(SrcSize, WideSize);
932 LLT GCDTy = LLT::scalar(GCD);
933
934 SmallVector Parts;
935 SmallVector NewMergeRegs;
936 SmallVector Unmerges;
937 LLT WideDstTy = LLT::scalar(NumMerge * WideSize);
938
939 // Decompose the original operands if they don't evenly divide.
940 for (int I = 1, E = MI.getNumOperands(); I != E; ++I) {
926941 Register SrcReg = MI.getOperand(I).getReg();
927 assert(MRI.getType(SrcReg) == LLT::scalar(PartSize));
928
929 auto ZextInput = MIRBuilder.buildZExt(DstTy, SrcReg);
930
931 Register NextResult = I + 1 == NumOps ? DstReg :
932 MRI.createGenericVirtualRegister(DstTy);
933
934 auto ShiftAmt = MIRBuilder.buildConstant(DstTy, Offset);
935 auto Shl = MIRBuilder.buildShl(DstTy, ZextInput, ShiftAmt);
936 MIRBuilder.buildOr(NextResult, ResultReg, Shl);
937 ResultReg = NextResult;
942 if (GCD == SrcSize) {
943 Unmerges.push_back(SrcReg);
944 } else {
945 auto Unmerge = MIRBuilder.buildUnmerge(GCDTy, SrcReg);
946 for (int J = 0, JE = Unmerge->getNumOperands() - 1; J != JE; ++J)
947 Unmerges.push_back(Unmerge.getReg(J));
948 }
949 }
950
951 // Pad with undef to the next size that is a multiple of the requested size.
952 if (static_cast(Unmerges.size()) != NumMerge * WideSize) {
953 Register UndefReg = MIRBuilder.buildUndef(GCDTy).getReg(0);
954 for (int I = Unmerges.size(); I != NumMerge * WideSize; ++I)
955 Unmerges.push_back(UndefReg);
956 }
957
958 const int PartsPerGCD = WideSize / GCD;
959
960 // Build merges of each piece.
961 ArrayRef Slicer(Unmerges);
962 for (int I = 0; I != NumMerge; ++I, Slicer = Slicer.drop_front(PartsPerGCD)) {
963 auto Merge = MIRBuilder.buildMerge(WideTy, Slicer.take_front(PartsPerGCD));
964 NewMergeRegs.push_back(Merge.getReg(0));
965 }
966
967 // A truncate may be necessary if the requested type doesn't evenly divide the
968 // original result type.
969 if (DstTy.getSizeInBits() == WideDstTy.getSizeInBits()) {
970 MIRBuilder.buildMerge(DstReg, NewMergeRegs);
971 } else {
972 auto FinalMerge = MIRBuilder.buildMerge(WideDstTy, NewMergeRegs);
973 MIRBuilder.buildTrunc(DstReg, FinalMerge.getReg(0));
938974 }
939975
940976 MI.eraseFromParent();
567567 // we need some temporary storage for the DstOp objects. Here we use a
568568 // sufficiently large SmallVector to not go through the heap.
569569 SmallVector TmpVec(Ops.begin(), Ops.end());
570 assert(TmpVec.size() > 1);
570571 return buildInstr(TargetOpcode::G_MERGE_VALUES, Res, TmpVec);
571572 }
572573
576577 // we need some temporary storage for the DstOp objects. Here we use a
577578 // sufficiently large SmallVector to not go through the heap.
578579 SmallVector TmpVec(Res.begin(), Res.end());
580 assert(TmpVec.size() > 1);
579581 return buildInstr(TargetOpcode::G_UNMERGE_VALUES, TmpVec, Op);
580582 }
581583
594596 // we need some temporary storage for the DstOp objects. Here we use a
595597 // sufficiently large SmallVector to not go through the heap.
596598 SmallVector TmpVec(Res.begin(), Res.end());
599 assert(TmpVec.size() > 1);
597600 return buildInstr(TargetOpcode::G_UNMERGE_VALUES, TmpVec, Op);
598601 }
599602
0 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
1 # RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=tahiti -O0 -run-pass=legalizer %s -o - | FileCheck %s
1 # RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=tahiti -O0 -run-pass=legalizer -global-isel-abort=2 -pass-remarks-missed='gisel*' -o - %s 2> %t | FileCheck %s
2 # FileCheck -check-prefix=ERR %s < %t
3
4 # ERR-NOT: remark:
5 # ERR: remark: :0:0: unable to legalize instruction: %197:_(s136) = G_INSERT %209:_, %206:_(s8), 128 (in function: test_merge_s68_s17_s17_s17_s17)
6 # ERR-NOT: remark:
7
28
39 ---
410 name: test_merge_p1_s8
119125 ; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
120126 ; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
121127 ; CHECK: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 2
122 ; CHECK: [[C3:%[0-9]+]]:_(s32) = G_CONSTANT i32 8
123 ; CHECK: [[C4:%[0-9]+]]:_(s32) = G_CONSTANT i32 16777215
124 ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY [[C3]](s32)
125 ; CHECK: [[AND:%[0-9]+]]:_(s32) = G_AND [[COPY]], [[C4]]
126 ; CHECK: [[C5:%[0-9]+]]:_(s32) = G_CONSTANT i32 255
128 ; CHECK: [[DEF:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
129 ; CHECK: [[C3:%[0-9]+]]:_(s32) = G_CONSTANT i32 255
130 ; CHECK: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[C3]](s32)
131 ; CHECK: [[TRUNC1:%[0-9]+]]:_(s16) = G_TRUNC [[C]](s32)
132 ; CHECK: [[AND:%[0-9]+]]:_(s16) = G_AND [[TRUNC1]], [[TRUNC]]
133 ; CHECK: [[C4:%[0-9]+]]:_(s32) = G_CONSTANT i32 8
134 ; CHECK: [[C5:%[0-9]+]]:_(s32) = G_CONSTANT i32 65535
135 ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY [[C4]](s32)
136 ; CHECK: [[AND1:%[0-9]+]]:_(s32) = G_AND [[COPY]], [[C5]]
137 ; CHECK: [[C6:%[0-9]+]]:_(s32) = G_CONSTANT i32 255
127138 ; CHECK: [[COPY1:%[0-9]+]]:_(s32) = COPY [[C1]](s32)
128 ; CHECK: [[AND1:%[0-9]+]]:_(s32) = G_AND [[COPY1]], [[C5]]
129 ; CHECK: [[SHL:%[0-9]+]]:_(s32) = G_SHL [[AND1]], [[AND]](s32)
130 ; CHECK: [[COPY2:%[0-9]+]]:_(s32) = COPY [[C]](s32)
131 ; CHECK: [[AND2:%[0-9]+]]:_(s32) = G_AND [[COPY2]], [[C5]]
132 ; CHECK: [[COPY3:%[0-9]+]]:_(s32) = COPY [[SHL]](s32)
133 ; CHECK: [[OR:%[0-9]+]]:_(s32) = G_OR [[AND2]], [[COPY3]]
134 ; CHECK: [[C6:%[0-9]+]]:_(s32) = G_CONSTANT i32 16
135 ; CHECK: [[COPY4:%[0-9]+]]:_(s32) = COPY [[C6]](s32)
136 ; CHECK: [[AND3:%[0-9]+]]:_(s32) = G_AND [[COPY4]], [[C4]]
137 ; CHECK: [[COPY5:%[0-9]+]]:_(s32) = COPY [[C2]](s32)
138 ; CHECK: [[AND4:%[0-9]+]]:_(s32) = G_AND [[COPY5]], [[C5]]
139 ; CHECK: [[SHL1:%[0-9]+]]:_(s32) = G_SHL [[AND4]], [[AND3]](s32)
140 ; CHECK: [[COPY6:%[0-9]+]]:_(s32) = COPY [[OR]](s32)
141 ; CHECK: [[COPY7:%[0-9]+]]:_(s32) = COPY [[SHL1]](s32)
142 ; CHECK: [[OR1:%[0-9]+]]:_(s32) = G_OR [[COPY6]], [[COPY7]]
143 ; CHECK: [[COPY8:%[0-9]+]]:_(s32) = COPY [[OR1]](s32)
144 ; CHECK: $vgpr0 = COPY [[COPY8]](s32)
139 ; CHECK: [[AND2:%[0-9]+]]:_(s32) = G_AND [[COPY1]], [[C6]]
140 ; CHECK: [[SHL:%[0-9]+]]:_(s32) = G_SHL [[AND2]], [[AND1]](s32)
141 ; CHECK: [[TRUNC2:%[0-9]+]]:_(s16) = G_TRUNC [[SHL]](s32)
142 ; CHECK: [[OR:%[0-9]+]]:_(s16) = G_OR [[AND]], [[TRUNC2]]
143 ; CHECK: [[TRUNC3:%[0-9]+]]:_(s16) = G_TRUNC [[C2]](s32)
144 ; CHECK: [[AND3:%[0-9]+]]:_(s16) = G_AND [[TRUNC3]], [[TRUNC]]
145 ; CHECK: [[C7:%[0-9]+]]:_(s32) = G_CONSTANT i32 8
146 ; CHECK: [[COPY2:%[0-9]+]]:_(s32) = COPY [[C7]](s32)
147 ; CHECK: [[AND4:%[0-9]+]]:_(s32) = G_AND [[COPY2]], [[C5]]
148 ; CHECK: [[COPY3:%[0-9]+]]:_(s32) = COPY [[DEF]](s32)
149 ; CHECK: [[AND5:%[0-9]+]]:_(s32) = G_AND [[COPY3]], [[C6]]
150 ; CHECK: [[SHL1:%[0-9]+]]:_(s32) = G_SHL [[AND5]], [[AND4]](s32)
151 ; CHECK: [[TRUNC4:%[0-9]+]]:_(s16) = G_TRUNC [[SHL1]](s32)
152 ; CHECK: [[OR1:%[0-9]+]]:_(s16) = G_OR [[AND3]], [[TRUNC4]]
153 ; CHECK: [[MV:%[0-9]+]]:_(s32) = G_MERGE_VALUES [[OR]](s16), [[OR1]](s16)
154 ; CHECK: [[COPY4:%[0-9]+]]:_(s32) = COPY [[MV]](s32)
155 ; CHECK: $vgpr0 = COPY [[COPY4]](s32)
145156 %0:_(s8) = G_CONSTANT i8 0
146157 %1:_(s8) = G_CONSTANT i8 1
147158 %2:_(s8) = G_CONSTANT i8 2
249260 ; CHECK: [[C3:%[0-9]+]]:_(s32) = G_CONSTANT i32 3
250261 ; CHECK: [[C4:%[0-9]+]]:_(s32) = G_CONSTANT i32 4
251262 ; CHECK: [[C5:%[0-9]+]]:_(s32) = G_CONSTANT i32 5
252 ; CHECK: [[C6:%[0-9]+]]:_(s32) = G_CONSTANT i32 4
253 ; CHECK: [[C7:%[0-9]+]]:_(s32) = G_CONSTANT i32 16777215
254 ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY [[C6]](s32)
255 ; CHECK: [[AND:%[0-9]+]]:_(s32) = G_AND [[COPY]], [[C7]]
256 ; CHECK: [[C8:%[0-9]+]]:_(s32) = G_CONSTANT i32 15
263 ; CHECK: [[DEF:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
264 ; CHECK: [[C6:%[0-9]+]]:_(s32) = G_CONSTANT i32 15
265 ; CHECK: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[C6]](s32)
266 ; CHECK: [[TRUNC1:%[0-9]+]]:_(s16) = G_TRUNC [[C]](s32)
267 ; CHECK: [[AND:%[0-9]+]]:_(s16) = G_AND [[TRUNC1]], [[TRUNC]]
268 ; CHECK: [[C7:%[0-9]+]]:_(s32) = G_CONSTANT i32 4
269 ; CHECK: [[C8:%[0-9]+]]:_(s32) = G_CONSTANT i32 65535
270 ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY [[C7]](s32)
271 ; CHECK: [[AND1:%[0-9]+]]:_(s32) = G_AND [[COPY]], [[C8]]
272 ; CHECK: [[C9:%[0-9]+]]:_(s32) = G_CONSTANT i32 15
257273 ; CHECK: [[COPY1:%[0-9]+]]:_(s32) = COPY [[C1]](s32)
258 ; CHECK: [[AND1:%[0-9]+]]:_(s32) = G_AND [[COPY1]], [[C8]]
259 ; CHECK: [[SHL:%[0-9]+]]:_(s32) = G_SHL [[AND1]], [[AND]](s32)
260 ; CHECK: [[COPY2:%[0-9]+]]:_(s32) = COPY [[C]](s32)
261 ; CHECK: [[AND2:%[0-9]+]]:_(s32) = G_AND [[COPY2]], [[C8]]
262 ; CHECK: [[COPY3:%[0-9]+]]:_(s32) = COPY [[SHL]](s32)
263 ; CHECK: [[OR:%[0-9]+]]:_(s32) = G_OR [[AND2]], [[COPY3]]
264 ; CHECK: [[C9:%[0-9]+]]:_(s32) = G_CONSTANT i32 8
265 ; CHECK: [[COPY4:%[0-9]+]]:_(s32) = COPY [[C9]](s32)
266 ; CHECK: [[AND3:%[0-9]+]]:_(s32) = G_AND [[COPY4]], [[C7]]
267 ; CHECK: [[COPY5:%[0-9]+]]:_(s32) = COPY [[C2]](s32)
268 ; CHECK: [[AND4:%[0-9]+]]:_(s32) = G_AND [[COPY5]], [[C8]]
274 ; CHECK: [[AND2:%[0-9]+]]:_(s32) = G_AND [[COPY1]], [[C9]]
275 ; CHECK: [[SHL:%[0-9]+]]:_(s32) = G_SHL [[AND2]], [[AND1]](s32)
276 ; CHECK: [[TRUNC2:%[0-9]+]]:_(s16) = G_TRUNC [[SHL]](s32)
277 ; CHECK: [[OR:%[0-9]+]]:_(s16) = G_OR [[AND]], [[TRUNC2]]
278 ; CHECK: [[C10:%[0-9]+]]:_(s32) = G_CONSTANT i32 8
279 ; CHECK: [[COPY2:%[0-9]+]]:_(s32) = COPY [[C10]](s32)
280 ; CHECK: [[AND3:%[0-9]+]]:_(s32) = G_AND [[COPY2]], [[C8]]
281 ; CHECK: [[COPY3:%[0-9]+]]:_(s32) = COPY [[C2]](s32)
282 ; CHECK: [[AND4:%[0-9]+]]:_(s32) = G_AND [[COPY3]], [[C9]]
269283 ; CHECK: [[SHL1:%[0-9]+]]:_(s32) = G_SHL [[AND4]], [[AND3]](s32)
270 ; CHECK: [[COPY6:%[0-9]+]]:_(s32) = COPY [[OR]](s32)
271 ; CHECK: [[COPY7:%[0-9]+]]:_(s32) = COPY [[SHL1]](s32)
272 ; CHECK: [[OR1:%[0-9]+]]:_(s32) = G_OR [[COPY6]], [[COPY7]]
273 ; CHECK: [[C10:%[0-9]+]]:_(s32) = G_CONSTANT i32 12
274 ; CHECK: [[COPY8:%[0-9]+]]:_(s32) = COPY [[C10]](s32)
275 ; CHECK: [[AND5:%[0-9]+]]:_(s32) = G_AND [[COPY8]], [[C7]]
276 ; CHECK: [[COPY9:%[0-9]+]]:_(s32) = COPY [[C3]](s32)
277 ; CHECK: [[AND6:%[0-9]+]]:_(s32) = G_AND [[COPY9]], [[C8]]
284 ; CHECK: [[TRUNC3:%[0-9]+]]:_(s16) = G_TRUNC [[SHL1]](s32)
285 ; CHECK: [[OR1:%[0-9]+]]:_(s16) = G_OR [[OR]], [[TRUNC3]]
286 ; CHECK: [[C11:%[0-9]+]]:_(s32) = G_CONSTANT i32 12
287 ; CHECK: [[COPY4:%[0-9]+]]:_(s32) = COPY [[C11]](s32)
288 ; CHECK: [[AND5:%[0-9]+]]:_(s32) = G_AND [[COPY4]], [[C8]]
289 ; CHECK: [[COPY5:%[0-9]+]]:_(s32) = COPY [[C3]](s32)
290 ; CHECK: [[AND6:%[0-9]+]]:_(s32) = G_AND [[COPY5]], [[C9]]
278291 ; CHECK: [[SHL2:%[0-9]+]]:_(s32) = G_SHL [[AND6]], [[AND5]](s32)
279 ; CHECK: [[COPY10:%[0-9]+]]:_(s32) = COPY [[OR1]](s32)
280 ; CHECK: [[COPY11:%[0-9]+]]:_(s32) = COPY [[SHL2]](s32)
281 ; CHECK: [[OR2:%[0-9]+]]:_(s32) = G_OR [[COPY10]], [[COPY11]]
282 ; CHECK: [[C11:%[0-9]+]]:_(s32) = G_CONSTANT i32 16
283 ; CHECK: [[COPY12:%[0-9]+]]:_(s32) = COPY [[C11]](s32)
284 ; CHECK: [[AND7:%[0-9]+]]:_(s32) = G_AND [[COPY12]], [[C7]]
285 ; CHECK: [[COPY13:%[0-9]+]]:_(s32) = COPY [[C4]](s32)
286 ; CHECK: [[AND8:%[0-9]+]]:_(s32) = G_AND [[COPY13]], [[C8]]
287 ; CHECK: [[SHL3:%[0-9]+]]:_(s32) = G_SHL [[AND8]], [[AND7]](s32)
288 ; CHECK: [[COPY14:%[0-9]+]]:_(s32) = COPY [[OR2]](s32)
289 ; CHECK: [[COPY15:%[0-9]+]]:_(s32) = COPY [[SHL3]](s32)
290 ; CHECK: [[OR3:%[0-9]+]]:_(s32) = G_OR [[COPY14]], [[COPY15]]
291 ; CHECK: [[C12:%[0-9]+]]:_(s32) = G_CONSTANT i32 20
292 ; CHECK: [[COPY16:%[0-9]+]]:_(s32) = COPY [[C12]](s32)
293 ; CHECK: [[AND9:%[0-9]+]]:_(s32) = G_AND [[COPY16]], [[C7]]
294 ; CHECK: [[COPY17:%[0-9]+]]:_(s32) = COPY [[C5]](s32)
295 ; CHECK: [[AND10:%[0-9]+]]:_(s32) = G_AND [[COPY17]], [[C8]]
296 ; CHECK: [[SHL4:%[0-9]+]]:_(s32) = G_SHL [[AND10]], [[AND9]](s32)
297 ; CHECK: [[COPY18:%[0-9]+]]:_(s32) = COPY [[OR3]](s32)
298 ; CHECK: [[COPY19:%[0-9]+]]:_(s32) = COPY [[SHL4]](s32)
299 ; CHECK: [[OR4:%[0-9]+]]:_(s32) = G_OR [[COPY18]], [[COPY19]]
300 ; CHECK: [[TRUNC:%[0-9]+]]:_(s24) = G_TRUNC [[OR4]](s32)
301 ; CHECK: S_NOP 0, implicit [[TRUNC]](s24)
292 ; CHECK: [[TRUNC4:%[0-9]+]]:_(s16) = G_TRUNC [[SHL2]](s32)
293 ; CHECK: [[OR2:%[0-9]+]]:_(s16) = G_OR [[OR1]], [[TRUNC4]]
294 ; CHECK: [[TRUNC5:%[0-9]+]]:_(s16) = G_TRUNC [[C4]](s32)
295 ; CHECK: [[AND7:%[0-9]+]]:_(s16) = G_AND [[TRUNC5]], [[TRUNC]]
296 ; CHECK: [[C12:%[0-9]+]]:_(s32) = G_CONSTANT i32 4
297 ; CHECK: [[COPY6:%[0-9]+]]:_(s32) = COPY [[C12]](s32)
298 ; CHECK: [[AND8:%[0-9]+]]:_(s32) = G_AND [[COPY6]], [[C8]]
299 ; CHECK: [[COPY7:%[0-9]+]]:_(s32) = COPY [[C5]](s32)
300 ; CHECK: [[AND9:%[0-9]+]]:_(s32) = G_AND [[COPY7]], [[C9]]
301 ; CHECK: [[SHL3:%[0-9]+]]:_(s32) = G_SHL [[AND9]], [[AND8]](s32)
302 ; CHECK: [[TRUNC6:%[0-9]+]]:_(s16) = G_TRUNC [[SHL3]](s32)
303 ; CHECK: [[OR3:%[0-9]+]]:_(s16) = G_OR [[AND7]], [[TRUNC6]]
304 ; CHECK: [[C13:%[0-9]+]]:_(s32) = G_CONSTANT i32 8
305 ; CHECK: [[COPY8:%[0-9]+]]:_(s32) = COPY [[C13]](s32)
306 ; CHECK: [[AND10:%[0-9]+]]:_(s32) = G_AND [[COPY8]], [[C8]]
307 ; CHECK: [[COPY9:%[0-9]+]]:_(s32) = COPY [[DEF]](s32)
308 ; CHECK: [[AND11:%[0-9]+]]:_(s32) = G_AND [[COPY9]], [[C9]]
309 ; CHECK: [[SHL4:%[0-9]+]]:_(s32) = G_SHL [[AND11]], [[AND10]](s32)
310 ; CHECK: [[TRUNC7:%[0-9]+]]:_(s16) = G_TRUNC [[SHL4]](s32)
311 ; CHECK: [[OR4:%[0-9]+]]:_(s16) = G_OR [[OR3]], [[TRUNC7]]
312 ; CHECK: [[C14:%[0-9]+]]:_(s32) = G_CONSTANT i32 12
313 ; CHECK: [[COPY10:%[0-9]+]]:_(s32) = COPY [[C14]](s32)
314 ; CHECK: [[AND12:%[0-9]+]]:_(s32) = G_AND [[COPY10]], [[C8]]
315 ; CHECK: [[COPY11:%[0-9]+]]:_(s32) = COPY [[DEF]](s32)
316 ; CHECK: [[AND13:%[0-9]+]]:_(s32) = G_AND [[COPY11]], [[C9]]
317 ; CHECK: [[SHL5:%[0-9]+]]:_(s32) = G_SHL [[AND13]], [[AND12]](s32)
318 ; CHECK: [[TRUNC8:%[0-9]+]]:_(s16) = G_TRUNC [[SHL5]](s32)
319 ; CHECK: [[OR5:%[0-9]+]]:_(s16) = G_OR [[OR4]], [[TRUNC8]]
320 ; CHECK: [[MV:%[0-9]+]]:_(s32) = G_MERGE_VALUES [[OR2]](s16), [[OR5]](s16)
321 ; CHECK: [[TRUNC9:%[0-9]+]]:_(s24) = G_TRUNC [[MV]](s32)
322 ; CHECK: S_NOP 0, implicit [[TRUNC9]](s24)
302323 %0:_(s4) = G_CONSTANT i4 0
303324 %1:_(s4) = G_CONSTANT i4 1
304325 %2:_(s4) = G_CONSTANT i4 2
321342 ; CHECK: [[C4:%[0-9]+]]:_(s32) = G_CONSTANT i32 4
322343 ; CHECK: [[C5:%[0-9]+]]:_(s32) = G_CONSTANT i32 5
323344 ; CHECK: [[C6:%[0-9]+]]:_(s32) = G_CONSTANT i32 6
324 ; CHECK: [[C7:%[0-9]+]]:_(s32) = G_CONSTANT i32 4
325 ; CHECK: [[C8:%[0-9]+]]:_(s32) = G_CONSTANT i32 268435455
326 ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY [[C7]](s32)
327 ; CHECK: [[AND:%[0-9]+]]:_(s32) = G_AND [[COPY]], [[C8]]
328 ; CHECK: [[C9:%[0-9]+]]:_(s32) = G_CONSTANT i32 15
345 ; CHECK: [[DEF:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
346 ; CHECK: [[C7:%[0-9]+]]:_(s32) = G_CONSTANT i32 15
347 ; CHECK: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[C7]](s32)
348 ; CHECK: [[TRUNC1:%[0-9]+]]:_(s16) = G_TRUNC [[C]](s32)
349 ; CHECK: [[AND:%[0-9]+]]:_(s16) = G_AND [[TRUNC1]], [[TRUNC]]
350 ; CHECK: [[C8:%[0-9]+]]:_(s32) = G_CONSTANT i32 4
351 ; CHECK: [[C9:%[0-9]+]]:_(s32) = G_CONSTANT i32 65535
352 ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY [[C8]](s32)
353 ; CHECK: [[AND1:%[0-9]+]]:_(s32) = G_AND [[COPY]], [[C9]]
354 ; CHECK: [[C10:%[0-9]+]]:_(s32) = G_CONSTANT i32 15
329355 ; CHECK: [[COPY1:%[0-9]+]]:_(s32) = COPY [[C1]](s32)
330 ; CHECK: [[AND1:%[0-9]+]]:_(s32) = G_AND [[COPY1]], [[C9]]
331 ; CHECK: [[SHL:%[0-9]+]]:_(s32) = G_SHL [[AND1]], [[AND]](s32)
332 ; CHECK: [[COPY2:%[0-9]+]]:_(s32) = COPY [[C]](s32)
333 ; CHECK: [[AND2:%[0-9]+]]:_(s32) = G_AND [[COPY2]], [[C9]]
334 ; CHECK: [[COPY3:%[0-9]+]]:_(s32) = COPY [[SHL]](s32)
335 ; CHECK: [[OR:%[0-9]+]]:_(s32) = G_OR [[AND2]], [[COPY3]]
336 ; CHECK: [[C10:%[0-9]+]]:_(s32) = G_CONSTANT i32 8
337 ; CHECK: [[COPY4:%[0-9]+]]:_(s32) = COPY [[C10]](s32)
338 ; CHECK: [[AND3:%[0-9]+]]:_(s32) = G_AND [[COPY4]], [[C8]]
339 ; CHECK: [[COPY5:%[0-9]+]]:_(s32) = COPY [[C2]](s32)
340 ; CHECK: [[AND4:%[0-9]+]]:_(s32) = G_AND [[COPY5]], [[C9]]
356 ; CHECK: [[AND2:%[0-9]+]]:_(s32) = G_AND [[COPY1]], [[C10]]
357 ; CHECK: [[SHL:%[0-9]+]]:_(s32) = G_SHL [[AND2]], [[AND1]](s32)
358 ; CHECK: [[TRUNC2:%[0-9]+]]:_(s16) = G_TRUNC [[SHL]](s32)
359 ; CHECK: [[OR:%[0-9]+]]:_(s16) = G_OR [[AND]], [[TRUNC2]]
360 ; CHECK: [[C11:%[0-9]+]]:_(s32) = G_CONSTANT i32 8
361 ; CHECK: [[COPY2:%[0-9]+]]:_(s32) = COPY [[C11]](s32)
362 ; CHECK: [[AND3:%[0-9]+]]:_(s32) = G_AND [[COPY2]], [[C9]]
363 ; CHECK: [[COPY3:%[0-9]+]]:_(s32) = COPY [[C2]](s32)
364 ; CHECK: [[AND4:%[0-9]+]]:_(s32) = G_AND [[COPY3]], [[C10]]
341365 ; CHECK: [[SHL1:%[0-9]+]]:_(s32) = G_SHL [[AND4]], [[AND3]](s32)
342 ; CHECK: [[COPY6:%[0-9]+]]:_(s32) = COPY [[OR]](s32)
343 ; CHECK: [[COPY7:%[0-9]+]]:_(s32) = COPY [[SHL1]](s32)
344 ; CHECK: [[OR1:%[0-9]+]]:_(s32) = G_OR [[COPY6]], [[COPY7]]
345 ; CHECK: [[C11:%[0-9]+]]:_(s32) = G_CONSTANT i32 12
346 ; CHECK: [[COPY8:%[0-9]+]]:_(s32) = COPY [[C11]](s32)
347 ; CHECK: [[AND5:%[0-9]+]]:_(s32) = G_AND [[COPY8]], [[C8]]
348 ; CHECK: [[COPY9:%[0-9]+]]:_(s32) = COPY [[C3]](s32)
349 ; CHECK: [[AND6:%[0-9]+]]:_(s32) = G_AND [[COPY9]], [[C9]]
366 ; CHECK: [[TRUNC3:%[0-9]+]]:_(s16) = G_TRUNC [[SHL1]](s32)
367 ; CHECK: [[OR1:%[0-9]+]]:_(s16) = G_OR [[OR]], [[TRUNC3]]
368 ; CHECK: [[C12:%[0-9]+]]:_(s32) = G_CONSTANT i32 12
369 ; CHECK: [[COPY4:%[0-9]+]]:_(s32) = COPY [[C12]](s32)
370 ; CHECK: [[AND5:%[0-9]+]]:_(s32) = G_AND [[COPY4]], [[C9]]
371 ; CHECK: [[COPY5:%[0-9]+]]:_(s32) = COPY [[C3]](s32)
372 ; CHECK: [[AND6:%[0-9]+]]:_(s32) = G_AND [[COPY5]], [[C10]]
350373 ; CHECK: [[SHL2:%[0-9]+]]:_(s32) = G_SHL [[AND6]], [[AND5]](s32)
351 ; CHECK: [[COPY10:%[0-9]+]]:_(s32) = COPY [[OR1]](s32)
352 ; CHECK: [[COPY11:%[0-9]+]]:_(s32) = COPY [[SHL2]](s32)
353 ; CHECK: [[OR2:%[0-9]+]]:_(s32) = G_OR [[COPY10]], [[COPY11]]
354 ; CHECK: [[C12:%[0-9]+]]:_(s32) = G_CONSTANT i32 16
355 ; CHECK: [[COPY12:%[0-9]+]]:_(s32) = COPY [[C12]](s32)
356 ; CHECK: [[AND7:%[0-9]+]]:_(s32) = G_AND [[COPY12]], [[C8]]
357 ; CHECK: [[COPY13:%[0-9]+]]:_(s32) = COPY [[C4]](s32)
358 ; CHECK: [[AND8:%[0-9]+]]:_(s32) = G_AND [[COPY13]], [[C9]]
359 ; CHECK: [[SHL3:%[0-9]+]]:_(s32) = G_SHL [[AND8]], [[AND7]](s32)
360 ; CHECK: [[COPY14:%[0-9]+]]:_(s32) = COPY [[OR2]](s32)
361 ; CHECK: [[COPY15:%[0-9]+]]:_(s32) = COPY [[SHL3]](s32)
362 ; CHECK: [[OR3:%[0-9]+]]:_(s32) = G_OR [[COPY14]], [[COPY15]]
363 ; CHECK: [[C13:%[0-9]+]]:_(s32) = G_CONSTANT i32 20
364 ; CHECK: [[COPY16:%[0-9]+]]:_(s32) = COPY [[C13]](s32)
365 ; CHECK: [[AND9:%[0-9]+]]:_(s32) = G_AND [[COPY16]], [[C8]]
366 ; CHECK: [[COPY17:%[0-9]+]]:_(s32) = COPY [[C5]](s32)
367 ; CHECK: [[AND10:%[0-9]+]]:_(s32) = G_AND [[COPY17]], [[C9]]
368 ; CHECK: [[SHL4:%[0-9]+]]:_(s32) = G_SHL [[AND10]], [[AND9]](s32)
369 ; CHECK: [[COPY18:%[0-9]+]]:_(s32) = COPY [[OR3]](s32)
370 ; CHECK: [[COPY19:%[0-9]+]]:_(s32) = COPY [[SHL4]](s32)
371 ; CHECK: [[OR4:%[0-9]+]]:_(s32) = G_OR [[COPY18]], [[COPY19]]
372 ; CHECK: [[C14:%[0-9]+]]:_(s32) = G_CONSTANT i32 24
373 ; CHECK: [[COPY20:%[0-9]+]]:_(s32) = COPY [[C14]](s32)
374 ; CHECK: [[AND11:%[0-9]+]]:_(s32) = G_AND [[COPY20]], [[C8]]
375 ; CHECK: [[COPY21:%[0-9]+]]:_(s32) = COPY [[C6]](s32)
376 ; CHECK: [[AND12:%[0-9]+]]:_(s32) = G_AND [[COPY21]], [[C9]]
377 ; CHECK: [[SHL5:%[0-9]+]]:_(s32) = G_SHL [[AND12]], [[AND11]](s32)
378 ; CHECK: [[COPY22:%[0-9]+]]:_(s32) = COPY [[OR4]](s32)
379 ; CHECK: [[COPY23:%[0-9]+]]:_(s32) = COPY [[SHL5]](s32)
380 ; CHECK: [[OR5:%[0-9]+]]:_(s32) = G_OR [[COPY22]], [[COPY23]]
381 ; CHECK: [[TRUNC:%[0-9]+]]:_(s28) = G_TRUNC [[OR5]](s32)
382 ; CHECK: S_NOP 0, implicit [[TRUNC]](s28)
374 ; CHECK: [[TRUNC4:%[0-9]+]]:_(s16) = G_TRUNC [[SHL2]](s32)
375 ; CHECK: [[OR2:%[0-9]+]]:_(s16) = G_OR [[OR1]], [[TRUNC4]]
376 ; CHECK: [[TRUNC5:%[0-9]+]]:_(s16) = G_TRUNC [[C4]](s32)
377 ; CHECK: [[AND7:%[0-9]+]]:_(s16) = G_AND [[TRUNC5]], [[TRUNC]]
378 ; CHECK: [[C13:%[0-9]+]]:_(s32) = G_CONSTANT i32 4
379 ; CHECK: [[COPY6:%[0-9]+]]:_(s32) = COPY [[C13]](s32)
380 ; CHECK: [[AND8:%[0-9]+]]:_(s32) = G_AND [[COPY6]], [[C9]]
381 ; CHECK: [[COPY7:%[0-9]+]]:_(s32) = COPY [[C5]](s32)
382 ; CHECK: [[AND9:%[0-9]+]]:_(s32) = G_AND [[COPY7]], [[C10]]
383 ; CHECK: [[SHL3:%[0-9]+]]:_(s32) = G_SHL [[AND9]], [[AND8]](s32)
384 ; CHECK: [[TRUNC6:%[0-9]+]]:_(s16) = G_TRUNC [[SHL3]](s32)
385 ; CHECK: [[OR3:%[0-9]+]]:_(s16) = G_OR [[AND7]], [[TRUNC6]]
386 ; CHECK: [[C14:%[0-9]+]]:_(s32) = G_CONSTANT i32 8
387 ; CHECK: [[COPY8:%[0-9]+]]:_(s32) = COPY [[C14]](s32)
388 ; CHECK: [[AND10:%[0-9]+]]:_(s32) = G_AND [[COPY8]], [[C9]]
389 ; CHECK: [[COPY9:%[0-9]+]]:_(s32) = COPY [[C6]](s32)
390 ; CHECK: [[AND11:%[0-9]+]]:_(s32) = G_AND [[COPY9]], [[C10]]
391 ; CHECK: [[SHL4:%[0-9]+]]:_(s32) = G_SHL [[AND11]], [[AND10]](s32)
392 ; CHECK: [[TRUNC7:%[0-9]+]]:_(s16) = G_TRUNC [[SHL4]](s32)
393 ; CHECK: [[OR4:%[0-9]+]]:_(s16) = G_OR [[OR3]], [[TRUNC7]]
394 ; CHECK: [[C15:%[0-9]+]]:_(s32) = G_CONSTANT i32 12
395 ; CHECK: [[COPY10:%[0-9]+]]:_(s32) = COPY [[C15]](s32)
396 ; CHECK: [[AND12:%[0-9]+]]:_(s32) = G_AND [[COPY10]], [[C9]]
397 ; CHECK: [[COPY11:%[0-9]+]]:_(s32) = COPY [[DEF]](s32)
398 ; CHECK: [[AND13:%[0-9]+]]:_(s32) = G_AND [[COPY11]], [[C10]]
399 ; CHECK: [[SHL5:%[0-9]+]]:_(s32) = G_SHL [[AND13]], [[AND12]](s32)
400 ; CHECK: [[TRUNC8:%[0-9]+]]:_(s16) = G_TRUNC [[SHL5]](s32)
401 ; CHECK: [[OR5:%[0-9]+]]:_(s16) = G_OR [[OR4]], [[TRUNC8]]
402 ; CHECK: [[MV:%[0-9]+]]:_(s32) = G_MERGE_VALUES [[OR2]](s16), [[OR5]](s16)
403 ; CHECK: [[TRUNC9:%[0-9]+]]:_(s28) = G_TRUNC [[MV]](s32)
404 ; CHECK: S_NOP 0, implicit [[TRUNC9]](s28)
383405 %0:_(s4) = G_CONSTANT i4 0
384406 %1:_(s4) = G_CONSTANT i4 1
385407 %2:_(s4) = G_CONSTANT i4 2
547569 ; CHECK: [[C4:%[0-9]+]]:_(s32) = G_CONSTANT i32 4
548570 ; CHECK: [[C5:%[0-9]+]]:_(s32) = G_CONSTANT i32 5
549571 ; CHECK: [[C6:%[0-9]+]]:_(s32) = G_CONSTANT i32 6
572 ; CHECK: [[DEF:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
550573 ; CHECK: [[C7:%[0-9]+]]:_(s32) = G_CONSTANT i32 255
551574 ; CHECK: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[C7]](s32)
552575 ; CHECK: [[TRUNC1:%[0-9]+]]:_(s16) = G_TRUNC [[C]](s32)
582605 ; CHECK: [[TRUNC6:%[0-9]+]]:_(s16) = G_TRUNC [[SHL2]](s32)
583606 ; CHECK: [[OR2:%[0-9]+]]:_(s16) = G_OR [[AND6]], [[TRUNC6]]
584607 ; CHECK: [[TRUNC7:%[0-9]+]]:_(s16) = G_TRUNC [[C6]](s32)
585 ; CHECK: [[MV:%[0-9]+]]:_(s64) = G_MERGE_VALUES [[OR]](s16), [[OR1]](s16), [[OR2]](s16), [[TRUNC7]](s16)
586 ; CHECK: [[TRUNC8:%[0-9]+]]:_(s56) = G_TRUNC [[MV]](s64)
587 ; CHECK: S_NOP 0, implicit [[TRUNC8]](s56)
608 ; CHECK: [[AND9:%[0-9]+]]:_(s16) = G_AND [[TRUNC7]], [[TRUNC]]
609 ; CHECK: [[C13:%[0-9]+]]:_(s32) = G_CONSTANT i32 8
610 ; CHECK: [[COPY6:%[0-9]+]]:_(s32) = COPY [[C13]](s32)
611 ; CHECK: [[AND10:%[0-9]+]]:_(s32) = G_AND [[COPY6]], [[C9]]
612 ; CHECK: [[COPY7:%[0-9]+]]:_(s32) = COPY [[DEF]](s32)
613 ; CHECK: [[AND11:%[0-9]+]]:_(s32) = G_AND [[COPY7]], [[C10]]
614 ; CHECK: [[SHL3:%[0-9]+]]:_(s32) = G_SHL [[AND11]], [[AND10]](s32)
615 ; CHECK: [[TRUNC8:%[0-9]+]]:_(s16) = G_TRUNC [[SHL3]](s32)
616 ; CHECK: [[OR3:%[0-9]+]]:_(s16) = G_OR [[AND9]], [[TRUNC8]]
617 ; CHECK: [[MV:%[0-9]+]]:_(s64) = G_MERGE_VALUES [[OR]](s16), [[OR1]](s16), [[OR2]](s16), [[OR3]](s16)
618 ; CHECK: [[TRUNC9:%[0-9]+]]:_(s56) = G_TRUNC [[MV]](s64)
619 ; CHECK: S_NOP 0, implicit [[TRUNC9]](s56)
588620 %0:_(s8) = G_CONSTANT i8 0
589621 %1:_(s8) = G_CONSTANT i8 1
590622 %2:_(s8) = G_CONSTANT i8 2
595627 %7:_(s56) = G_MERGE_VALUES %0, %1, %2, %3, %4, %5, %6
596628 S_NOP 0, implicit %7
597629 ...
630
631 ---
632 name: test_merge_s68_s17_s17_s17_s17
633 body: |
634 bb.0:
635 ; CHECK-LABEL: name: test_merge_s68_s17_s17_s17_s17
636 ; CHECK: [[TRUNC:%[0-9]+]]:_(s1) = G_TRUNC %142(s16)
637 ; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
638 ; CHECK: [[TRUNC1:%[0-9]+]]:_(s1) = G_TRUNC %143(s16)
639 ; CHECK: [[TRUNC2:%[0-9]+]]:_(s17) = G_TRUNC [[C]](s32)
640 ; CHECK: [[TRUNC3:%[0-9]+]]:_(s1) = G_TRUNC %144(s16)
641 ; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
642 ; CHECK: [[TRUNC4:%[0-9]+]]:_(s1) = G_TRUNC %145(s16)
643 ; CHECK: [[TRUNC5:%[0-9]+]]:_(s17) = G_TRUNC [[C1]](s32)
644 ; CHECK: [[TRUNC6:%[0-9]+]]:_(s1) = G_TRUNC %146(s16)
645 ; CHECK: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 2
646 ; CHECK: [[TRUNC7:%[0-9]+]]:_(s1) = G_TRUNC %147(s16)
647 ; CHECK: [[TRUNC8:%[0-9]+]]:_(s17) = G_TRUNC [[C2]](s32)
648 ; CHECK: [[C3:%[0-9]+]]:_(s32) = G_CONSTANT i32 3
649 ; CHECK: [[TRUNC9:%[0-9]+]]:_(s17) = G_TRUNC [[C3]](s32)
650 ; CHECK: [[ZEXT:%[0-9]+]]:_(s272) = G_ZEXT [[TRUNC2]](s17)
651 ; CHECK: [[C4:%[0-9]+]]:_(s272) = G_CONSTANT i272 15
652 ; CHECK: [[SHL:%[0-9]+]]:_(s272) = G_SHL [[ZEXT]], [[C4]](s272)
653 ; CHECK: [[OR:%[0-9]+]]:_(s272) = G_OR [[ZEXT]], [[SHL]]
654 ; CHECK: [[C5:%[0-9]+]]:_(s272) = G_CONSTANT i272 30
655 ; CHECK: [[SHL1:%[0-9]+]]:_(s272) = G_SHL [[OR]], [[C5]](s272)
656 ; CHECK: [[OR1:%[0-9]+]]:_(s272) = G_OR [[OR]], [[SHL1]]
657 ; CHECK: [[C6:%[0-9]+]]:_(s272) = G_CONSTANT i272 45
658 ; CHECK: [[SHL2:%[0-9]+]]:_(s272) = G_SHL [[OR1]], [[C6]](s272)
659 ; CHECK: [[OR2:%[0-9]+]]:_(s272) = G_OR [[OR1]], [[SHL2]]
660 ; CHECK: [[C7:%[0-9]+]]:_(s272) = G_CONSTANT i272 60
661 ; CHECK: [[SHL3:%[0-9]+]]:_(s272) = G_SHL [[OR2]], [[C7]](s272)
662 ; CHECK: [[OR3:%[0-9]+]]:_(s272) = G_OR [[OR2]], [[SHL3]]
663 ; CHECK: [[C8:%[0-9]+]]:_(s272) = G_CONSTANT i272 75
664 ; CHECK: [[SHL4:%[0-9]+]]:_(s272) = G_SHL [[OR3]], [[C8]](s272)
665 ; CHECK: [[OR4:%[0-9]+]]:_(s272) = G_OR [[OR3]], [[SHL4]]
666 ; CHECK: [[C9:%[0-9]+]]:_(s272) = G_CONSTANT i272 90
667 ; CHECK: [[SHL5:%[0-9]+]]:_(s272) = G_SHL [[OR4]], [[C9]](s272)
668 ; CHECK: [[OR5:%[0-9]+]]:_(s272) = G_OR [[OR4]], [[SHL5]]
669 ; CHECK: [[C10:%[0-9]+]]:_(s272) = G_CONSTANT i272 105
670 ; CHECK: [[SHL6:%[0-9]+]]:_(s272) = G_SHL [[OR5]], [[C10]](s272)
671 ; CHECK: [[OR6:%[0-9]+]]:_(s272) = G_OR [[OR5]], [[SHL6]]
672 ; CHECK: [[C11:%[0-9]+]]:_(s272) = G_CONSTANT i272 120
673 ; CHECK: [[SHL7:%[0-9]+]]:_(s272) = G_SHL [[OR6]], [[C11]](s272)
674 ; CHECK: [[OR7:%[0-9]+]]:_(s272) = G_OR [[OR6]], [[SHL7]]
675 ; CHECK: [[C12:%[0-9]+]]:_(s272) = G_CONSTANT i272 135
676 ; CHECK: [[SHL8:%[0-9]+]]:_(s272) = G_SHL [[OR7]], [[C12]](s272)
677 ; CHECK: [[OR8:%[0-9]+]]:_(s272) = G_OR [[OR7]], [[SHL8]]
678 ; CHECK: [[C13:%[0-9]+]]:_(s272) = G_CONSTANT i272 150
679 ; CHECK: [[SHL9:%[0-9]+]]:_(s272) = G_SHL [[OR8]], [[C13]](s272)
680 ; CHECK: [[OR9:%[0-9]+]]:_(s272) = G_OR [[OR8]], [[SHL9]]
681 ; CHECK: [[C14:%[0-9]+]]:_(s272) = G_CONSTANT i272 165
682 ; CHECK: [[SHL10:%[0-9]+]]:_(s272) = G_SHL [[OR9]], [[C14]](s272)
683 ; CHECK: [[OR10:%[0-9]+]]:_(s272) = G_OR [[OR9]], [[SHL10]]
684 ; CHECK: [[C15:%[0-9]+]]:_(s272) = G_CONSTANT i272 180
685 ; CHECK: [[SHL11:%[0-9]+]]:_(s272) = G_SHL [[OR10]], [[C15]](s272)
686 ; CHECK: [[OR11:%[0-9]+]]:_(s272) = G_OR [[OR10]], [[SHL11]]
687 ; CHECK: [[C16:%[0-9]+]]:_(s272) = G_CONSTANT i272 195
688 ; CHECK: [[SHL12:%[0-9]+]]:_(s272) = G_SHL [[OR11]], [[C16]](s272)
689 ; CHECK: [[OR12:%[0-9]+]]:_(s272) = G_OR [[OR11]], [[SHL12]]
690 ; CHECK: [[C17:%[0-9]+]]:_(s272) = G_CONSTANT i272 210
691 ; CHECK: [[SHL13:%[0-9]+]]:_(s272) = G_SHL [[OR12]], [[C17]](s272)
692 ; CHECK: [[OR13:%[0-9]+]]:_(s272) = G_OR [[OR12]], [[SHL13]]
693 ; CHECK: [[C18:%[0-9]+]]:_(s272) = G_CONSTANT i272 225
694 ; CHECK: [[SHL14:%[0-9]+]]:_(s272) = G_SHL [[OR13]], [[C18]](s272)
695 ; CHECK: [[OR14:%[0-9]+]]:_(s272) = G_OR [[OR13]], [[SHL14]]
696 ; CHECK: [[C19:%[0-9]+]]:_(s272) = G_CONSTANT i272 240
697 ; CHECK: [[TRUNC10:%[0-9]+]]:_(s32) = G_TRUNC [[C19]](s272)
698 ; CHECK: [[C20:%[0-9]+]]:_(s32) = G_CONSTANT i32 136
699 ; CHECK: [[UV:%[0-9]+]]:_(s136), [[UV1:%[0-9]+]]:_(s136) = G_UNMERGE_VALUES [[OR14]](s272)
700 ; CHECK: [[SUB:%[0-9]+]]:_(s32) = G_SUB [[TRUNC10]], [[C20]]
701 ; CHECK: [[SUB1:%[0-9]+]]:_(s32) = G_SUB [[C20]], [[TRUNC10]]
702 ; CHECK: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ult), [[TRUNC10]](s32), [[C20]]
703 ; CHECK: [[ICMP1:%[0-9]+]]:_(s1) = G_ICMP intpred(eq), [[TRUNC10]](s32), [[C]]
704 ; CHECK: [[SHL15:%[0-9]+]]:_(s136) = G_SHL [[UV1]], [[TRUNC10]](s32)
705 ; CHECK: [[SHL16:%[0-9]+]]:_(s136) = G_SHL [[UV1]], [[TRUNC10]](s32)
706 ; CHECK: [[LSHR:%[0-9]+]]:_(s136) = G_LSHR [[UV]], [[SUB1]](s32)
707 ; CHECK: [[OR15:%[0-9]+]]:_(s136) = G_OR [[SHL16]], [[LSHR]]
708 ; CHECK: [[C21:%[0-9]+]]:_(s136) = G_CONSTANT i136 0
709 ; CHECK: [[SHL17:%[0-9]+]]:_(s136) = G_SHL [[UV]], [[SUB]](s32)
710 ; CHECK: [[SELECT:%[0-9]+]]:_(s136) = G_SELECT [[ICMP]](s1), [[SHL15]], [[C21]]
711 ; CHECK: [[SELECT1:%[0-9]+]]:_(s136) = G_SELECT [[ICMP]](s1), [[OR15]], [[SHL17]]
712 ; CHECK: [[EXTRACT:%[0-9]+]]:_(s64) = G_EXTRACT [[UV1]](s136), 0
713 ; CHECK: [[EXTRACT1:%[0-9]+]]:_(s64) = G_EXTRACT [[UV1]](s136), 64
714 ; CHECK: [[EXTRACT2:%[0-9]+]]:_(s8) = G_EXTRACT [[UV1]](s136), 128
715 ; CHECK: [[EXTRACT3:%[0-9]+]]:_(s64) = G_EXTRACT [[SELECT1]](s136), 0
716 ; CHECK: [[EXTRACT4:%[0-9]+]]:_(s64) = G_EXTRACT [[SELECT1]](s136), 64
717 ; CHECK: [[EXTRACT5:%[0-9]+]]:_(s8) = G_EXTRACT [[SELECT1]](s136), 128
718 ; CHECK: [[SELECT2:%[0-9]+]]:_(s64) = G_SELECT [[ICMP1]](s1), [[EXTRACT]], [[EXTRACT3]]
719 ; CHECK: [[SELECT3:%[0-9]+]]:_(s64) = G_SELECT [[ICMP1]](s1), [[EXTRACT1]], [[EXTRACT4]]
720 ; CHECK: [[SELECT4:%[0-9]+]]:_(s8) = G_SELECT [[ICMP1]](s1), [[EXTRACT2]], [[EXTRACT5]]
721 ; CHECK: [[DEF:%[0-9]+]]:_(s136) = G_IMPLICIT_DEF
722 ; CHECK: [[INSERT:%[0-9]+]]:_(s136) = G_INSERT [[DEF]], [[SELECT2]](s64), 0
723 ; CHECK: [[INSERT1:%[0-9]+]]:_(s136) = G_INSERT [[INSERT]], [[SELECT3]](s64), 64
724 ; CHECK: [[INSERT2:%[0-9]+]]:_(s136) = G_INSERT [[INSERT1]], [[SELECT4]](s8), 128
725 ; CHECK: [[MV:%[0-9]+]]:_(s272) = G_MERGE_VALUES [[SELECT]](s136), [[INSERT2]](s136)
726 ; CHECK: [[EXTRACT6:%[0-9]+]]:_(s64) = G_EXTRACT [[OR14]](s272), 0
727 ; CHECK: [[EXTRACT7:%[0-9]+]]:_(s64) = G_EXTRACT [[OR14]](s272), 64
728 ; CHECK: [[EXTRACT8:%[0-9]+]]:_(s64) = G_EXTRACT [[OR14]](s272), 128
729 ; CHECK: [[EXTRACT9:%[0-9]+]]:_(s64) = G_EXTRACT [[OR14]](s272), 192
730 ; CHECK: [[EXTRACT10:%[0-9]+]]:_(s16) = G_EXTRACT [[OR14]](s272), 256
731 ; CHECK: [[EXTRACT11:%[0-9]+]]:_(s64) = G_EXTRACT [[MV]](s272), 0
732 ; CHECK: [[EXTRACT12:%[0-9]+]]:_(s64) = G_EXTRACT [[MV]](s272), 64
733 ; CHECK: [[EXTRACT13:%[0-9]+]]:_(s64) = G_EXTRACT [[MV]](s272), 128
734 ; CHECK: [[EXTRACT14:%[0-9]+]]:_(s64) = G_EXTRACT [[MV]](s272), 192
735 ; CHECK: [[EXTRACT15:%[0-9]+]]:_(s16) = G_EXTRACT [[MV]](s272), 256
736 ; CHECK: [[OR16:%[0-9]+]]:_(s64) = G_OR [[EXTRACT6]], [[EXTRACT11]]
737 ; CHECK: [[OR17:%[0-9]+]]:_(s64) = G_OR [[EXTRACT7]], [[EXTRACT12]]
738 ; CHECK: [[OR18:%[0-9]+]]:_(s64) = G_OR [[EXTRACT8]], [[EXTRACT13]]
739 ; CHECK: [[OR19:%[0-9]+]]:_(s64) = G_OR [[EXTRACT9]], [[EXTRACT14]]
740 ; CHECK: [[OR20:%[0-9]+]]:_(s16) = G_OR [[EXTRACT10]], [[EXTRACT15]]
741 ; CHECK: [[DEF1:%[0-9]+]]:_(s512) = G_IMPLICIT_DEF
742 ; CHECK: [[TRUNC11:%[0-9]+]]:_(s272) = G_TRUNC [[DEF1]](s512)
743 ; CHECK: [[ANYEXT:%[0-9]+]]:_(s512) = G_ANYEXT [[TRUNC11]](s272)
744 ; CHECK: [[INSERT3:%[0-9]+]]:_(s512) = G_INSERT [[ANYEXT]], [[OR16]](s64), 0
745 ; CHECK: [[TRUNC12:%[0-9]+]]:_(s272) = G_TRUNC [[INSERT3]](s512)
746 ; CHECK: [[ANYEXT1:%[0-9]+]]:_(s512) = G_ANYEXT [[TRUNC12]](s272)
747 ; CHECK: [[INSERT4:%[0-9]+]]:_(s512) = G_INSERT [[ANYEXT1]], [[OR17]](s64), 64
748 ; CHECK: [[TRUNC13:%[0-9]+]]:_(s272) = G_TRUNC [[INSERT4]](s512)
749 ; CHECK: [[ANYEXT2:%[0-9]+]]:_(s512) = G_ANYEXT [[TRUNC13]](s272)
750 ; CHECK: [[INSERT5:%[0-9]+]]:_(s512) = G_INSERT [[ANYEXT2]], [[OR18]](s64), 128
751 ; CHECK: [[TRUNC14:%[0-9]+]]:_(s272) = G_TRUNC [[INSERT5]](s512)
752 ; CHECK: [[ANYEXT3:%[0-9]+]]:_(s512) = G_ANYEXT [[TRUNC14]](s272)
753 ; CHECK: [[INSERT6:%[0-9]+]]:_(s512) = G_INSERT [[ANYEXT3]], [[OR19]](s64), 192
754 ; CHECK: [[TRUNC15:%[0-9]+]]:_(s272) = G_TRUNC [[INSERT6]](s512)
755 ; CHECK: [[ANYEXT4:%[0-9]+]]:_(s512) = G_ANYEXT [[TRUNC15]](s272)
756 ; CHECK: [[INSERT7:%[0-9]+]]:_(s512) = G_INSERT [[ANYEXT4]], [[OR20]](s16), 256
757 ; CHECK: [[TRUNC16:%[0-9]+]]:_(s272) = G_TRUNC [[INSERT7]](s512)
758 ; CHECK: [[UV2:%[0-9]+]]:_(s16), [[UV3:%[0-9]+]]:_(s16), [[UV4:%[0-9]+]]:_(s16), [[UV5:%[0-9]+]]:_(s16), [[UV6:%[0-9]+]]:_(s16), [[UV7:%[0-9]+]]:_(s16), [[UV8:%[0-9]+]]:_(s16), [[UV9:%[0-9]+]]:_(s16), [[UV10:%[0-9]+]]:_(s16), [[UV11:%[0-9]+]]:_(s16), [[UV12:%[0-9]+]]:_(s16), [[UV13:%[0-9]+]]:_(s16), [[UV14:%[0-9]+]]:_(s16), [[UV15:%[0-9]+]]:_(s16), [[UV16:%[0-9]+]]:_(s16), [[UV17:%[0-9]+]]:_(s16), [[UV18:%[0-9]+]]:_(s16) = G_UNMERGE_VALUES [[TRUNC16]](s272)
759 ; CHECK: [[TRUNC17:%[0-9]+]]:_(s1) = G_TRUNC [[UV2]](s16)
760 ; CHECK: [[UV19:%[0-9]+]]:_(s1), [[UV20:%[0-9]+]]:_(s1), [[UV21:%[0-9]+]]:_(s1), [[UV22:%[0-9]+]]:_(s1), [[UV23:%[0-9]+]]:_(s1), [[UV24:%[0-9]+]]:_(s1), [[UV25:%[0-9]+]]:_(s1), [[UV26:%[0-9]+]]:_(s1), [[UV27:%[0-9]+]]:_(s1), [[UV28:%[0-9]+]]:_(s1), [[UV29:%[0-9]+]]:_(s1), [[UV30:%[0-9]+]]:_(s1), [[UV31:%[0-9]+]]:_(s1), [[UV32:%[0-9]+]]:_(s1), [[UV33:%[0-9]+]]:_(s1), [[UV34:%[0-9]+]]:_(s1), [[UV35:%[0-9]+]]:_(s1) = G_UNMERGE_VALUES [[TRUNC5]](s17)
761 ; CHECK: [[TRUNC18:%[0-9]+]]:_(s1) = G_TRUNC [[UV3]](s16)
762 ; CHECK: [[UV36:%[0-9]+]]:_(s1), [[UV37:%[0-9]+]]:_(s1), [[UV38:%[0-9]+]]:_(s1), [[UV39:%[0-9]+]]:_(s1), [[UV40:%[0-9]+]]:_(s1), [[UV41:%[0-9]+]]:_(s1), [[UV42:%[0-9]+]]:_(s1), [[UV43:%[0-9]+]]:_(s1), [[UV44:%[0-9]+]]:_(s1), [[UV45:%[0-9]+]]:_(s1), [[UV46:%[0-9]+]]:_(s1), [[UV47:%[0-9]+]]:_(s1), [[UV48:%[0-9]+]]:_(s1), [[UV49:%[0-9]+]]:_(s1), [[UV50:%[0-9]+]]:_(s1), [[UV51:%[0-9]+]]:_(s1), [[UV52:%[0-9]+]]:_(s1) = G_UNMERGE_VALUES [[TRUNC8]](s17)
763 ; CHECK: [[TRUNC19:%[0-9]+]]:_(s1) = G_TRUNC [[UV4]](s16)
764 ; CHECK: [[UV53:%[0-9]+]]:_(s1), [[UV54:%[0-9]+]]:_(s1), [[UV55:%[0-9]+]]:_(s1), [[UV56:%[0-9]+]]:_(s1), [[UV57:%[0-9]+]]:_(s1), [[UV58:%[0-9]+]]:_(s1), [[UV59:%[0-9]+]]:_(s1), [[UV60:%[0-9]+]]:_(s1), [[UV61:%[0-9]+]]:_(s1), [[UV62:%[0-9]+]]:_(s1), [[UV63:%[0-9]+]]:_(s1), [[UV64:%[0-9]+]]:_(s1), [[UV65:%[0-9]+]]:_(s1), [[UV66:%[0-9]+]]:_(s1), [[UV67:%[0-9]+]]:_(s1), [[UV68:%[0-9]+]]:_(s1), [[UV69:%[0-9]+]]:_(s1) = G_UNMERGE_VALUES [[TRUNC9]](s17)
765 ; CHECK: [[TRUNC20:%[0-9]+]]:_(s1) = G_TRUNC [[UV5]](s16)
766 ; CHECK: [[DEF2:%[0-9]+]]:_(s1) = G_IMPLICIT_DEF
767 ; CHECK: [[TRUNC21:%[0-9]+]]:_(s1) = G_TRUNC [[UV6]](s16)
768 ; CHECK: [[MV1:%[0-9]+]]:_(s32) = G_MERGE_VALUES [[TRUNC17]](s1), [[TRUNC18]](s1), [[TRUNC19]](s1), [[TRUNC20]](s1), [[TRUNC21]](s1), %14(s1), %15(s1), %16(s1), %17(s1), %18(s1), %19(s1), [[TRUNC]](s1), [[TRUNC1]](s1), [[TRUNC3]](s1), [[TRUNC4]](s1), [[TRUNC6]](s1), [[TRUNC7]](s1), [[UV19]](s1), [[UV20]](s1), [[UV21]](s1), [[UV22]](s1), [[UV23]](s1), [[UV24]](s1), [[UV25]](s1), [[UV26]](s1), [[UV27]](s1), [[UV28]](s1), [[UV29]](s1), [[UV30]](s1), [[UV31]](s1), [[UV32]](s1), [[UV33]](s1)
769 ; CHECK: [[TRUNC22:%[0-9]+]]:_(s1) = G_TRUNC [[UV7]](s16)
770 ; CHECK: [[MV2:%[0-9]+]]:_(s32) = G_MERGE_VALUES [[UV34]](s1), [[UV35]](s1), [[UV36]](s1), [[UV37]](s1), [[UV38]](s1), [[UV39]](s1), [[UV40]](s1), [[UV41]](s1), [[UV42]](s1), [[UV43]](s1), [[UV44]](s1), [[UV45]](s1), [[UV46]](s1), [[UV47]](s1), [[UV48]](s1), [[UV49]](s1), [[UV50]](s1), [[UV51]](s1), [[UV52]](s1), [[UV53]](s1), [[UV54]](s1), [[UV55]](s1), [[UV56]](s1), [[UV57]](s1), [[UV58]](s1), [[UV59]](s1), [[UV60]](s1), [[UV61]](s1), [[UV62]](s1), [[UV63]](s1), [[UV64]](s1), [[UV65]](s1)
771 ; CHECK: [[TRUNC23:%[0-9]+]]:_(s1) = G_TRUNC [[UV8]](s16)
772 ; CHECK: [[MV3:%[0-9]+]]:_(s32) = G_MERGE_VALUES [[UV66]](s1), [[UV67]](s1), [[UV68]](s1), [[UV69]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1), [[DEF2]](s1)
773 ; CHECK: [[TRUNC24:%[0-9]+]]:_(s1) = G_TRUNC [[UV9]](s16)
774 ; CHECK: [[MV4:%[0-9]+]]:_(s96) = G_MERGE_VALUES [[MV1]](s32), [[MV2]](s32), [[MV3]](s32)
775 ; CHECK: [[TRUNC25:%[0-9]+]]:_(s1) = G_TRUNC [[UV10]](s16)
776 ; CHECK: [[TRUNC26:%[0-9]+]]:_(s68) = G_TRUNC [[MV4]](s96)
777 ; CHECK: [[TRUNC27:%[0-9]+]]:_(s1) = G_TRUNC [[UV11]](s16)
778 ; CHECK: S_NOP 0, implicit [[TRUNC26]](s68)
779 ; CHECK: [[TRUNC28:%[0-9]+]]:_(s1) = G_TRUNC [[UV12]](s16)
780 %0:_(s17) = G_CONSTANT i17 0
781 %1:_(s17) = G_CONSTANT i17 1
782 %2:_(s17) = G_CONSTANT i17 2
783 %3:_(s17) = G_CONSTANT i17 3
784 %4:_(s68) = G_MERGE_VALUES %0, %1, %2, %3
785 S_NOP 0, implicit %4
786 ...
907907 if (!TM)
908908 return;
909909
910 const LLT S32 = LLT::scalar(32);
910911 const LLT S24 = LLT::scalar(24);
912 const LLT S21 = LLT::scalar(21);
913 const LLT S16 = LLT::scalar(16);
911914 const LLT S9 = LLT::scalar(9);
915 const LLT S8 = LLT::scalar(8);
912916 const LLT S3 = LLT::scalar(3);
913917
914918 DefineLegalizerInfo(A, {
924928 // 24 = 3 3 3 3 3 3 3 3
925929 // => 9
926930 //
927 // This can do 2 merges for the first parts, but has 2 leftover operands.
928 SmallVector MergeOps;
931 // This can do 3 merges, but need an extra implicit_def.
932 SmallVector Merge0Ops;
929933 for (int I = 0; I != 8; ++I)
930 MergeOps.push_back(B.buildConstant(S3, I).getReg(0));
931
932 auto Merge = B.buildMerge(S24, MergeOps);
933 EXPECT_EQ(LegalizerHelper::LegalizeResult::UnableToLegalize,
934 Helper.lower(*Merge, 1, S9));
934 Merge0Ops.push_back(B.buildConstant(S3, I).getReg(0));
935
936 auto Merge0 = B.buildMerge(S24, Merge0Ops);
937
938 // 21 = 3 3 3 3 3 3 3
939 // => 9, 2 extra implicit_def needed
940 //
941 SmallVector Merge1Ops;
942 for (int I = 0; I != 7; ++I)
943 Merge1Ops.push_back(B.buildConstant(S3, I).getReg(0));
944
945 auto Merge1 = B.buildMerge(S21, Merge1Ops);
946
947 SmallVector Merge2Ops;
948 for (int I = 0; I != 2; ++I)
949 Merge2Ops.push_back(B.buildConstant(S8, I).getReg(0));
950
951 auto Merge2 = B.buildMerge(S16, Merge2Ops);
952
953
954 EXPECT_EQ(LegalizerHelper::LegalizeResult::Legalized,
955 Helper.widenScalar(*Merge0, 1, S9));
956 EXPECT_EQ(LegalizerHelper::LegalizeResult::Legalized,
957 Helper.widenScalar(*Merge1, 1, S9));
958
959 // Request a source size greater than the original destination size.
960 EXPECT_EQ(LegalizerHelper::LegalizeResult::Legalized,
961 Helper.widenScalar(*Merge2, 1, S32));
962
963 auto CheckStr = R"(
964 CHECK: [[K0:%[0-9]+]]:_(s3) = G_CONSTANT i3 0
965 CHECK-NEXT: [[K1:%[0-9]+]]:_(s3) = G_CONSTANT i3 1
966 CHECK-NEXT: [[K2:%[0-9]+]]:_(s3) = G_CONSTANT i3 2
967 CHECK-NEXT: [[K3:%[0-9]+]]:_(s3) = G_CONSTANT i3 3
968 CHECK-NEXT: [[K4:%[0-9]+]]:_(s3) = G_CONSTANT i3 -4
969 CHECK-NEXT: [[K5:%[0-9]+]]:_(s3) = G_CONSTANT i3 -3
970 CHECK-NEXT: [[K6:%[0-9]+]]:_(s3) = G_CONSTANT i3 -2
971 CHECK-NEXT: [[K7:%[0-9]+]]:_(s3) = G_CONSTANT i3 -1
972 CHECK-NEXT: [[IMPDEF0:%[0-9]+]]:_(s3) = G_IMPLICIT_DEF
973 CHECK-NEXT: [[MERGE0:%[0-9]+]]:_(s9) = G_MERGE_VALUES [[K0]]:_(s3), [[K1]]:_(s3), [[K2]]:_(s3)
974 CHECK-NEXT: [[MERGE1:%[0-9]+]]:_(s9) = G_MERGE_VALUES [[K3]]:_(s3), [[K4]]:_(s3), [[K5]]:_(s3)
975 CHECK-NEXT: [[MERGE2:%[0-9]+]]:_(s9) = G_MERGE_VALUES [[K6]]:_(s3), [[K7]]:_(s3), [[IMPDEF0]]:_(s3)
976 CHECK-NEXT: [[MERGE3:%[0-9]+]]:_(s27) = G_MERGE_VALUES [[MERGE0]]:_(s9), [[MERGE1]]:_(s9), [[MERGE2]]:_(s9)
977 CHECK-NEXT: (s24) = G_TRUNC [[MERGE3]]:_(s27)
978
979
980 CHECK: [[K8:%[0-9]+]]:_(s3) = G_CONSTANT i3 0
981 CHECK-NEXT: [[K9:%[0-9]+]]:_(s3) = G_CONSTANT i3 1
982 CHECK-NEXT: [[K10:%[0-9]+]]:_(s3) = G_CONSTANT i3 2
983 CHECK-NEXT: [[K11:%[0-9]+]]:_(s3) = G_CONSTANT i3 3
984 CHECK-NEXT: [[K12:%[0-9]+]]:_(s3) = G_CONSTANT i3 -4
985 CHECK-NEXT: [[K13:%[0-9]+]]:_(s3) = G_CONSTANT i3 -3
986 CHECK-NEXT: [[K14:%[0-9]+]]:_(s3) = G_CONSTANT i3 -2
987 CHECK-NEXT: [[IMPDEF1:%[0-9]+]]:_(s3) = G_IMPLICIT_DEF
988 CHECK-NEXT: [[MERGE4:%[0-9]+]]:_(s9) = G_MERGE_VALUES [[K8]]:_(s3), [[K9]]:_(s3), [[K10]]:_(s3)
989 CHECK-NEXT: [[MERGE5:%[0-9]+]]:_(s9) = G_MERGE_VALUES [[K11]]:_(s3), [[K12]]:_(s3), [[K13]]:_(s3)
990 CHECK-NEXT: [[MERGE6:%[0-9]+]]:_(s9) = G_MERGE_VALUES [[K14]]:_(s3), [[IMPDEF1]]:_(s3), [[IMPDEF1]]:_(s3)
991 CHECK-NEXT: [[MERGE7:%[0-9]+]]:_(s27) = G_MERGE_VALUES [[MERGE4]]:_(s9), [[MERGE5]]:_(s9), [[MERGE6]]:_(s9)
992 CHECK-NEXT: (s21) = G_TRUNC [[MERGE7]]:_(s27)
993
994
995 CHECK: [[K15:%[0-9]+]]:_(s8) = G_CONSTANT i8 0
996 CHECK-NEXT: [[K16:%[0-9]+]]:_(s8) = G_CONSTANT i8 1
997 CHECK-NEXT: [[ZEXT_K15:[0-9]+]]:_(s32) = G_ZEXT [[K15]]:_(s8)
998 CHECK-NEXT: [[ZEXT_K16:[0-9]+]]:_(s32) = G_ZEXT [[K16]]:_(s8)
999 [[K16:%[0-9]+]]:_(s32) = G_CONSTANT i32 8
1000 [[SHL:%[0-9]+]]:_(s32) = G_SHL [[ZEXT_K16]]:_, [[K16]]:_(s32)
1001 [[OR:%[0-9]+]]:_(s32) = G_OR [[ZEXT_K16]]:_, [[SHL]]:_
1002 (s16) = G_TRUNC [[OR]]:_(s32)
1003 )";
1004
1005 EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
9351006 }
9361007 } // namespace