[LSR] Filter out zero factors. PR50765
authorMax Kazantsev <mkazantsev@azul.com>
Wed, 23 Jun 2021 03:43:06 +0000 (10:43 +0700)
committerMax Kazantsev <mkazantsev@azul.com>
Wed, 23 Jun 2021 03:43:06 +0000 (10:43 +0700)
Zero factor leads to division by zero and failure of corresponding
assert as shown in PR50765. We should filter out such factors.

Differential Revision: https://reviews.llvm.org/D104702
Reviewed By: huihuiz, reames

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

index a4cbcd4..5d2d967 100644 (file)
@@ -2712,13 +2712,13 @@ void LSRInstance::CollectInterestingTypesAndFactors() {
       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());
       }
     }
index 0f29683..8ebb0ca 100644 (file)
@@ -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.