<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Trying to remove memory access that still has uses"
   href="https://bugs.llvm.org/show_bug.cgi?id=47557">47557</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Trying to remove memory access that still has uses
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>cszide@163.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=23973" name="attach_23973" title="small.bc">attachment 23973</a> <a href="attachment.cgi?id=23973&action=edit" title="small.bc">[details]</a></span>
small.bc

$clang -v
clang version 12.0.0 (<a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a>
65f6810d3a4b0ef1fdaad49e808459fbd133bb20)
Target: x86_64-unknown-linux-gnu
Thread model: posix

$clang -O3 -c -emit-llvm -femit-all-decls -mllvm -disable-llvm-optzns small.c

$opt -simplifycfg -instcombine -early-cse-memssa -loop-unroll -loop-unswitch
-loop-reduce -loop-simplifycfg  small.bc -o small-opt.bc
opt:
/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/llvm/lib/Analysis/MemorySSA.cpp:1832:
void llvm::MemorySSA::removeFromLookups(llvm::MemoryAccess*): Assertion
`MA->use_empty() && "Trying to remove memory access that still has uses"'
failed.
PLEASE submit a bug report to <a href="https://bugs.llvm.org/">https://bugs.llvm.org/</a> and include the crash
backtrace.
Stack dump:
0.      Program arguments:
/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt
-simplifycfg -instcombine -early-cse-memssa -loop-unroll -loop-unswitch
-loop-reduce -loop-simplifycfg small.bc -o small-opt.bc 
1.      Running pass 'Function Pass Manager' on module 'small.bc'.
2.      Running pass 'Loop Pass Manager' on function '@e'
3.      Running pass 'Simplify loop CFG' on basic block '%for.cond'
 #0 0x000055e6e068c99c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x2b9999c)
 #1 0x000055e6e068a714 llvm::sys::RunSignalHandlers()
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x2b97714)
 #2 0x000055e6e068a863 SignalHandler(int)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x2b97863)
 #3 0x00007fc8d302e8a0 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x128a0)
 #4 0x00007fc8d1ce0f47 raise
/build/glibc-2ORdQG/glibc-2.27/sysdeps/unix/sysv/linux/raise.c:51:0
 #5 0x00007fc8d1ce28b1 abort /build/glibc-2ORdQG/glibc-2.27/stdlib/abort.c:81:0
 #6 0x00007fc8d1cd242a __assert_fail_base
/build/glibc-2ORdQG/glibc-2.27/assert/assert.c:89:0
 #7 0x00007fc8d1cd24a2 (/lib/x86_64-linux-gnu/libc.so.6+0x304a2)
 #8 0x000055e6df769715
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x1c76715)
 #9 0x000055e6df77fd77
llvm::MemorySSAUpdater::removeBlocks(llvm::SmallSetVector<llvm::BasicBlock*,
8u> const&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x1c8cd77)
#10 0x000055e6e0464661 (anonymous
namespace)::ConstantTerminatorFoldingImpl::deleteDeadLoopBlocks()
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x2971661)
#11 0x000055e6e046685a constantFoldTerminators(llvm::Loop&,
llvm::DominatorTree&, llvm::LoopInfo&, llvm::ScalarEvolution&,
llvm::MemorySSAUpdater*, bool&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x297385a)
#12 0x000055e6e0467f47 (anonymous
namespace)::LoopSimplifyCFGLegacyPass::runOnLoop(llvm::Loop*,
llvm::LPPassManager&) (.part.254)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x2974f47)
#13 0x000055e6df742ae3 llvm::LPPassManager::runOnFunction(llvm::Function&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x1c4fae3)
#14 0x000055e6dfecdcc8 llvm::FPPassManager::runOnFunction(llvm::Function&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x23dacc8)
#15 0x000055e6dfece7c9 llvm::FPPassManager::runOnModule(llvm::Module&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x23db7c9)
#16 0x000055e6dfecd546 llvm::legacy::PassManagerImpl::run(llvm::Module&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x23da546)
#17 0x000055e6de3554c9 main
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x8624c9)
#18 0x00007fc8d1cc3b97 __libc_start_main
/build/glibc-2ORdQG/glibc-2.27/csu/libc-start.c:344:0
#19 0x000055e6de4047ca _start
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x9117ca)
Aborted (core dumped)

I also use bugpoint to reduce the testcase. The reduced optimization sequence
is "-loop-unswitch -loop-reduce -loop-simplifycfg".

$opt bugpoint-reduced-simplified.bc -loop-unswitch -loop-reduce
-loop-simplifycfg

opt:
/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/llvm/lib/Analysis/MemorySSA.cpp:1832:
void llvm::MemorySSA::removeFromLookups(llvm::MemoryAccess*): Assertion
`MA->use_empty() && "Trying to remove memory access that still has uses"'
failed.
PLEASE submit a bug report to <a href="https://bugs.llvm.org/">https://bugs.llvm.org/</a> and include the crash
backtrace.
Stack dump:
0.      Program arguments:
/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt
bugpoint-reduced-simplified.bc -loop-unswitch -loop-reduce -loop-simplifycfg 
1.      Running pass 'Function Pass Manager' on module
'bugpoint-reduced-simplified.bc'.
2.      Running pass 'Loop Pass Manager' on function '@e'
3.      Running pass 'Simplify loop CFG' on basic block '%for.cond'
 #0 0x00005569bb76799c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x2b9999c)
 #1 0x00005569bb765714 llvm::sys::RunSignalHandlers()
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x2b97714)
 #2 0x00005569bb765863 SignalHandler(int)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x2b97863)
 #3 0x00007f3a5f4d28a0 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x128a0)
 #4 0x00007f3a5e184f47 raise
