Index: lib/Transforms/Scalar/GVN.cpp =================================================================== --- lib/Transforms/Scalar/GVN.cpp +++ lib/Transforms/Scalar/GVN.cpp @@ -1045,8 +1045,15 @@ Value *DepPtr = DepLI->getPointerOperand(); uint64_t DepSize = DL.getTypeSizeInBits(DepLI->getType()); - int R = AnalyzeLoadFromClobberingWrite(LoadTy, LoadPtr, DepPtr, DepSize, DL); - if (R != -1) return R; + int Offset = AnalyzeLoadFromClobberingWrite(LoadTy, LoadPtr, DepPtr, DepSize, DL); + if (Offset != -1) { + // If the size is too large and we will have to widen, ensure we pass the + // widening rules below + unsigned SrcValSize = DL.getTypeStoreSize(DepLI->getType()); + unsigned LoadSize = DL.getTypeStoreSize(LoadTy); + if (Offset + LoadSize <= SrcValSize) + return Offset; + } // If we have a load/load clobber an DepLI can be widened to cover this load, // then we should widen it!