diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -3934,6 +3934,9 @@ // Check each interesting stride. for (int64_t Factor : Factors) { + // Check that Factor can be represented by IntTy + if (!ConstantInt::isValueValidForType(IntTy, Factor)) + continue; // Check that the multiplication doesn't overflow. if (Base.BaseOffset == std::numeric_limits::min() && Factor == -1) continue; diff --git a/llvm/test/Transforms/LoopStrengthReduce/pr42770.ll b/llvm/test/Transforms/LoopStrengthReduce/pr42770.ll --- a/llvm/test/Transforms/LoopStrengthReduce/pr42770.ll +++ b/llvm/test/Transforms/LoopStrengthReduce/pr42770.ll @@ -1,6 +1,5 @@ ; Check that it doesn't crash ; REQUIRES: asserts -; XFAIL: * ; RUN: opt < %s -loop-reduce -S target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128-ni:1"