[llvm-bugs] [Bug 49566] New: LoopFusion is querying SCEV while manipulating loops

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Mar 12 14:09:43 PST 2021


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

            Bug ID: 49566
           Summary: LoopFusion is querying SCEV while manipulating loops
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: listmail at philipreames.com
                CC: llvm-bugs at lists.llvm.org

Ran across this while working on a SCEV patch.  Specifically, D98222, but
that's not terrible relevant.

The key point is that SCEV is analyzing IR, has identified a loop from the IR
structure, and yet the LoopInfo for that same IR is stale.  

Ignore most of the details of how we got there, and focus on the loop info
listed for the IR below.  The key point is that we're claiming two loops
(neither of which are loops), when the actually IR contains one.  This is
wrong.




FAIL: LLVM :: Transforms/LoopFusion/simple.ll (37038 of 42866)
******************** TEST 'LLVM :: Transforms/LoopFusion/simple.ll' FAILED
********************
Script:
--
: 'RUN: at line 2';   /home/ubuntu/llvm-repo/build/bin/opt -S -loop-simplify
-loop-fusion <
/home/ubuntu/llvm-repo/llvm-project/llvm/test/Transforms/LoopFusion/simple.ll |
/home/ubuntu/llvm-repo/build/bin/FileCheck
/home/ubuntu/llvm-repo/llvm-project/llvm/test/Transforms/LoopFusion/simple.ll
--
Exit Code: 2

Command Output (stderr):
--
define void @flow_dep(i32* noalias %A, i32* noalias %B) {
entry:
  br label %for.first

for.first:                                        ; preds = %for.second.latch,
%entry
  %i.first = phi i64 [ 0, %entry ], [ %inc.first, %for.second.latch ]
  %i.second = phi i64 [ %inc.second, %for.second.latch ], [ 0, %entry ]
  %Ai.first = getelementptr inbounds i32, i32* %A, i64 %i.first
  store i32 0, i32* %Ai.first, align 4
  br label %for.second

for.second:                                       ; preds = %for.first
  %Ai.second = getelementptr inbounds i32, i32* %A, i64 %i.second
  %0 = load i32, i32* %Ai.second, align 4
  %Bi = getelementptr inbounds i32, i32* %B, i64 %i.second
  store i32 %0, i32* %Bi, align 4
  br label %for.second.latch

for.second.latch:                                 ; preds = %for.second
  %inc.first = add nsw i64 %i.first, 1
  %cmp.first = icmp slt i64 %inc.first, 100
  %inc.second = add nsw i64 %i.second, 1
  %cmp.second = icmp slt i64 %inc.second, 100
  br i1 %cmp.second, label %for.first, label %for.end

for.end:                                          ; preds = %for.second.latch
  ret void
}

Loop at depth 1 containing: %for.first<header><exiting>
  %i.first = phi i64 [ 0, %entry ], [ %inc.first, %for.second.latch ]
  %inc.first = add nsw i64 %i.first, 1
