From 8b330f1f6919a2ac85eeda753ad8d1090468e23f Mon Sep 17 00:00:00 2001 From: Max Kazantsev Date: Tue, 15 Dec 2020 14:40:17 +0700 Subject: [PATCH] [SCEV] Add missing type check into getRangeForAffineNoSelfWrappingAR We make type widening without checking if it's needed. Bail if the max iteration count is wider than AR's type. --- llvm/lib/Analysis/ScalarEvolution.cpp | 3 +++ .../IndVarSimplify/2020-12-15-trunc-bug-expensive-range-inference.ll | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 3005a44..071b569 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -6006,6 +6006,9 @@ ConstantRange ScalarEvolution::getRangeForAffineNoSelfWrappingAR( // iteration count estimate, and we might infer nw from some exit for which we // do not know max exit count (or any other side reasoning). // TODO: Turn into assert at some point. + if (getTypeSizeInBits(MaxBECount->getType()) > + getTypeSizeInBits(AddRec->getType())) + return ConstantRange::getFull(BitWidth); MaxBECount = getNoopOrZeroExtend(MaxBECount, AddRec->getType()); const SCEV *RangeWidth = getMinusOne(AddRec->getType()); const SCEV *StepAbs = getUMinExpr(Step, getNegativeSCEV(Step)); diff --git a/llvm/test/Transforms/IndVarSimplify/2020-12-15-trunc-bug-expensive-range-inference.ll b/llvm/test/Transforms/IndVarSimplify/2020-12-15-trunc-bug-expensive-range-inference.ll index dd105f4..a1ad4d0 100644 --- a/llvm/test/Transforms/IndVarSimplify/2020-12-15-trunc-bug-expensive-range-inference.ll +++ b/llvm/test/Transforms/IndVarSimplify/2020-12-15-trunc-bug-expensive-range-inference.ll @@ -1,7 +1,5 @@ ; RUN: opt < %s -indvars -S -scalar-evolution-use-expensive-range-sharpening | FileCheck %s ; RUN: opt < %s -passes=indvars -S -scalar-evolution-use-expensive-range-sharpening | FileCheck %s -; REQUIRES: asserts -; XFAIL: * target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2" target triple = "x86_64-unknown-linux-gnu" -- 2.7.4