summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
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
commit145eb97d3a8a1f2766a891003c659483dcf15681 (patch)
tree3c930c4ff7ceca99dbdfbd8aadc2a2afaae7453d /llvm/lib/Transforms
parenta3555e24169781d7b923a4c928313420ee1a4a8e (diff)
downloadbcm5719-llvm-145eb97d3a8a1f2766a891003c659483dcf15681.tar.gz
bcm5719-llvm-145eb97d3a8a1f2766a891003c659483dcf15681.zip
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!") llvm-svn: 184341
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index 246de56d9ad..14cb9793925 100644
--- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/llvm/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.
OpenPOWER on IntegriCloud