[llvm] 78b51c7 - [LSR] Make sure that Factor fits into Base type

Danila Malyutin via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 21 10:51:32 PDT 2021


Author: Danila Malyutin
Date: 2021-09-21T20:50:50+03:00
New Revision: 78b51c7a2cb6994c1baf4349d61266f36f0c45c5

URL: https://github.com/llvm/llvm-project/commit/78b51c7a2cb6994c1baf4349d61266f36f0c45c5
DIFF: https://github.com/llvm/llvm-project/commit/78b51c7a2cb6994c1baf4349d61266f36f0c45c5.diff

LOG: [LSR] Make sure that Factor fits into Base type

Fixes pr42770

Differential Revision: https://reviews.llvm.org/D108772

Added: 
    llvm/test/Transforms/LoopStrengthReduce/scaling-factor-incompat-type.ll

Modified: 
    llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Removed: 
    llvm/test/Transforms/LoopStrengthReduce/pr42770.ll


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index cbb8073256cfa..1523f6a7c479c 100644
--- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -3934,6 +3934,9 @@ void LSRInstance::GenerateICmpZeroScales(LSRUse &LU, unsigned LUIdx,
 
   // Check each interesting stride.
   for (int64_t Factor : Factors) {
+    // Check that Factor can be represented by IntTy
+    if (!ConstantInt::isValueValidForType(IntTy, Factor))
+      continue;
     // Check that the multiplication doesn't overflow.
     if (Base.BaseOffset == std::numeric_limits<int64_t>::min() && Factor == -1)
       continue;

diff  --git a/llvm/test/Transforms/LoopStrengthReduce/pr42770.ll b/llvm/test/Transforms/LoopStrengthReduce/scaling-factor-incompat-type.ll
similarity index 73%
rename from llvm/test/Transforms/LoopStrengthReduce/pr42770.ll
rename to llvm/test/Transforms/LoopStrengthReduce/scaling-factor-incompat-type.ll
index afe6778f783c4..7e2654df1f820 100644
--- a/llvm/test/Transforms/LoopStrengthReduce/pr42770.ll
+++ b/llvm/test/Transforms/LoopStrengthReduce/scaling-factor-incompat-type.ll
@@ -1,20 +1,23 @@
-; Check that it doesn't crash
+; Check that it doesn't crash by generating formula with zero in base register
+; when one of the IV factors does't fit (2^32 in this test) the formula type
+; see pr42770
 ; REQUIRES: asserts
-; XFAIL: *
-; RUN: opt < %s -loop-reduce -S
+; RUN: opt < %s -loop-reduce -S | FileCheck %s
 
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128-ni:1"
 
+; CHECK-LABEL: @foo(
 define void @foo() {
 bb:
   br label %bb4
-
+; CHECK: bb1:
+; CHECK: %tmp3 = ashr i64 %lsr.iv.next, 32
 bb1:                                              ; preds = %bb13
   %tmp = shl i64 %tmp14, 32
   %tmp2 = add i64 %tmp, 1
   %tmp3 = ashr i64 %tmp2, 32
   ret void
-
+; CHECK bb4:
 bb4:                                              ; preds = %bb13, %bb
   %tmp5 = phi i64 [ 2, %bb ], [ %tmp14, %bb13 ]
   %tmp6 = add i64 %tmp5, 4


        


More information about the llvm-commits mailing list