[llvm-bugs] [Bug 49538] New: Assertion failure "This cannot be done on broken IR!" when running -loop-vectorize with -scev-verify-ir

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Mar 11 06:29:32 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=49538

            Bug ID: 49538
           Summary: Assertion failure "This cannot be done on broken IR!"
                    when running -loop-vectorize with -scev-verify-ir
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: bjorn.a.pettersson at ericsson.com
                CC: llvm-bugs at lists.llvm.org

This test case

;-------------------------------------------------------------
; RUN: opt < %s -loop-vectorize -scev-verify-ir

define void @test_nested4() {
entry:
  br label %bb1

bb1:                                              ; preds = %bb3, %entry
  %i = phi i16 [ %i9, %bb3 ], [ -1, %entry ]
  br label %bb2

bb2:                                              ; preds = %bb2, %bb1
  %i3 = phi i16 [ %i5, %bb2 ], [ -1, %bb1 ]
  %i4 = mul i17 undef, undef
  %i5 = add nsw i16 %i3, 1
  %i6 = icmp eq i16 %i5, %i
  br i1 %i6, label %bb3, label %bb2

bb3:                                              ; preds = %bb2
  %i8 = phi i16 [ undef, %bb2 ]
  %i9 = add nsw i16 %i, 1
  %i10 = icmp eq i16 %i9, undef
  br i1 %i10, label %bb4, label %bb1

bb4:                                              ; preds = %bb3
  ret void
}

;-------------------------------------------------------------


fails like this

> build-all/bin/opt -S -loop-vectorize -scev-verify-ir lv-scev-verify-reduced.ll
PHINode should have one entry for each predecessor of its parent basic block!
  %i8 = phi i16 [ undef, %bb2 ]
opt: ../lib/Analysis/ScalarEvolution.cpp:9855: bool
llvm::ScalarEvolution::isLoopBackedgeGuardedByCond(const llvm::Loop *,
ICmpInst::Predicate, const llvm::SCEV *, const llvm::SCEV *): Assertion
`!verifyFunction(*L->getHeader()->getParent(), &dbgs()) && "This cannot be done
on broken IR!"' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash
backtrace.
Stack dump:
0.      Program arguments: build-all/bin/opt -S -loop-vectorize -scev-verify-ir
lv-scev-verify-reduced.ll
1.      Running pass 'Function Pass Manager' on module
'lv-scev-verify-reduced.ll'.
2.      Running pass 'Loop Vectorization' on function '@test_nested4'
 #0 0x00000000028fcea3 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
(build-all/bin/opt+0x28fcea3)
 #1 0x00000000028fabfe llvm::sys::RunSignalHandlers()
(build-all/bin/opt+0x28fabfe)
 #2 0x00000000028fd35c SignalHandler(int) (build-all/bin/opt+0x28fd35c)
 #3 0x00007f0631fad630 __restore_rt (/lib64/libpthread.so.0+0xf630)
 #4 0x00007f062f6e0387 raise (/lib64/libc.so.6+0x36387)
 #5 0x00007f062f6e1a78 abort (/lib64/libc.so.6+0x37a78)
 #6 0x00007f062f6d91a6 __assert_fail_base (/lib64/libc.so.6+0x2f1a6)
 #7 0x00007f062f6d9252 (/lib64/libc.so.6+0x2f252)
 #8 0x0000000001a189d4
llvm::ScalarEvolution::isLoopBackedgeGuardedByCond(llvm::Loop const*,
llvm::CmpInst::Predicate, llvm::SCEV const*, llvm::SCEV const*)
(build-all/bin/opt+0x1a189d4)
 #9 0x0000000001a17fa0
llvm::ScalarEvolution::proveNoUnsignedWrapViaInduction(llvm::SCEVAddRecExpr
const*) (build-all/bin/opt+0x1a17fa0)
#10 0x0000000001a1461d llvm::ScalarEvolution::getZeroExtendExpr(llvm::SCEV
const*, llvm::Type*, unsigned int) (build-all/bin/opt+0x1a1461d)
#11 0x0000000002a74593
llvm::InnerLoopVectorizer::getOrCreateTripCount(llvm::Loop*)
(build-all/bin/opt+0x2a74593)
#12 0x0000000002a74e0c
llvm::InnerLoopVectorizer::emitMinimumIterationCountCheck(llvm::Loop*,
llvm::BasicBlock*) (build-all/bin/opt+0x2a74e0c)
#13 0x0000000002a77a00
llvm::InnerLoopVectorizer::createVectorizedLoopSkeleton()
(build-all/bin/opt+0x2a77a00)
#14 0x0000000002a96816
llvm::LoopVectorizationPlanner::executePlan(llvm::InnerLoopVectorizer&,
llvm::DominatorTree*) (build-all/bin/opt+0x2a96816)
#15 0x0000000002aa645b llvm::LoopVectorizePass::processLoop(llvm::Loop*)
(build-all/bin/opt+0x2aa645b)
#16 0x0000000002aa7862 llvm::LoopVectorizePass::runImpl(llvm::Function&,
llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::TargetTransformInfo&,
llvm::DominatorTree&, llvm::BlockFrequencyInfo&, llvm::TargetLibraryInfo*,
llvm::DemandedBits&, llvm::AAResults&, llvm::AssumptionCache&,
std::function<llvm::LoopAccessInfo const& (llvm::Loop&)>&,
llvm::OptimizationRemarkEmitter&, llvm::ProfileSummaryInfo*)
(build-all/bin/opt+0x2aa7862)
#17 0x0000000002aae598 (anonymous
namespace)::LoopVectorize::runOnFunction(llvm::Function&)
(build-all/bin/opt+0x2aae598)
Abort (core dumped)


It starts to happen after this commit:

 commit 0ea3749b3cde16d70c5f66357b623c8edf521f2b (HEAD)
 Author: Florian Hahn <flo at fhahn.com>
 Date:   Sun Dec 27 15:13:09 2020 +0000

    [LV] Set up branch from middle block earlier.

    Previously the branch from the middle block to the scalar preheader & exit
    was being set-up at the end of skeleton creation in completeLoopSkeleton.
    Inserting SCEV or runtime checks may result in LCSSA phis being created,
    if they are required. Adjusting branches afterwards may break those
    PHIs.

    To avoid this, we can instead create the branch from the middle block
    to the exit after we created the middle block, so we have the final CFG
    before potentially adjusting/creating PHIs.

    This fixes a crash for the included test case. For the non-crashing
    case, this is almost a NFC with respect to the generated code. The
    only change is the order of the predecessors of the involved branch
    targets.

    Note an assertion was moved from LoopVersioning() to
    LoopVersioning::versionLoop. Adjusting the branches means loop-simplify
    form may be broken before constructing LoopVersioning. But LV only uses
    LoopVersioning to annotate the loop instructions with !noalias metadata,
    which does not require loop-simplify form.

    This is a fix for an existing issue uncovered by D93317.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210311/4815ed3a/attachment.html>


More information about the llvm-bugs mailing list