Index: lib/Target/X86/X86ISelLowering.cpp =================================================================== --- lib/Target/X86/X86ISelLowering.cpp +++ lib/Target/X86/X86ISelLowering.cpp @@ -6394,6 +6394,7 @@ const TargetLowering &TLI = DAG.getTargetLoweringInfo(); LLVMContext *Ctx = DAG.getContext(); MVT PVT = TLI.getPointerTy(DAG.getDataLayout()); + SDValue Brdcst; if (Subtarget.hasAVX()) { if (SplatBitSize <= 64 && Subtarget.hasAVX2() && !(SplatBitSize == 64 && Subtarget.is32Bit())) { @@ -6410,9 +6411,8 @@ CVT, dl, DAG.getEntryNode(), CP, MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), Alignment); - SDValue Brdcst = DAG.getNode(X86ISD::VBROADCAST, dl, + Brdcst = DAG.getNode(X86ISD::VBROADCAST, dl, MVT::getVectorVT(CVT, Repeat), Ld); - return DAG.getBitcast(VT, Brdcst); } else if (SplatBitSize == 32 || SplatBitSize == 64) { // Splatted value can fit in one FLOAT constant in constant pool. // Load the constant and broadcast it. @@ -6432,9 +6432,8 @@ CVT, dl, DAG.getEntryNode(), CP, MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), Alignment); - SDValue Brdcst = DAG.getNode(X86ISD::VBROADCAST, dl, + Brdcst = DAG.getNode(X86ISD::VBROADCAST, dl, MVT::getVectorVT(CVT, Repeat), Ld); - return DAG.getBitcast(VT, Brdcst); } else if (SplatBitSize > 64) { // Load the vector of constants and broadcast it. MVT CVT = VT.getScalarType(); @@ -6447,9 +6446,15 @@ MVT::getVectorVT(CVT, NumElm), dl, DAG.getEntryNode(), VCP, MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), Alignment); - SDValue Brdcst = DAG.getNode(X86ISD::SUBV_BROADCAST, dl, VT, Ld); - return DAG.getBitcast(VT, Brdcst); + Brdcst = DAG.getNode(X86ISD::SUBV_BROADCAST, dl, VT, Ld); + } else { + return SDValue(); } + // If the load already had a use, we can't fold it into the broadcast. + // So fallback to the original state. + if (!Ld.hasOneUse()) + return SDValue(); + return DAG.getBitcast(VT, Brdcst); } } return SDValue();