26 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
			
		
		
	
	
			26 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
| diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
 | |
| index cf02ef1e83f3..e370f8c34809 100644
 | |
| --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
 | |
| +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
 | |
| @@ -3885,8 +3885,8 @@ void LSRInstance::GenerateICmpZeroScales(LSRUse &LU, unsigned LUIdx,
 | |
|      // Check that the multiplication doesn't overflow.
 | |
|      if (Base.BaseOffset == std::numeric_limits<int64_t>::min() && Factor == -1)
 | |
|        continue;
 | |
| -    int64_t NewBaseOffset = (uint64_t)Base.BaseOffset * Factor;
 | |
| -    if (NewBaseOffset / Factor != Base.BaseOffset)
 | |
| +    int64_t NewBaseOffset;
 | |
| +    if(__builtin_mul_overflow(Base.BaseOffset, Factor, &NewBaseOffset))
 | |
|        continue;
 | |
|      // If the offset will be truncated at this use, check that it is in bounds.
 | |
|      if (!IntTy->isPointerTy() &&
 | |
| @@ -3897,8 +3897,7 @@ void LSRInstance::GenerateICmpZeroScales(LSRUse &LU, unsigned LUIdx,
 | |
|      int64_t Offset = LU.MinOffset;
 | |
|      if (Offset == std::numeric_limits<int64_t>::min() && Factor == -1)
 | |
|        continue;
 | |
| -    Offset = (uint64_t)Offset * Factor;
 | |
| -    if (Offset / Factor != LU.MinOffset)
 | |
| +    if(__builtin_mul_overflow(Offset, Factor, &Offset))
 | |
|        continue;
 | |
|      // If the offset will be truncated at this use, check that it is in bounds.
 | |
|      if (!IntTy->isPointerTy() &&
 |