@@ -638,7 +638,6 @@ namespace {
638638 SDValue mergeInsertEltWithShuffle(SDNode *N, unsigned InsIndex);
639639 SDValue combineInsertEltToShuffle(SDNode *N, unsigned InsIndex);
640640 SDValue combineInsertEltToLoad(SDNode *N, unsigned InsIndex);
641- SDValue ConstantFoldBITCASTofBUILD_VECTOR(SDNode *, EVT);
642641 SDValue BuildSDIV(SDNode *N);
643642 SDValue BuildSDIVPow2(SDNode *N);
644643 SDValue BuildUDIV(SDNode *N);
@@ -16431,8 +16430,8 @@ SDValue DAGCombiner::visitBITCAST(SDNode *N) {
1643116430 TLI.isTypeLegal(VT.getVectorElementType()))) &&
1643216431 N0.getOpcode() == ISD::BUILD_VECTOR && N0->hasOneUse() &&
1643316432 cast<BuildVectorSDNode>(N0)->isConstant())
16434- return ConstantFoldBITCASTofBUILD_VECTOR(N0.getNode( ),
16435- VT.getVectorElementType());
16433+ return DAG.FoldConstantBuildVector(cast<BuildVectorSDNode>(N0), SDLoc(N ),
16434+ VT.getVectorElementType());
1643616435
1643716436 // If the input is a constant, let getNode fold it.
1643816437 if (isIntOrFPConstant(N0)) {
@@ -16825,83 +16824,6 @@ SDValue DAGCombiner::visitFREEZE(SDNode *N) {
1682516824 return DAG.getNode(N0.getOpcode(), DL, N0->getVTList(), Ops, SafeFlags);
1682616825}
1682716826
16828- /// We know that BV is a build_vector node with Constant, ConstantFP or Undef
16829- /// operands. DstEltVT indicates the destination element value type.
16830- SDValue DAGCombiner::
16831- ConstantFoldBITCASTofBUILD_VECTOR(SDNode *BV, EVT DstEltVT) {
16832- EVT SrcEltVT = BV->getValueType(0).getVectorElementType();
16833-
16834- // If this is already the right type, we're done.
16835- if (SrcEltVT == DstEltVT) return SDValue(BV, 0);
16836-
16837- unsigned SrcBitSize = SrcEltVT.getSizeInBits();
16838- unsigned DstBitSize = DstEltVT.getSizeInBits();
16839-
16840- // If this is a conversion of N elements of one type to N elements of another
16841- // type, convert each element. This handles FP<->INT cases.
16842- if (SrcBitSize == DstBitSize) {
16843- SmallVector<SDValue, 8> Ops;
16844- for (SDValue Op : BV->op_values()) {
16845- // If the vector element type is not legal, the BUILD_VECTOR operands
16846- // are promoted and implicitly truncated. Make that explicit here.
16847- if (Op.getValueType() != SrcEltVT)
16848- Op = DAG.getNode(ISD::TRUNCATE, SDLoc(BV), SrcEltVT, Op);
16849- Ops.push_back(DAG.getBitcast(DstEltVT, Op));
16850- AddToWorklist(Ops.back().getNode());
16851- }
16852- EVT VT = EVT::getVectorVT(*DAG.getContext(), DstEltVT,
16853- BV->getValueType(0).getVectorNumElements());
16854- return DAG.getBuildVector(VT, SDLoc(BV), Ops);
16855- }
16856-
16857- // Otherwise, we're growing or shrinking the elements. To avoid having to
16858- // handle annoying details of growing/shrinking FP values, we convert them to
16859- // int first.
16860- if (SrcEltVT.isFloatingPoint()) {
16861- // Convert the input float vector to a int vector where the elements are the
16862- // same sizes.
16863- EVT IntVT = EVT::getIntegerVT(*DAG.getContext(), SrcEltVT.getSizeInBits());
16864- BV = ConstantFoldBITCASTofBUILD_VECTOR(BV, IntVT).getNode();
16865- SrcEltVT = IntVT;
16866- }
16867-
16868- // Now we know the input is an integer vector. If the output is a FP type,
16869- // convert to integer first, then to FP of the right size.
16870- if (DstEltVT.isFloatingPoint()) {
16871- EVT TmpVT = EVT::getIntegerVT(*DAG.getContext(), DstEltVT.getSizeInBits());
16872- SDNode *Tmp = ConstantFoldBITCASTofBUILD_VECTOR(BV, TmpVT).getNode();
16873-
16874- // Next, convert to FP elements of the same size.
16875- return ConstantFoldBITCASTofBUILD_VECTOR(Tmp, DstEltVT);
16876- }
16877-
16878- // Okay, we know the src/dst types are both integers of differing types.
16879- assert(SrcEltVT.isInteger() && DstEltVT.isInteger());
16880-
16881- // TODO: Should ConstantFoldBITCASTofBUILD_VECTOR always take a
16882- // BuildVectorSDNode?
16883- auto *BVN = cast<BuildVectorSDNode>(BV);
16884-
16885- // Extract the constant raw bit data.
16886- BitVector UndefElements;
16887- SmallVector<APInt> RawBits;
16888- bool IsLE = DAG.getDataLayout().isLittleEndian();
16889- if (!BVN->getConstantRawBits(IsLE, DstBitSize, RawBits, UndefElements))
16890- return SDValue();
16891-
16892- SDLoc DL(BV);
16893- SmallVector<SDValue, 8> Ops;
16894- for (unsigned I = 0, E = RawBits.size(); I != E; ++I) {
16895- if (UndefElements[I])
16896- Ops.push_back(DAG.getUNDEF(DstEltVT));
16897- else
16898- Ops.push_back(DAG.getConstant(RawBits[I], DL, DstEltVT));
16899- }
16900-
16901- EVT VT = EVT::getVectorVT(*DAG.getContext(), DstEltVT, Ops.size());
16902- return DAG.getBuildVector(VT, DL, Ops);
16903- }
16904-
1690516827// Returns true if floating point contraction is allowed on the FMUL-SDValue
1690616828// `N`
1690716829static bool isContractableFMUL(const TargetOptions &Options, SDValue N) {
0 commit comments