/build/glibc-2ORdQG/glibc-2.27/sysdeps/unix/sysv/linux/raise.c:51:0
 #5 0x00007f3a5e1868b1 abort /build/glibc-2ORdQG/glibc-2.27/stdlib/abort.c:81:0
 #6 0x00007f3a5e17642a __assert_fail_base
/build/glibc-2ORdQG/glibc-2.27/assert/assert.c:89:0
 #7 0x00007f3a5e1764a2 (/lib/x86_64-linux-gnu/libc.so.6+0x304a2)
 #8 0x00005569ba844715
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x1c76715)
 #9 0x00005569ba85ad77
llvm::MemorySSAUpdater::removeBlocks(llvm::SmallSetVector<llvm::BasicBlock*,
8u> const&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x1c8cd77)
#10 0x00005569bb53f661 (anonymous
namespace)::ConstantTerminatorFoldingImpl::deleteDeadLoopBlocks()
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x2971661)
#11 0x00005569bb54185a constantFoldTerminators(llvm::Loop&,
llvm::DominatorTree&, llvm::LoopInfo&, llvm::ScalarEvolution&,
llvm::MemorySSAUpdater*, bool&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x297385a)
#12 0x00005569bb542f47 (anonymous
namespace)::LoopSimplifyCFGLegacyPass::runOnLoop(llvm::Loop*,
llvm::LPPassManager&) (.part.254)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x2974f47)
#13 0x00005569ba81dae3 llvm::LPPassManager::runOnFunction(llvm::Function&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x1c4fae3)
#14 0x00005569bafa8cc8 llvm::FPPassManager::runOnFunction(llvm::Function&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x23dacc8)
#15 0x00005569bafa97c9 llvm::FPPassManager::runOnModule(llvm::Module&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x23db7c9)
#16 0x00005569bafa8546 llvm::legacy::PassManagerImpl::run(llvm::Module&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x23da546)
#17 0x00005569b94304c9 main
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x8624c9)
#18 0x00007f3a5e167b97 __libc_start_main
/build/glibc-2ORdQG/glibc-2.27/csu/libc-start.c:344:0
#19 0x00005569b94df7ca _start
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x9117ca)
Aborted (core dumped)

---small.c-------
int a, b;
int c[];
long d;
void e() {
f:
  d = 0;
  for (;; d++) {
    int g = 0;
    for (; g <= 1; g++) {
      a = 0;
      for (; a;)
        c[d] = 0;
      if (b)
        goto f;
    }
  }
}
void main() {}</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>