Index: lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp =================================================================== --- lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp +++ lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp @@ -555,6 +555,11 @@ unsigned RemainingBytes = SrcVT.getStoreSize(); SmallVector LoadVals; + // The object itself can't wrap around the address space, so it shouldn't be + // possible for the adds of the offsets to the split parts to overflow. + SDNodeFlags FlagsNUW; + FlagsNUW.setNoUnsignedWrap(true); + while (RemainingBytes > 0) { SDValue ScalarLoad; unsigned LoadBytes = WideBytes; @@ -582,7 +587,7 @@ Offset += LoadBytes; BasePTR = DAG.getNode(ISD::ADD, dl, BasePTR.getValueType(), BasePTR, DAG.getConstant(LoadBytes, dl, - BasePTR.getValueType())); + BasePTR.getValueType()), FlagsNUW); LoadVals.push_back(ScalarLoad.getValue(0)); LoadChains.push_back(ScalarLoad.getValue(1)); Index: lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp =================================================================== --- lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp +++ lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp @@ -1123,6 +1123,11 @@ MachineMemOperand::Flags MMOFlags = LD->getMemOperand()->getFlags(); AAMDNodes AAInfo = LD->getAAInfo(); + // The object itself can't wrap around the address space, so it shouldn't be + // possible for the adds of the offsets to the split parts to overflow. + SDNodeFlags FlagsNUW; + FlagsNUW.setNoUnsignedWrap(true); + EVT LoMemVT, HiMemVT; std::tie(LoMemVT, HiMemVT) = DAG.GetSplitDestVTs(MemoryVT); @@ -1131,7 +1136,8 @@ unsigned IncrementSize = LoMemVT.getSizeInBits()/8; Ptr = DAG.getNode(ISD::ADD, dl, Ptr.getValueType(), Ptr, - DAG.getConstant(IncrementSize, dl, Ptr.getValueType())); + DAG.getConstant(IncrementSize, dl, Ptr.getValueType()), + FlagsNUW); Hi = DAG.getLoad(ISD::UNINDEXED, ExtType, HiVT, dl, Ch, Ptr, Offset, LD->getPointerInfo().getWithOffset(IncrementSize), HiMemVT, Alignment, MMOFlags, AAInfo); @@ -3808,11 +3814,17 @@ LdWidth -= NewVTWidth; unsigned Offset = 0; + // The object itself can't wrap around the address space, so it shouldn't be + // possible for the adds of the offsets to the split parts to overflow. + SDNodeFlags FlagsNUW; + FlagsNUW.setNoUnsignedWrap(true); + while (LdWidth > 0) { unsigned Increment = NewVTWidth / 8; Offset += Increment; BasePtr = DAG.getNode(ISD::ADD, dl, BasePtr.getValueType(), BasePtr, - DAG.getConstant(Increment, dl, BasePtr.getValueType())); + DAG.getConstant(Increment, dl, BasePtr.getValueType()), + FlagsNUW); SDValue L; if (LdWidth < NewVTWidth) { @@ -3924,6 +3936,11 @@ EVT LdEltVT = LdVT.getVectorElementType(); unsigned NumElts = LdVT.getVectorNumElements(); + // The object itself can't wrap around the address space, so it shouldn't be + // possible for the adds of the offsets to the split parts to overflow. + SDNodeFlags FlagsNUW; + FlagsNUW.setNoUnsignedWrap(true); + // Load each element and widen. unsigned WidenNumElts = WidenVT.getVectorNumElements(); SmallVector Ops(WidenNumElts); @@ -3937,7 +3954,8 @@ SDValue NewBasePtr = DAG.getNode(ISD::ADD, dl, BasePtr.getValueType(), BasePtr, DAG.getConstant(Offset, dl, - BasePtr.getValueType())); + BasePtr.getValueType()), + FlagsNUW); Ops[i] = DAG.getExtLoad(ExtType, dl, EltVT, Chain, NewBasePtr, LD->getPointerInfo().getWithOffset(Offset), LdEltVT, Align, MMOFlags, AAInfo); @@ -3973,6 +3991,11 @@ unsigned ValEltWidth = ValEltVT.getSizeInBits(); assert(StVT.getVectorElementType() == ValEltVT); + // The object itself can't wrap around the address space, so it shouldn't be + // possible for the adds of the offsets to the split parts to overflow. + SDNodeFlags FlagsNUW; + FlagsNUW.setNoUnsignedWrap(true); + int Idx = 0; // current index to store unsigned Offset = 0; // offset from base to store while (StWidth != 0) { @@ -3994,7 +4017,8 @@ Idx += NumVTElts; BasePtr = DAG.getNode(ISD::ADD, dl, BasePtr.getValueType(), BasePtr, DAG.getConstant(Increment, dl, - BasePtr.getValueType())); + BasePtr.getValueType()), + FlagsNUW); } while (StWidth != 0 && StWidth >= NewVTWidth); } else { // Cast the vector to the scalar type we can store. @@ -4015,7 +4039,7 @@ Offset += Increment; BasePtr = DAG.getNode(ISD::ADD, dl, BasePtr.getValueType(), BasePtr, DAG.getConstant(Increment, dl, - BasePtr.getValueType())); + BasePtr.getValueType()), FlagsNUW); } while (StWidth != 0 && StWidth >= NewVTWidth); // Restore index back to be relative to the original widen element type. Idx = Idx * NewVTWidth / ValEltWidth; @@ -4036,6 +4060,11 @@ SDValue ValOp = GetWidenedVector(ST->getValue()); SDLoc dl(ST); + // The object itself can't wrap around the address space, so it shouldn't be + // possible for the adds of the offsets to the split parts to overflow. + SDNodeFlags FlagsNUW; + FlagsNUW.setNoUnsignedWrap(true); + EVT StVT = ST->getMemoryVT(); EVT ValVT = ValOp.getValueType(); @@ -4061,7 +4090,8 @@ SDValue NewBasePtr = DAG.getNode(ISD::ADD, dl, BasePtr.getValueType(), BasePtr, DAG.getConstant(Offset, dl, - BasePtr.getValueType())); + BasePtr.getValueType()), + FlagsNUW); SDValue EOp = DAG.getNode( ISD::EXTRACT_VECTOR_ELT, dl, ValEltVT, ValOp, DAG.getConstant(0, dl, TLI.getVectorIdxTy(DAG.getDataLayout()))); Index: lib/CodeGen/SelectionDAG/TargetLowering.cpp =================================================================== --- lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -3426,6 +3426,11 @@ EVT IdxVT = getVectorIdxTy(DAG.getDataLayout()); unsigned NumElem = StVT.getVectorNumElements(); + // The object itself can't wrap around the address space, so it shouldn't be + // possible for the adds of the offsets to the split parts to overflow. + SDNodeFlags FlagsNUW; + FlagsNUW.setNoUnsignedWrap(true); + // Extract each of the elements from the original vector and save them into // memory individually. SmallVector Stores; @@ -3434,7 +3439,8 @@ DAG.getConstant(Idx, SL, IdxVT)); SDValue Ptr = DAG.getNode(ISD::ADD, SL, PtrVT, BasePtr, - DAG.getConstant(Idx * Stride, SL, PtrVT)); + DAG.getConstant(Idx * Stride, SL, PtrVT), + FlagsNUW); // This scalar TruncStore may be illegal, but we legalize it later. SDValue Store = DAG.getTruncStore( @@ -3458,6 +3464,12 @@ EVT LoadedVT = LD->getMemoryVT(); SDLoc dl(LD); auto &MF = DAG.getMachineFunction(); + + // The object itself can't wrap around the address space, so it shouldn't be + // possible for the adds of the offsets to the split parts to overflow. + SDNodeFlags FlagsNUW; + FlagsNUW.setNoUnsignedWrap(true); + if (VT.isFloatingPoint() || VT.isVector()) { EVT intVT = EVT::getIntegerVT(*DAG.getContext(), LoadedVT.getSizeInBits()); if (isTypeLegal(intVT) && isTypeLegal(LoadedVT)) { @@ -3512,9 +3524,9 @@ MachinePointerInfo::getFixedStack(MF, FrameIndex, Offset))); // Increment the pointers. Offset += RegBytes; - Ptr = DAG.getNode(ISD::ADD, dl, PtrVT, Ptr, PtrIncrement); + Ptr = DAG.getNode(ISD::ADD, dl, PtrVT, Ptr, PtrIncrement, FlagsNUW); StackPtr = DAG.getNode(ISD::ADD, dl, StackPtrVT, StackPtr, - StackPtrIncrement); + StackPtrIncrement, FlagsNUW); } // The last copy may be partial. Do an extending load. @@ -3569,7 +3581,8 @@ NewLoadedVT, Alignment, LD->getMemOperand()->getFlags(), LD->getAAInfo()); Ptr = DAG.getNode(ISD::ADD, dl, Ptr.getValueType(), Ptr, - DAG.getConstant(IncrementSize, dl, Ptr.getValueType())); + DAG.getConstant(IncrementSize, dl, Ptr.getValueType()), + FlagsNUW); Hi = DAG.getExtLoad(HiExtType, dl, VT, Chain, Ptr, LD->getPointerInfo().getWithOffset(IncrementSize), NewLoadedVT, MinAlign(Alignment, IncrementSize), @@ -3579,7 +3592,8 @@ NewLoadedVT, Alignment, LD->getMemOperand()->getFlags(), LD->getAAInfo()); Ptr = DAG.getNode(ISD::ADD, dl, Ptr.getValueType(), Ptr, - DAG.getConstant(IncrementSize, dl, Ptr.getValueType())); + DAG.getConstant(IncrementSize, dl, Ptr.getValueType()), + FlagsNUW); Lo = DAG.getExtLoad(ISD::ZEXTLOAD, dl, VT, Chain, Ptr, LD->getPointerInfo().getWithOffset(IncrementSize), NewLoadedVT, MinAlign(Alignment, IncrementSize), @@ -3610,6 +3624,11 @@ int Alignment = ST->getAlignment(); auto &MF = DAG.getMachineFunction(); + // The object itself can't wrap around the address space, so it shouldn't be + // possible for the adds of the offsets to the split parts to overflow. + SDNodeFlags FlagsNUW; + FlagsNUW.setNoUnsignedWrap(true); + SDLoc dl(ST); if (ST->getMemoryVT().isFloatingPoint() || ST->getMemoryVT().isVector()) { @@ -3671,8 +3690,8 @@ // Increment the pointers. Offset += RegBytes; StackPtr = DAG.getNode(ISD::ADD, dl, StackPtrVT, - StackPtr, StackPtrIncrement); - Ptr = DAG.getNode(ISD::ADD, dl, PtrVT, Ptr, PtrIncrement); + StackPtr, StackPtrIncrement, FlagsNUW); + Ptr = DAG.getNode(ISD::ADD, dl, PtrVT, Ptr, PtrIncrement, FlagsNUW); } // The last store may be partial. Do a truncating store. On big-endian @@ -3720,7 +3739,7 @@ EVT PtrVT = Ptr.getValueType(); Ptr = DAG.getNode(ISD::ADD, dl, PtrVT, Ptr, - DAG.getConstant(IncrementSize, dl, PtrVT)); + DAG.getConstant(IncrementSize, dl, PtrVT), FlagsNUW); Alignment = MinAlign(Alignment, IncrementSize); Store2 = DAG.getTruncStore( Chain, dl, DAG.getDataLayout().isLittleEndian() ? Hi : Lo, Ptr,