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

Danila Malyutin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 17 06:22:14 PDT 2021


danilaml updated this revision to Diff 373204.
danilaml added a comment.

Addressed Quentin's comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108772/new/

https://reviews.llvm.org/D108772

Files:
  llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
  llvm/test/Transforms/LoopStrengthReduce/pr42770.ll
  llvm/test/Transforms/LoopStrengthReduce/scaling-factor-incompat-type.ll


Index: llvm/test/Transforms/LoopStrengthReduce/scaling-factor-incompat-type.ll
===================================================================
--- llvm/test/Transforms/LoopStrengthReduce/scaling-factor-incompat-type.ll
+++ llvm/test/Transforms/LoopStrengthReduce/scaling-factor-incompat-type.ll
@@ -1,20 +1,21 @@
-; Check that it doesn't crash
+; Check that it doesn't crash, 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
Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -3934,6 +3934,9 @@
 
   // 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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108772.373204.patch
Type: text/x-patch
Size: 1647 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210917/1c649ec5/attachment.bin>


More information about the llvm-commits mailing list