[LSR] Make sure that Factor fits into Base type

Fixes pr42770

Differential Revision: https://reviews.llvm.org/D108772
This commit is contained in:
Danila Malyutin 2021-08-26 21:00:13 +03:00
parent 1d66649adf
commit 78b51c7a2c
2 changed files with 11 additions and 5 deletions

View File

@ -3934,6 +3934,9 @@ void LSRInstance::GenerateICmpZeroScales(LSRUse &LU, unsigned LUIdx,
// 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<int64_t>::min() && Factor == -1)
continue;

View File

@ -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