[PATCH] D104702: [LSR] Filter out zero factors. PR50765

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 22 04:39:21 PDT 2021


mkazantsev created this revision.
mkazantsev added reviewers: lebedev.ri, SjoerdMeijer, huihuiz, fhahn.
Herald added a subscriber: hiraditya.
mkazantsev requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Zero factor leads to division by zero and failure of corresponding
assert as shown in PR50765. We should filter out such factors.


https://reviews.llvm.org/D104702

Files:
  llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
  llvm/test/Transforms/LoopStrengthReduce/pr50765.ll


Index: llvm/test/Transforms/LoopStrengthReduce/pr50765.ll
===================================================================
--- llvm/test/Transforms/LoopStrengthReduce/pr50765.ll
+++ llvm/test/Transforms/LoopStrengthReduce/pr50765.ll
@@ -1,6 +1,4 @@
 ; RUN: opt -S -loop-reduce < %s | FileCheck %s
-; XFAIL: *
-; REQUIRES: asserts
 ;
 ;This test produces zero factor that becomes a denumerator and fails an assetion.
 
Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -2712,13 +2712,13 @@
       if (const SCEVConstant *Factor =
             dyn_cast_or_null<SCEVConstant>(getExactSDiv(NewStride, OldStride,
                                                         SE, true))) {
-        if (Factor->getAPInt().getMinSignedBits() <= 64)
+        if (Factor->getAPInt().getMinSignedBits() <= 64 && !Factor->isZero())
           Factors.insert(Factor->getAPInt().getSExtValue());
       } else if (const SCEVConstant *Factor =
                    dyn_cast_or_null<SCEVConstant>(getExactSDiv(OldStride,
                                                                NewStride,
                                                                SE, true))) {
-        if (Factor->getAPInt().getMinSignedBits() <= 64)
+        if (Factor->getAPInt().getMinSignedBits() <= 64 && !Factor->isZero())
           Factors.insert(Factor->getAPInt().getSExtValue());
       }
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104702.353607.patch
Type: text/x-patch
Size: 1557 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210622/5c2028d1/attachment.bin>


More information about the llvm-commits mailing list