[PATCH] D125990: [LSR] Fix bug for optimizing unused IVs to final values

Zaara Syeda via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 7 08:39:17 PDT 2022


syzaara added a comment.

In D125990#3633683 <https://reviews.llvm.org/D125990#3633683>, @nathanchance wrote:

> I bisected an assertion failure while building the Linux kernel for PowerPC to this patch:
>
>   # bad: [20962c1240691d25b21ce425313c81eed0b1b358] [SimplifyCFG] Don't split predecessors of callbr terminator
>   # good: [dc969061c68e62328607d68215ed8b9ef4a1e4b1] [SimplifyCFG] Thread all predecessors with same value at once
>   git bisect start '20962c1240691d25b21ce425313c81eed0b1b358' 'dc969061c68e62328607d68215ed8b9ef4a1e4b1'
>   # bad: [a6e63e35ede4b9f23b58437263eaac9a2926c9bf] [NFC][HLSL] Add tests for vector alias. Remove dead code.
>   git bisect bad a6e63e35ede4b9f23b58437263eaac9a2926c9bf
>   # good: [5493f8fc59ca9cc6fc14da8e6aafe6a52fb9ebc0] [VectorCombine] Improve shuffle select shuffle-of-shuffles
>   git bisect good 5493f8fc59ca9cc6fc14da8e6aafe6a52fb9ebc0
>   # bad: [b170d856a3a303ab826f6896812bfd0ce05ec706] [SimplifyCFG] Skip hoisting common instructions that return token type
>   git bisect bad b170d856a3a303ab826f6896812bfd0ce05ec706
>   # bad: [7b1ff859feaaf1316932d0be113d762626009fd6] [gn build] Port b8dbc6ffea93
>   git bisect bad 7b1ff859feaaf1316932d0be113d762626009fd6
>   # good: [a2158374ba1a6f81f4cce3eb54d0bc44f3ab75e0] [mlir][LLVMIR] Apply CallOp/CallableInterface on suitable operations
>   git bisect good a2158374ba1a6f81f4cce3eb54d0bc44f3ab75e0
>   # bad: [dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e] [LSR] Fix bug for optimizing unused IVs to final values
>   git bisect bad dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e
>   # good: [b8dbc6ffea93976dc0d8569c9d23e9c21e33e317] [HLSL] Add ExternalSemaSource & vector alias
>   git bisect good b8dbc6ffea93976dc0d8569c9d23e9c21e33e317
>   # first bad commit: [dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e] [LSR] Fix bug for optimizing unused IVs to final values
>
> A simplified C reproducer:
>
>   enum { true } typedef size_t;
>   struct kernfs_node {
>     struct kernfs_node *parent;
>   } kernfs_path_from_node_locked_kn_to;
>   size_t kernfs_path_from_node_locked___trans_tmp_1;
>   void kernfs_path_from_node() {
>     asm goto("" : : : : __label_warn_on);
>   __label_warn_on:;
>     struct kernfs_node *to = &kernfs_path_from_node_locked_kn_to;
>     size_t depth;
>     while (to) {
>       depth++;
>       to = to->parent;
>     }
>     kernfs_path_from_node_locked___trans_tmp_1 = depth;
>   }
>
>
>
>   $ clang --target=powerpc64-linux-gnu -O2 -c -o /dev/null dir.i
>   clang: /home/nathan/cbl/src/llvm-project/llvm/include/llvm/IR/Instructions.h:2838: llvm::Value *llvm::PHINode::getIncomingValueForBlock(const llvm::BasicBlock *) const: Assertion `Idx >= 0 && "Invalid basic block argument!"' failed.
>   PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
>   Stack dump:
>   0.      Program arguments: clang --target=powerpc64-linux-gnu -O2 -c -o /dev/null dir.i
>   1.      <eof> parser at end of file
>   2.      Code generation
>   3.      Running pass 'Function Pass Manager' on module 'dir.i'.
>   4.      Running pass 'Loop Pass Manager' on function '@kernfs_path_from_node'
>   5.      Running pass 'Loop Strength Reduction' on basic block '%while.body'
>    #0 0x000055926ab23473 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/nathan/tmp/install/llvm/dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e/bin/clang-15+0x3445473)
>    #1 0x000055926ab2140e llvm::sys::RunSignalHandlers() (/home/nathan/tmp/install/llvm/dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e/bin/clang-15+0x344340e)
>    #2 0x000055926aaa7893 (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) CrashRecoveryContext.cpp:0:0
>    #3 0x000055926aaa7a0e CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
>    #4 0x00007fbd976d8b90 __restore_rt (/lib64/libc.so.6+0x38b90)
>    #5 0x00007fbd97728c4c __pthread_kill_implementation (/lib64/libc.so.6+0x88c4c)
>    #6 0x00007fbd976d8ae6 gsignal (/lib64/libc.so.6+0x38ae6)
>    #7 0x00007fbd976c27f4 abort (/lib64/libc.so.6+0x227f4)
>    #8 0x00007fbd976c271b _nl_load_domain.cold (/lib64/libc.so.6+0x2271b)
>    #9 0x00007fbd976d1696 (/lib64/libc.so.6+0x31696)
>   #10 0x0000559269ca1c1d llvm::InductionDescriptor::isInductionPHI(llvm::PHINode*, llvm::Loop const*, llvm::ScalarEvolution*, llvm::InductionDescriptor&, llvm::SCEV const*, llvm::SmallVectorImpl<llvm::Instruction*>*) (/home/nathan/tmp/install/llvm/dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e/bin/clang-15+0x25c3c1d)
>   #11 0x000055926abe97dc llvm::rewriteLoopExitValues(llvm::Loop*, llvm::LoopInfo*, llvm::TargetLibraryInfo*, llvm::ScalarEvolution*, llvm::TargetTransformInfo const*, llvm::SCEVExpander&, llvm::DominatorTree*, llvm::ReplaceExitVal, llvm::SmallVector<llvm::WeakTrackingVH, 16u>&) (/home/nathan/tmp/install/llvm/dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e/bin/clang-15+0x350b7dc)
>   #12 0x000055926a96f3d8 ReduceLoopStrength(llvm::Loop*, llvm::IVUsers&, llvm::ScalarEvolution&, llvm::DominatorTree&, llvm::LoopInfo&, llvm::TargetTransformInfo const&, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::MemorySSA*) LoopStrengthReduce.cpp:0:0
>   #13 0x000055926a99d154 (anonymous namespace)::LoopStrengthReduce::runOnLoop(llvm::Loop*, llvm::LPPassManager&) LoopStrengthReduce.cpp:0:0
>   #14 0x0000559269efcaeb llvm::LPPassManager::runOnFunction(llvm::Function&) (/home/nathan/tmp/install/llvm/dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e/bin/clang-15+0x281eaeb)
>   #15 0x000055926a3a7197 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/nathan/tmp/install/llvm/dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e/bin/clang-15+0x2cc9197)
>   #16 0x000055926a3aec41 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/nathan/tmp/install/llvm/dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e/bin/clang-15+0x2cd0c41)
>   #17 0x000055926a3a7ba5 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/nathan/tmp/install/llvm/dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e/bin/clang-15+0x2cc9ba5)
>   #18 0x000055926b332f5d clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) (/home/nathan/tmp/install/llvm/dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e/bin/clang-15+0x3c54f5d)
>   #19 0x000055926b6eafde clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) CodeGenAction.cpp:0:0
>   #20 0x000055926bfbafc4 clang::ParseAST(clang::Sema&, bool, bool) (/home/nathan/tmp/install/llvm/dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e/bin/clang-15+0x48dcfc4)
>   #21 0x000055926b62d8f0 clang::FrontendAction::Execute() (/home/nathan/tmp/install/llvm/dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e/bin/clang-15+0x3f4f8f0)
>   #22 0x000055926b5a1f5f clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/nathan/tmp/install/llvm/dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e/bin/clang-15+0x3ec3f5f)
>   #23 0x000055926b6e4682 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/nathan/tmp/install/llvm/dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e/bin/clang-15+0x4006682)
>   #24 0x00005592696f6f4a cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/nathan/tmp/install/llvm/dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e/bin/clang-15+0x2018f4a)
>   #25 0x00005592696f4cdf ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
>   #26 0x000055926b423572 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::$_1>(long) Job.cpp:0:0
>   #27 0x000055926aaa77a7 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/nathan/tmp/install/llvm/dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e/bin/clang-15+0x33c97a7)
>   #28 0x000055926b4230cf clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/home/nathan/tmp/install/llvm/dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e/bin/clang-15+0x3d450cf)
>   #29 0x000055926b3e2dde clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/nathan/tmp/install/llvm/dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e/bin/clang-15+0x3d04dde)
>   #30 0x000055926b3e308e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/nathan/tmp/install/llvm/dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e/bin/clang-15+0x3d0508e)
>   #31 0x000055926b3ff030 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/nathan/tmp/install/llvm/dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e/bin/clang-15+0x3d21030)
>   #32 0x00005592696f43a1 clang_main(int, char**) (/home/nathan/tmp/install/llvm/dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e/bin/clang-15+0x20163a1)
>   #33 0x00007fbd976c3550 __libc_start_call_main (/lib64/libc.so.6+0x23550)
>   #34 0x00007fbd976c3609 __libc_start_main at GLIBC_2.2.5 (/lib64/libc.so.6+0x23609)
>   #35 0x00005592696f1945 _start /build/glibc/src/glibc/csu/../sysdeps/x86_64/start.S:117:0
>   clang-15: error: clang frontend command failed with exit code 134 (use -v to see invocation)
>   ClangBuiltLinux clang version 15.0.0 (https://github.com/llvm/llvm-project dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e)
>   Target: powerpc64-unknown-linux-gnu
>   Thread model: posix
>   InstalledDir: /home/nathan/tmp/install/llvm/dbf6ab5ef9ae0e1f4706917c2b3f98a67c35826e/bin
>   clang-15: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.
>
> At the parent commit, there is no crash.

Thank you for the reproducer! Posted fix in https://reviews.llvm.org/D129297


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125990



More information about the llvm-commits mailing list