Loop at depth 1 containing: %for.second<header>,%for.second.latch<exiting>
opt:
/home/ubuntu/llvm-repo/llvm-project/llvm/lib/Analysis/ScalarEvolution.cpp:5680:
llvm::ConstantRange llvm::ScalarEvolution::getRangeForUnknownRecurrence(const
llvm::SCEVUnknown*): Assertion `L->getHeader() == P->getParent() &&
L->contains(BO->getParent())' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash
backtrace.
Stack dump:
0.      Program arguments: /home/ubuntu/llvm-repo/build/bin/opt -S
-loop-simplify -loop-fusion
 #0 0x000055f016075f91 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
(/home/ubuntu/llvm-repo/build/bin/opt+0x1b58f91)
 #1 0x000055f016073c44 llvm::sys::RunSignalHandlers()
(/home/ubuntu/llvm-repo/build/bin/opt+0x1b56c44)
 #2 0x000055f016073dbb SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f732d0ed3c0 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
 #4 0x00007f732cba918b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4618b)
 #5 0x00007f732cb88859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x25859)
 #6 0x00007f732cb88729 (/lib/x86_64-linux-gnu/libc.so.6+0x25729)
 #7 0x00007f732cb99f36 (/lib/x86_64-linux-gnu/libc.so.6+0x36f36)
 #8 0x000055f014f987ad
llvm::ScalarEvolution::getRangeForUnknownRecurrence(llvm::SCEVUnknown const*)
(/home/ubuntu/llvm-repo/build/bin/opt+0xa7b7ad)
 #9 0x000055f014f9bca3 llvm::ScalarEvolution::getRangeRef(llvm::SCEV const*,
llvm::ScalarEvolution::RangeSignHint)
(/home/ubuntu/llvm-repo/build/bin/opt+0xa7eca3)
#10 0x000055f014f9cfd4 llvm::ScalarEvolution::isKnownNonNegative(llvm::SCEV
const*) (/home/ubuntu/llvm-repo/build/bin/opt+0xa7ffd4)
#11 0x000055f014f9d8b9 StrengthenNoWrapFlags(llvm::ScalarEvolution*,
llvm::SCEVTypes, llvm::ArrayRef<llvm::SCEV const*>, llvm::SCEV::NoWrapFlags)
ScalarEvolution.cpp:0:0
#12 0x000055f014fa0b28
llvm::ScalarEvolution::getMulExpr(llvm::SmallVectorImpl<llvm::SCEV const*>&,
llvm::SCEV::NoWrapFlags, unsigned int)
(/home/ubuntu/llvm-repo/build/bin/opt+0xa83b28)
#13 0x000055f014fb1344 llvm::ScalarEvolution::getGEPExpr(llvm::GEPOperator*,
llvm::SmallVectorImpl<llvm::SCEV const*> const&)
(/home/ubuntu/llvm-repo/build/bin/opt+0xa94344)
#14 0x000055f014fb1766
llvm::ScalarEvolution::createNodeForGEP(llvm::GEPOperator*)
(/home/ubuntu/llvm-repo/build/bin/opt+0xa94766)
#15 0x000055f014f99f24 llvm::ScalarEvolution::createSCEV(llvm::Value*)
(.part.0) ScalarEvolution.cpp:0:0
#16 0x000055f014f9a8fd llvm::ScalarEvolution::getSCEV(llvm::Value*)
(/home/ubuntu/llvm-repo/build/bin/opt+0xa7d8fd)
#17 0x000055f014e3f258 llvm::DependenceInfo::depends(llvm::Instruction*,
llvm::Instruction*, bool) (/home/ubuntu/llvm-repo/build/bin/opt+0x922258)
#18 0x000055f0160e6252 llvm::isSafeToMoveBefore(llvm::Instruction&,
llvm::Instruction&, llvm::DominatorTree&, llvm::PostDominatorTree const*,
llvm::DependenceInfo*) (/home/ubuntu/llvm-repo/build/bin/opt+0x1bc9252)
#19 0x000055f0160e6d5b llvm::moveInstructionsToTheBeginning(llvm::BasicBlock&,
llvm::BasicBlock&, llvm::DominatorTree&, llvm::PostDominatorTree const&,
llvm::DependenceInfo&) (/home/ubuntu/llvm-repo/build/bin/opt+0x1bc9d5b)
#20 0x000055f015f71aa2 (anonymous
namespace)::LoopFuser::performFusion((anonymous namespace)::FusionCandidate
const&, (anonymous namespace)::FusionCandidate const&) LoopFuse.cpp:0:0
#21 0x000055f015f748c5 (anonymous namespace)::LoopFuser::fuseCandidates()
LoopFuse.cpp:0:0
#22 0x000055f015f75fd3 (anonymous
namespace)::LoopFuser::fuseLoops(llvm::Function&) LoopFuse.cpp:0:0
#23 0x000055f015f7711a llvm::LoopFusePass::run(llvm::Function&,
llvm::AnalysisManager<llvm::Function>&)
(/home/ubuntu/llvm-repo/build/bin/opt+0x1a5a11a)
#24 0x000055f016319456 llvm::detail::PassModel<llvm::Function,
llvm::LoopFusePass, llvm::PreservedAnalyses,
llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&,
llvm::AnalysisManager<llvm::Function>&)
(/home/ubuntu/llvm-repo/build/bin/opt+0x1dfc456)
#25 0x000055f0157b0456 llvm::PassManager<llvm::Function,
llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&,
llvm::AnalysisManager<llvm::Function>&)
(/home/ubuntu/llvm-repo/build/bin/opt+0x1293456)
#26 0x000055f0163150c6 llvm::detail::PassModel<llvm::Function,
llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >,
llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>
>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&)
(/home/ubuntu/llvm-repo/build/bin/opt+0x1df80c6)
#27 0x000055f0157aef69 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&,
llvm::AnalysisManager<llvm::Module>&)
(/home/ubuntu/llvm-repo/build/bin/opt+0x1291f69)
#28 0x000055f0149fdee6 llvm::detail::PassModel<llvm::Module,
llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses,
llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&,
llvm::AnalysisManager<llvm::Module>&)
(/home/ubuntu/llvm-repo/build/bin/opt+0x4e0ee6)
#29 0x000055f0157ac9af llvm::PassManager<llvm::Module,
llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&,
llvm::AnalysisManager<llvm::Module>&)
(/home/ubuntu/llvm-repo/build/bin/opt+0x128f9af)
#30 0x000055f014a08528 llvm::runPassPipeline(llvm::StringRef, llvm::Module&,
llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*,
llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef,
llvm::ArrayRef<llvm::StringRef>, llvm::opt_tool::OutputKind,
llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool)
(/home/ubuntu/llvm-repo/build/bin/opt+0x4eb528)
#31 0x000055f014982327 main (/home/ubuntu/llvm-repo/build/bin/opt+0x465327)
#32 0x00007f732cb8a0b3 __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x270b3)
#33 0x000055f0149fbd3e _start (/home/ubuntu/llvm-repo/build/bin/opt+0x4ded3e)
FileCheck error: '<stdin>' is empty.
FileCheck command line:  /home/ubuntu/llvm-repo/build/bin/FileCheck
/home/ubuntu/llvm-repo/llvm-project/llvm/test/Transforms/LoopFusion/simple.ll

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
********************
Failed Tests (1):
  LLVM :: Transforms/LoopFusion/simple.ll


Testing Time: 46.57s
  Unsupported      : 18846
  Passed           : 23960
  Expectedly Failed:    59
  Failed           :     1

-- 
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/20210312/94ee12c3/attachment-0001.html>


More information about the llvm-bugs mailing list