[SCEV] Add missing type check into getRangeForAffineNoSelfWrappingAR
authorMax Kazantsev <mkazantsev@azul.com>
Tue, 15 Dec 2020 07:40:17 +0000 (14:40 +0700)
committerMax Kazantsev <mkazantsev@azul.com>
Tue, 15 Dec 2020 07:50:32 +0000 (14:50 +0700)
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
llvm/test/Transforms/IndVarSimplify/2020-12-15-trunc-bug-expensive-range-inference.ll

index 3005a44..071b569 100644 (file)
@@ -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));
index dd105f4..a1ad4d0 100644 (file)
@@ -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"