@@ -16736,38 +16736,51 @@ SDValue DAGCombiner::visitBITCAST(SDNode *N) {
1673616736 }
1673716737
1673816738 // fold (conv (load x)) -> (load (conv*)x)
16739+ // fold (conv (freeze (load x))) -> (freeze (load (conv*)x))
1673916740 // If the resultant load doesn't need a higher alignment than the original!
16740- if (ISD::isNormalLoad(N0.getNode()) && N0.hasOneUse() &&
16741- // Do not remove the cast if the types differ in endian layout.
16742- TLI.hasBigEndianPartOrdering(N0.getValueType(), DAG.getDataLayout()) ==
16743- TLI.hasBigEndianPartOrdering(VT, DAG.getDataLayout()) &&
16744- // If the load is volatile, we only want to change the load type if the
16745- // resulting load is legal. Otherwise we might increase the number of
16746- // memory accesses. We don't care if the original type was legal or not
16747- // as we assume software couldn't rely on the number of accesses of an
16748- // illegal type.
16749- ((!LegalOperations && cast<LoadSDNode>(N0)->isSimple()) ||
16750- TLI.isOperationLegal(ISD::LOAD, VT))) {
16751- LoadSDNode *LN0 = cast<LoadSDNode>(N0);
16741+ auto CastLoad = [this, &VT](SDValue N0, const SDLoc &DL) {
16742+ if (!ISD::isNormalLoad(N0.getNode()) || !N0.hasOneUse())
16743+ return SDValue();
1675216744
16753- if (TLI.isLoadBitCastBeneficial(N0.getValueType(), VT, DAG,
16754- *LN0->getMemOperand())) {
16755- // If the range metadata type does not match the new memory
16756- // operation type, remove the range metadata.
16757- if (const MDNode *MD = LN0->getRanges()) {
16758- ConstantInt *Lower = mdconst::extract<ConstantInt>(MD->getOperand(0));
16759- if (Lower->getBitWidth() != VT.getScalarSizeInBits() ||
16760- !VT.isInteger()) {
16761- LN0->getMemOperand()->clearRanges();
16762- }
16745+ // Do not remove the cast if the types differ in endian layout.
16746+ if (TLI.hasBigEndianPartOrdering(N0.getValueType(), DAG.getDataLayout()) !=
16747+ TLI.hasBigEndianPartOrdering(VT, DAG.getDataLayout()))
16748+ return SDValue();
16749+
16750+ // If the load is volatile, we only want to change the load type if the
16751+ // resulting load is legal. Otherwise we might increase the number of
16752+ // memory accesses. We don't care if the original type was legal or not
16753+ // as we assume software couldn't rely on the number of accesses of an
16754+ // illegal type.
16755+ auto *LN0 = cast<LoadSDNode>(N0);
16756+ if ((LegalOperations || !LN0->isSimple()) &&
16757+ !TLI.isOperationLegal(ISD::LOAD, VT))
16758+ return SDValue();
16759+
16760+ if (!TLI.isLoadBitCastBeneficial(N0.getValueType(), VT, DAG,
16761+ *LN0->getMemOperand()))
16762+ return SDValue();
16763+
16764+ // If the range metadata type does not match the new memory
16765+ // operation type, remove the range metadata.
16766+ if (const MDNode *MD = LN0->getRanges()) {
16767+ ConstantInt *Lower = mdconst::extract<ConstantInt>(MD->getOperand(0));
16768+ if (Lower->getBitWidth() != VT.getScalarSizeInBits() || !VT.isInteger()) {
16769+ LN0->getMemOperand()->clearRanges();
1676316770 }
16764- SDValue Load =
16765- DAG.getLoad(VT, SDLoc(N), LN0->getChain(), LN0->getBasePtr(),
16766- LN0->getMemOperand());
16767- DAG.ReplaceAllUsesOfValueWith(N0.getValue(1), Load.getValue(1));
16768- return Load;
1676916771 }
16770- }
16772+ SDValue Load = DAG.getLoad(VT, DL, LN0->getChain(), LN0->getBasePtr(),
16773+ LN0->getMemOperand());
16774+ DAG.ReplaceAllUsesOfValueWith(N0.getValue(1), Load.getValue(1));
16775+ return Load;
16776+ };
16777+
16778+ if (SDValue NewLd = CastLoad(N0, SDLoc(N)))
16779+ return NewLd;
16780+
16781+ if (N0.getOpcode() == ISD::FREEZE && N0.hasOneUse())
16782+ if (SDValue NewLd = CastLoad(N0.getOperand(0), SDLoc(N)))
16783+ return DAG.getFreeze(NewLd);
1677116784
1677216785 if (SDValue V = foldBitcastedFPLogic(N, DAG, TLI))
1677316786 return V;
0 commit comments