From 5a2fb058d3628063cacc3dda0cda331c8d4dab11 Mon Sep 17 00:00:00 2001 From: Quentin Colombet Date: Wed, 19 Jun 2013 19:59:41 +0000 Subject: LSR: Fix the parameters used to compute the scaling factor cost. Prior to this change, the considered addressing modes may be invalid since the maximum and minimum offsets were not taking into account. This was causing an assertion failure. The added test case exercices that behavior. Assertion failed: (CurScaleCost >= 0 && "Legal addressing mode has an illegal cost!") git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184341 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/LoopStrengthReduce.cpp | 18 ++++-- .../scaling_factor_cost_crash.ll | 68 ++++++++++++++++++++++ 2 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 test/Transforms/LoopStrengthReduce/scaling_factor_cost_crash.ll diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 246de56d9a..14cb979392 100644 --- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -1417,11 +1417,19 @@ static unsigned getScalingFactorCost(const TargetTransformInfo &TTI, switch (LU.Kind) { case LSRUse::Address: { - int CurScaleCost = TTI.getScalingFactorCost(LU.AccessTy, F.BaseGV, - F.BaseOffset, F.HasBaseReg, - F.Scale); - assert(CurScaleCost >= 0 && "Legal addressing mode has an illegal cost!"); - return CurScaleCost; + // Check the scaling factor cost with both the min and max offsets. + int ScaleCostMinOffset = + TTI.getScalingFactorCost(LU.AccessTy, F.BaseGV, + F.BaseOffset + LU.MinOffset, + F.HasBaseReg, F.Scale); + int ScaleCostMaxOffset = + TTI.getScalingFactorCost(LU.AccessTy, F.BaseGV, + F.BaseOffset + LU.MaxOffset, + F.HasBaseReg, F.Scale); + + assert(ScaleCostMinOffset >= 0 && ScaleCostMaxOffset >= 0 && + "Legal addressing mode has an illegal cost!"); + return std::max(ScaleCostMinOffset, ScaleCostMaxOffset); } case LSRUse::ICmpZero: // ICmpZero BaseReg + -1*ScaleReg => ICmp BaseReg, ScaleReg. diff --git a/test/Transforms/LoopStrengthReduce/scaling_factor_cost_crash.ll b/test/Transforms/LoopStrengthReduce/scaling_factor_cost_crash.ll new file mode 100644 index 0000000000..cd8fec3d2c --- /dev/null +++ b/test/Transforms/LoopStrengthReduce/scaling_factor_cost_crash.ll @@ -0,0 +1,68 @@ +; RUN: opt -loop-reduce %s -S -o - | FileCheck %s +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S32" +target triple = "i686-pc-win32" + +; Assertion failed: (CurScaleCost >= 0 && "Legal addressing mode has an illegal cost!") +; CHECK: @scalingFactorCrash +define void @scalingFactorCrash() { + br i1 undef, label %1, label %24 + +;