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/scaling-factor-incompat-type.ll rename from llvm/test/Transforms/LoopStrengthReduce/pr42770.ll rename to llvm/test/Transforms/LoopStrengthReduce/scaling-factor-incompat-type.ll --- a/llvm/test/Transforms/LoopStrengthReduce/pr42770.ll +++ b/llvm/test/Transforms/LoopStrengthReduce/scaling-factor-incompat-type.ll @@ -1,20 +1,23 @@ -; Check that it doesn't crash +; Check that it doesn't crash by generating formula with zero in base register +; when one of the IV factors does't fit (2^32 in this test) the formula type +; see pr42770 ; REQUIRES: asserts -; XFAIL: * -; RUN: opt < %s -loop-reduce -S +; RUN: opt < %s -loop-reduce -S | FileCheck %s target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128-ni:1" +; CHECK-LABEL: @foo( define void @foo() { bb: br label %bb4 - +; CHECK: bb1: +; CHECK: %tmp3 = ashr i64 %lsr.iv.next, 32 bb1: ; preds = %bb13 %tmp = shl i64 %tmp14, 32 %tmp2 = add i64 %tmp, 1 %tmp3 = ashr i64 %tmp2, 32 ret void - +; CHECK bb4: bb4: ; preds = %bb13, %bb %tmp5 = phi i64 [ 2, %bb ], [ %tmp14, %bb13 ] %tmp6 = add i64 %tmp5, 4