xref: /freebsd/contrib/llvm-project/llvm/lib/Target/SystemZ/SystemZSelectionDAGInfo.cpp (revision 5ffd83dbcc34f10e07f6d3e968ae6365869615f4)
10b57cec5SDimitry Andric //===-- SystemZSelectionDAGInfo.cpp - SystemZ SelectionDAG Info -----------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file implements the SystemZSelectionDAGInfo class.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #include "SystemZTargetMachine.h"
140b57cec5SDimitry Andric #include "llvm/CodeGen/SelectionDAG.h"
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric using namespace llvm;
170b57cec5SDimitry Andric 
180b57cec5SDimitry Andric #define DEBUG_TYPE "systemz-selectiondag-info"
190b57cec5SDimitry Andric 
200b57cec5SDimitry Andric // Decide whether it is best to use a loop or straight-line code for
210b57cec5SDimitry Andric // a block operation of Size bytes with source address Src and destination
220b57cec5SDimitry Andric // address Dest.  Sequence is the opcode to use for straight-line code
230b57cec5SDimitry Andric // (such as MVC) and Loop is the opcode to use for loops (such as MVC_LOOP).
240b57cec5SDimitry Andric // Return the chain for the completed operation.
250b57cec5SDimitry Andric static SDValue emitMemMem(SelectionDAG &DAG, const SDLoc &DL, unsigned Sequence,
260b57cec5SDimitry Andric                           unsigned Loop, SDValue Chain, SDValue Dst,
270b57cec5SDimitry Andric                           SDValue Src, uint64_t Size) {
280b57cec5SDimitry Andric   EVT PtrVT = Src.getValueType();
290b57cec5SDimitry Andric   // The heuristic we use is to prefer loops for anything that would
300b57cec5SDimitry Andric   // require 7 or more MVCs.  With these kinds of sizes there isn't
310b57cec5SDimitry Andric   // much to choose between straight-line code and looping code,
320b57cec5SDimitry Andric   // since the time will be dominated by the MVCs themselves.
330b57cec5SDimitry Andric   // However, the loop has 4 or 5 instructions (depending on whether
340b57cec5SDimitry Andric   // the base addresses can be proved equal), so there doesn't seem
350b57cec5SDimitry Andric   // much point using a loop for 5 * 256 bytes or fewer.  Anything in
360b57cec5SDimitry Andric   // the range (5 * 256, 6 * 256) will need another instruction after
370b57cec5SDimitry Andric   // the loop, so it doesn't seem worth using a loop then either.
380b57cec5SDimitry Andric   // The next value up, 6 * 256, can be implemented in the same
390b57cec5SDimitry Andric   // number of straight-line MVCs as 6 * 256 - 1.
400b57cec5SDimitry Andric   if (Size > 6 * 256)
410b57cec5SDimitry Andric     return DAG.getNode(Loop, DL, MVT::Other, Chain, Dst, Src,
420b57cec5SDimitry Andric                        DAG.getConstant(Size, DL, PtrVT),
430b57cec5SDimitry Andric                        DAG.getConstant(Size / 256, DL, PtrVT));
440b57cec5SDimitry Andric   return DAG.getNode(Sequence, DL, MVT::Other, Chain, Dst, Src,
450b57cec5SDimitry Andric                      DAG.getConstant(Size, DL, PtrVT));
460b57cec5SDimitry Andric }
470b57cec5SDimitry Andric 
480b57cec5SDimitry Andric SDValue SystemZSelectionDAGInfo::EmitTargetCodeForMemcpy(
490b57cec5SDimitry Andric     SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Dst, SDValue Src,
50*5ffd83dbSDimitry Andric     SDValue Size, Align Alignment, bool IsVolatile, bool AlwaysInline,
510b57cec5SDimitry Andric     MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {
520b57cec5SDimitry Andric   if (IsVolatile)
530b57cec5SDimitry Andric     return SDValue();
540b57cec5SDimitry Andric 
550b57cec5SDimitry Andric   if (auto *CSize = dyn_cast<ConstantSDNode>(Size))
560b57cec5SDimitry Andric     return emitMemMem(DAG, DL, SystemZISD::MVC, SystemZISD::MVC_LOOP,
570b57cec5SDimitry Andric                       Chain, Dst, Src, CSize->getZExtValue());
580b57cec5SDimitry Andric   return SDValue();
590b57cec5SDimitry Andric }
600b57cec5SDimitry Andric 
610b57cec5SDimitry Andric // Handle a memset of 1, 2, 4 or 8 bytes with the operands given by
620b57cec5SDimitry Andric // Chain, Dst, ByteVal and Size.  These cases are expected to use
630b57cec5SDimitry Andric // MVI, MVHHI, MVHI and MVGHI respectively.
640b57cec5SDimitry Andric static SDValue memsetStore(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain,
650b57cec5SDimitry Andric                            SDValue Dst, uint64_t ByteVal, uint64_t Size,
660b57cec5SDimitry Andric                            unsigned Align, MachinePointerInfo DstPtrInfo) {
670b57cec5SDimitry Andric   uint64_t StoreVal = ByteVal;
680b57cec5SDimitry Andric   for (unsigned I = 1; I < Size; ++I)
690b57cec5SDimitry Andric     StoreVal |= ByteVal << (I * 8);
700b57cec5SDimitry Andric   return DAG.getStore(
710b57cec5SDimitry Andric       Chain, DL, DAG.getConstant(StoreVal, DL, MVT::getIntegerVT(Size * 8)),
720b57cec5SDimitry Andric       Dst, DstPtrInfo, Align);
730b57cec5SDimitry Andric }
740b57cec5SDimitry Andric 
750b57cec5SDimitry Andric SDValue SystemZSelectionDAGInfo::EmitTargetCodeForMemset(
760b57cec5SDimitry Andric     SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Dst,
77*5ffd83dbSDimitry Andric     SDValue Byte, SDValue Size, Align Alignment, bool IsVolatile,
780b57cec5SDimitry Andric     MachinePointerInfo DstPtrInfo) const {
790b57cec5SDimitry Andric   EVT PtrVT = Dst.getValueType();
800b57cec5SDimitry Andric 
810b57cec5SDimitry Andric   if (IsVolatile)
820b57cec5SDimitry Andric     return SDValue();
830b57cec5SDimitry Andric 
840b57cec5SDimitry Andric   if (auto *CSize = dyn_cast<ConstantSDNode>(Size)) {
850b57cec5SDimitry Andric     uint64_t Bytes = CSize->getZExtValue();
860b57cec5SDimitry Andric     if (Bytes == 0)
870b57cec5SDimitry Andric       return SDValue();
880b57cec5SDimitry Andric     if (auto *CByte = dyn_cast<ConstantSDNode>(Byte)) {
890b57cec5SDimitry Andric       // Handle cases that can be done using at most two of
900b57cec5SDimitry Andric       // MVI, MVHI, MVHHI and MVGHI.  The latter two can only be
910b57cec5SDimitry Andric       // used if ByteVal is all zeros or all ones; in other casees,
920b57cec5SDimitry Andric       // we can move at most 2 halfwords.
930b57cec5SDimitry Andric       uint64_t ByteVal = CByte->getZExtValue();
940b57cec5SDimitry Andric       if (ByteVal == 0 || ByteVal == 255 ?
950b57cec5SDimitry Andric           Bytes <= 16 && countPopulation(Bytes) <= 2 :
960b57cec5SDimitry Andric           Bytes <= 4) {
970b57cec5SDimitry Andric         unsigned Size1 = Bytes == 16 ? 8 : 1 << findLastSet(Bytes);
980b57cec5SDimitry Andric         unsigned Size2 = Bytes - Size1;
990b57cec5SDimitry Andric         SDValue Chain1 = memsetStore(DAG, DL, Chain, Dst, ByteVal, Size1,
100*5ffd83dbSDimitry Andric                                      Alignment.value(), DstPtrInfo);
1010b57cec5SDimitry Andric         if (Size2 == 0)
1020b57cec5SDimitry Andric           return Chain1;
1030b57cec5SDimitry Andric         Dst = DAG.getNode(ISD::ADD, DL, PtrVT, Dst,
1040b57cec5SDimitry Andric                           DAG.getConstant(Size1, DL, PtrVT));
1050b57cec5SDimitry Andric         DstPtrInfo = DstPtrInfo.getWithOffset(Size1);
106*5ffd83dbSDimitry Andric         SDValue Chain2 = memsetStore(
107*5ffd83dbSDimitry Andric             DAG, DL, Chain, Dst, ByteVal, Size2,
108*5ffd83dbSDimitry Andric             std::min((unsigned)Alignment.value(), Size1), DstPtrInfo);
1090b57cec5SDimitry Andric         return DAG.getNode(ISD::TokenFactor, DL, MVT::Other, Chain1, Chain2);
1100b57cec5SDimitry Andric       }
1110b57cec5SDimitry Andric     } else {
1120b57cec5SDimitry Andric       // Handle one and two bytes using STC.
1130b57cec5SDimitry Andric       if (Bytes <= 2) {
114*5ffd83dbSDimitry Andric         SDValue Chain1 =
115*5ffd83dbSDimitry Andric             DAG.getStore(Chain, DL, Byte, Dst, DstPtrInfo, Alignment);
1160b57cec5SDimitry Andric         if (Bytes == 1)
1170b57cec5SDimitry Andric           return Chain1;
1180b57cec5SDimitry Andric         SDValue Dst2 = DAG.getNode(ISD::ADD, DL, PtrVT, Dst,
1190b57cec5SDimitry Andric                                    DAG.getConstant(1, DL, PtrVT));
1200b57cec5SDimitry Andric         SDValue Chain2 =
1210b57cec5SDimitry Andric             DAG.getStore(Chain, DL, Byte, Dst2, DstPtrInfo.getWithOffset(1),
1220b57cec5SDimitry Andric                          /* Alignment = */ 1);
1230b57cec5SDimitry Andric         return DAG.getNode(ISD::TokenFactor, DL, MVT::Other, Chain1, Chain2);
1240b57cec5SDimitry Andric       }
1250b57cec5SDimitry Andric     }
1260b57cec5SDimitry Andric     assert(Bytes >= 2 && "Should have dealt with 0- and 1-byte cases already");
1270b57cec5SDimitry Andric 
1280b57cec5SDimitry Andric     // Handle the special case of a memset of 0, which can use XC.
1290b57cec5SDimitry Andric     auto *CByte = dyn_cast<ConstantSDNode>(Byte);
1300b57cec5SDimitry Andric     if (CByte && CByte->getZExtValue() == 0)
1310b57cec5SDimitry Andric       return emitMemMem(DAG, DL, SystemZISD::XC, SystemZISD::XC_LOOP,
1320b57cec5SDimitry Andric                         Chain, Dst, Dst, Bytes);
1330b57cec5SDimitry Andric 
1340b57cec5SDimitry Andric     // Copy the byte to the first location and then use MVC to copy
1350b57cec5SDimitry Andric     // it to the rest.
136*5ffd83dbSDimitry Andric     Chain = DAG.getStore(Chain, DL, Byte, Dst, DstPtrInfo, Alignment);
1370b57cec5SDimitry Andric     SDValue DstPlus1 = DAG.getNode(ISD::ADD, DL, PtrVT, Dst,
1380b57cec5SDimitry Andric                                    DAG.getConstant(1, DL, PtrVT));
1390b57cec5SDimitry Andric     return emitMemMem(DAG, DL, SystemZISD::MVC, SystemZISD::MVC_LOOP,
1400b57cec5SDimitry Andric                       Chain, DstPlus1, Dst, Bytes - 1);
1410b57cec5SDimitry Andric   }
1420b57cec5SDimitry Andric   return SDValue();
1430b57cec5SDimitry Andric }
1440b57cec5SDimitry Andric 
1450b57cec5SDimitry Andric // Use CLC to compare [Src1, Src1 + Size) with [Src2, Src2 + Size),
1460b57cec5SDimitry Andric // deciding whether to use a loop or straight-line code.
1470b57cec5SDimitry Andric static SDValue emitCLC(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain,
1480b57cec5SDimitry Andric                        SDValue Src1, SDValue Src2, uint64_t Size) {
1490b57cec5SDimitry Andric   SDVTList VTs = DAG.getVTList(MVT::i32, MVT::Other);
1500b57cec5SDimitry Andric   EVT PtrVT = Src1.getValueType();
1510b57cec5SDimitry Andric   // A two-CLC sequence is a clear win over a loop, not least because it
1520b57cec5SDimitry Andric   // needs only one branch.  A three-CLC sequence needs the same number
1530b57cec5SDimitry Andric   // of branches as a loop (i.e. 2), but is shorter.  That brings us to
1540b57cec5SDimitry Andric   // lengths greater than 768 bytes.  It seems relatively likely that
1550b57cec5SDimitry Andric   // a difference will be found within the first 768 bytes, so we just
1560b57cec5SDimitry Andric   // optimize for the smallest number of branch instructions, in order
1570b57cec5SDimitry Andric   // to avoid polluting the prediction buffer too much.  A loop only ever
1580b57cec5SDimitry Andric   // needs 2 branches, whereas a straight-line sequence would need 3 or more.
1590b57cec5SDimitry Andric   if (Size > 3 * 256)
1600b57cec5SDimitry Andric     return DAG.getNode(SystemZISD::CLC_LOOP, DL, VTs, Chain, Src1, Src2,
1610b57cec5SDimitry Andric                        DAG.getConstant(Size, DL, PtrVT),
1620b57cec5SDimitry Andric                        DAG.getConstant(Size / 256, DL, PtrVT));
1630b57cec5SDimitry Andric   return DAG.getNode(SystemZISD::CLC, DL, VTs, Chain, Src1, Src2,
1640b57cec5SDimitry Andric                      DAG.getConstant(Size, DL, PtrVT));
1650b57cec5SDimitry Andric }
1660b57cec5SDimitry Andric 
1670b57cec5SDimitry Andric // Convert the current CC value into an integer that is 0 if CC == 0,
1680b57cec5SDimitry Andric // greater than zero if CC == 1 and less than zero if CC >= 2.
1690b57cec5SDimitry Andric // The sequence starts with IPM, which puts CC into bits 29 and 28
1700b57cec5SDimitry Andric // of an integer and clears bits 30 and 31.
1710b57cec5SDimitry Andric static SDValue addIPMSequence(const SDLoc &DL, SDValue CCReg,
1720b57cec5SDimitry Andric                               SelectionDAG &DAG) {
1730b57cec5SDimitry Andric   SDValue IPM = DAG.getNode(SystemZISD::IPM, DL, MVT::i32, CCReg);
1740b57cec5SDimitry Andric   SDValue SHL = DAG.getNode(ISD::SHL, DL, MVT::i32, IPM,
1750b57cec5SDimitry Andric                             DAG.getConstant(30 - SystemZ::IPM_CC, DL, MVT::i32));
1760b57cec5SDimitry Andric   SDValue SRA = DAG.getNode(ISD::SRA, DL, MVT::i32, SHL,
1770b57cec5SDimitry Andric                             DAG.getConstant(30, DL, MVT::i32));
1780b57cec5SDimitry Andric   return SRA;
1790b57cec5SDimitry Andric }
1800b57cec5SDimitry Andric 
1810b57cec5SDimitry Andric std::pair<SDValue, SDValue> SystemZSelectionDAGInfo::EmitTargetCodeForMemcmp(
1820b57cec5SDimitry Andric     SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Src1,
1830b57cec5SDimitry Andric     SDValue Src2, SDValue Size, MachinePointerInfo Op1PtrInfo,
1840b57cec5SDimitry Andric     MachinePointerInfo Op2PtrInfo) const {
1850b57cec5SDimitry Andric   if (auto *CSize = dyn_cast<ConstantSDNode>(Size)) {
1860b57cec5SDimitry Andric     uint64_t Bytes = CSize->getZExtValue();
1870b57cec5SDimitry Andric     assert(Bytes > 0 && "Caller should have handled 0-size case");
1880b57cec5SDimitry Andric     // Swap operands to invert CC == 1 vs. CC == 2 cases.
1890b57cec5SDimitry Andric     SDValue CCReg = emitCLC(DAG, DL, Chain, Src2, Src1, Bytes);
1900b57cec5SDimitry Andric     Chain = CCReg.getValue(1);
1910b57cec5SDimitry Andric     return std::make_pair(addIPMSequence(DL, CCReg, DAG), Chain);
1920b57cec5SDimitry Andric   }
1930b57cec5SDimitry Andric   return std::make_pair(SDValue(), SDValue());
1940b57cec5SDimitry Andric }
1950b57cec5SDimitry Andric 
1960b57cec5SDimitry Andric std::pair<SDValue, SDValue> SystemZSelectionDAGInfo::EmitTargetCodeForMemchr(
1970b57cec5SDimitry Andric     SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Src,
1980b57cec5SDimitry Andric     SDValue Char, SDValue Length, MachinePointerInfo SrcPtrInfo) const {
1990b57cec5SDimitry Andric   // Use SRST to find the character.  End is its address on success.
2000b57cec5SDimitry Andric   EVT PtrVT = Src.getValueType();
2010b57cec5SDimitry Andric   SDVTList VTs = DAG.getVTList(PtrVT, MVT::i32, MVT::Other);
2020b57cec5SDimitry Andric   Length = DAG.getZExtOrTrunc(Length, DL, PtrVT);
2030b57cec5SDimitry Andric   Char = DAG.getZExtOrTrunc(Char, DL, MVT::i32);
2040b57cec5SDimitry Andric   Char = DAG.getNode(ISD::AND, DL, MVT::i32, Char,
2050b57cec5SDimitry Andric                      DAG.getConstant(255, DL, MVT::i32));
2060b57cec5SDimitry Andric   SDValue Limit = DAG.getNode(ISD::ADD, DL, PtrVT, Src, Length);
2070b57cec5SDimitry Andric   SDValue End = DAG.getNode(SystemZISD::SEARCH_STRING, DL, VTs, Chain,
2080b57cec5SDimitry Andric                             Limit, Src, Char);
2090b57cec5SDimitry Andric   SDValue CCReg = End.getValue(1);
2100b57cec5SDimitry Andric   Chain = End.getValue(2);
2110b57cec5SDimitry Andric 
2120b57cec5SDimitry Andric   // Now select between End and null, depending on whether the character
2130b57cec5SDimitry Andric   // was found.
2148bcb0991SDimitry Andric   SDValue Ops[] = {
2158bcb0991SDimitry Andric       End, DAG.getConstant(0, DL, PtrVT),
2168bcb0991SDimitry Andric       DAG.getTargetConstant(SystemZ::CCMASK_SRST, DL, MVT::i32),
2178bcb0991SDimitry Andric       DAG.getTargetConstant(SystemZ::CCMASK_SRST_FOUND, DL, MVT::i32), CCReg};
2180b57cec5SDimitry Andric   End = DAG.getNode(SystemZISD::SELECT_CCMASK, DL, PtrVT, Ops);
2190b57cec5SDimitry Andric   return std::make_pair(End, Chain);
2200b57cec5SDimitry Andric }
2210b57cec5SDimitry Andric 
2220b57cec5SDimitry Andric std::pair<SDValue, SDValue> SystemZSelectionDAGInfo::EmitTargetCodeForStrcpy(
2230b57cec5SDimitry Andric     SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Dest,
2240b57cec5SDimitry Andric     SDValue Src, MachinePointerInfo DestPtrInfo, MachinePointerInfo SrcPtrInfo,
2250b57cec5SDimitry Andric     bool isStpcpy) const {
2260b57cec5SDimitry Andric   SDVTList VTs = DAG.getVTList(Dest.getValueType(), MVT::Other);
2270b57cec5SDimitry Andric   SDValue EndDest = DAG.getNode(SystemZISD::STPCPY, DL, VTs, Chain, Dest, Src,
2280b57cec5SDimitry Andric                                 DAG.getConstant(0, DL, MVT::i32));
2290b57cec5SDimitry Andric   return std::make_pair(isStpcpy ? EndDest : Dest, EndDest.getValue(1));
2300b57cec5SDimitry Andric }
2310b57cec5SDimitry Andric 
2320b57cec5SDimitry Andric std::pair<SDValue, SDValue> SystemZSelectionDAGInfo::EmitTargetCodeForStrcmp(
2330b57cec5SDimitry Andric     SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Src1,
2340b57cec5SDimitry Andric     SDValue Src2, MachinePointerInfo Op1PtrInfo,
2350b57cec5SDimitry Andric     MachinePointerInfo Op2PtrInfo) const {
2360b57cec5SDimitry Andric   SDVTList VTs = DAG.getVTList(Src1.getValueType(), MVT::i32, MVT::Other);
2370b57cec5SDimitry Andric   // Swap operands to invert CC == 1 vs. CC == 2 cases.
2380b57cec5SDimitry Andric   SDValue Unused = DAG.getNode(SystemZISD::STRCMP, DL, VTs, Chain, Src2, Src1,
2390b57cec5SDimitry Andric                                DAG.getConstant(0, DL, MVT::i32));
2400b57cec5SDimitry Andric   SDValue CCReg = Unused.getValue(1);
2410b57cec5SDimitry Andric   Chain = Unused.getValue(2);
2420b57cec5SDimitry Andric   return std::make_pair(addIPMSequence(DL, CCReg, DAG), Chain);
2430b57cec5SDimitry Andric }
2440b57cec5SDimitry Andric 
2450b57cec5SDimitry Andric // Search from Src for a null character, stopping once Src reaches Limit.
2460b57cec5SDimitry Andric // Return a pair of values, the first being the number of nonnull characters
2470b57cec5SDimitry Andric // and the second being the out chain.
2480b57cec5SDimitry Andric //
2490b57cec5SDimitry Andric // This can be used for strlen by setting Limit to 0.
2500b57cec5SDimitry Andric static std::pair<SDValue, SDValue> getBoundedStrlen(SelectionDAG &DAG,
2510b57cec5SDimitry Andric                                                     const SDLoc &DL,
2520b57cec5SDimitry Andric                                                     SDValue Chain, SDValue Src,
2530b57cec5SDimitry Andric                                                     SDValue Limit) {
2540b57cec5SDimitry Andric   EVT PtrVT = Src.getValueType();
2550b57cec5SDimitry Andric   SDVTList VTs = DAG.getVTList(PtrVT, MVT::i32, MVT::Other);
2560b57cec5SDimitry Andric   SDValue End = DAG.getNode(SystemZISD::SEARCH_STRING, DL, VTs, Chain,
2570b57cec5SDimitry Andric                             Limit, Src, DAG.getConstant(0, DL, MVT::i32));
2580b57cec5SDimitry Andric   Chain = End.getValue(2);
2590b57cec5SDimitry Andric   SDValue Len = DAG.getNode(ISD::SUB, DL, PtrVT, End, Src);
2600b57cec5SDimitry Andric   return std::make_pair(Len, Chain);
2610b57cec5SDimitry Andric }
2620b57cec5SDimitry Andric 
2630b57cec5SDimitry Andric std::pair<SDValue, SDValue> SystemZSelectionDAGInfo::EmitTargetCodeForStrlen(
2640b57cec5SDimitry Andric     SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Src,
2650b57cec5SDimitry Andric     MachinePointerInfo SrcPtrInfo) const {
2660b57cec5SDimitry Andric   EVT PtrVT = Src.getValueType();
2670b57cec5SDimitry Andric   return getBoundedStrlen(DAG, DL, Chain, Src, DAG.getConstant(0, DL, PtrVT));
2680b57cec5SDimitry Andric }
2690b57cec5SDimitry Andric 
2700b57cec5SDimitry Andric std::pair<SDValue, SDValue> SystemZSelectionDAGInfo::EmitTargetCodeForStrnlen(
2710b57cec5SDimitry Andric     SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Src,
2720b57cec5SDimitry Andric     SDValue MaxLength, MachinePointerInfo SrcPtrInfo) const {
2730b57cec5SDimitry Andric   EVT PtrVT = Src.getValueType();
2740b57cec5SDimitry Andric   MaxLength = DAG.getZExtOrTrunc(MaxLength, DL, PtrVT);
2750b57cec5SDimitry Andric   SDValue Limit = DAG.getNode(ISD::ADD, DL, PtrVT, Src, MaxLength);
2760b57cec5SDimitry Andric   return getBoundedStrlen(DAG, DL, Chain, Src, Limit);
2770b57cec5SDimitry Andric }
278