summaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/LoopStrengthReduce.cpp
diff options
context:
space:
mode:
authorQuentin Colombet <qcolombet@apple.com>2013-06-19 19:59:41 +0000
committerQuentin Colombet <qcolombet@apple.com>2013-06-19 19:59:41 +0000
commit5a2fb058d3628063cacc3dda0cda331c8d4dab11 (patch)
tree48c8684cae8e901efe9c6fd4e984e69bed1fd596 /lib/Transforms/Scalar/LoopStrengthReduce.cpp
parentae5758bac75f561f8aa519476942e02be73022e4 (diff)
downloadllvm-5a2fb058d3628063cacc3dda0cda331c8d4dab11.tar.gz
llvm-5a2fb058d3628063cacc3dda0cda331c8d4dab11.tar.bz2
llvm-5a2fb058d3628063cacc3dda0cda331c8d4dab11.tar.xz
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. <rdar://problem/14199725> 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
Diffstat (limited to 'lib/Transforms/Scalar/LoopStrengthReduce.cpp')
-rw-r--r--lib/Transforms/Scalar/LoopStrengthReduce.cpp18
1 files changed, 13 insertions, 5 deletions
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.