<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - Unsupported memory instruction in sinking pass"
   href="https://llvm.org/bugs/show_bug.cgi?id=28570">28570</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Unsupported memory instruction in sinking pass
          </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>normal
          </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>yyc1992@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following reduced IR triggers a "unsupported memory instruction" assertion
when running with `opt -sink bug.ll` (backtrace below, segfault soon after with
assertion off).

```
; ModuleID = 'bug.ll'
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define void @f(i32* ()*) {
top:
  %1 = call i32* %0() #0
  fence singlethread seq_cst
  %2 = load i32, i32* %1, align 4
  fence singlethread seq_cst
  %3 = icmp eq i32 %2, 0
  br i1 %3, label %fail, label %pass

fail:                                             ; preds = %top
  br label %pass

pass:                                             ; preds = %fail, %top
  ret void
}

attributes #0 = { nounwind readnone }
```

This was introduced fairly recently. The "unsupported memory operation" was the
`fence singlethread seq_cst`. Bisected to

```
commit bd10da16fd5320ca47b0cf7edcd88d3eabd6d0fe
Author: Nicolai Haehnle <<a href="mailto:nhaehnle@gmail.com">nhaehnle@gmail.com</a>>
Date:   Mon Jul 11 14:11:51 2016 +0000

    [Sink] Don't move calls to readonly functions across stores

    Summary:  

    Reviewers: hfinkel, majnemer, tstellarAMD, sunfish

    Subscribers: llvm-commits

    Differential Revision: <a href="http://reviews.llvm.org/D17279">http://reviews.llvm.org/D17279</a>  

    git-svn-id: <a href="https://llvm.org/svn/llvm-project/llvm/trunk@275066">https://llvm.org/svn/llvm-project/llvm/trunk@275066</a>
91177308-0d34-0410-b5e6-96231b3b80d8  
```

which looks related (the `readnone` attribute on the function call is
important) but the real bug might be somewhere else....

```
#6 0x000000000106b6a0 LLVMInstallFatalErrorHandler
/home/yuyichao/projects/julia/tests/llvm/deps/srccache/llvm-svn/lib/Support/ErrorHandling.cpp:133:0 
#7 0x000000000078c8d3 llvm::PointerIntPairInfo<llvm::Instruction const*, 1u,
llvm::PointerLikeTypeTraits<llvm::Instruction const*> >::updatePointer(long,
llvm::Instruction const*)
/home/yuyichao/projects/julia/tests/llvm/deps/srccache/llvm-svn/include/llvm/ADT/PointerIntPair.h:159:0 
#8 0x000000000078c8d3 llvm::PointerIntPair<llvm::Instruction const*, 1u, bool,
llvm::PointerLikeTypeTraits<llvm::Instruction const*>,
llvm::PointerIntPairInfo<llvm::Instruction const*, 1u,
llvm::PointerLikeTypeTraits<llvm::Instruction const*> >
<span class="quote">>::setPointerAndInt(llvm::Instruction const*, bool)</span >
/home/yuyichao/projects/julia/tests/llvm/deps/srccache/llvm-svn/include/llvm/ADT/PointerIntPair.h:75:0 
#9 0x000000000078c8d3 llvm::PointerIntPair<llvm::Instruction const*, 1u, bool,
llvm::PointerLikeTypeTraits<llvm::Instruction const*>,
llvm::PointerIntPairInfo<llvm::Instruction const*, 1u,
llvm::PointerLikeTypeTraits<llvm::Instruction const*> >
<span class="quote">>::PointerIntPair(llvm::Instruction const*, bool)</span >
/home/yuyichao/projects/julia/tests/llvm/deps/srccache/llvm-svn/include/llvm/ADT/PointerIntPair.h:52:0 
#10 0x000000000078c8d3 llvm::CallSiteBase<llvm::Function const,
llvm::BasicBlock const, llvm::Value const, llvm::User const, llvm::Use const,
llvm::Instruction const, llvm::CallInst const, llvm::InvokeInst const,
llvm::Use const*>::CallSiteBase(llvm::CallInst const*)
/home/yuyichao/projects/julia/tests/llvm/deps/srccache/llvm-svn/include/llvm/IR/CallSite.h:54:0 
#11 0x000000000078c8d3 llvm::CallSiteBase<llvm::Function const,
llvm::BasicBlock const, llvm::Value const, llvm::User const, llvm::Use const,
llvm::Instruction const, llvm::CallInst const, llvm::InvokeInst const,
llvm::Use const*>::get(llvm::Value const*)
/home/yuyichao/projects/julia/tests/llvm/deps/srccache/llvm-svn/include/llvm/IR/CallSite.h:67:0 
#12 0x000000000078c8d3 llvm::CallSiteBase<llvm::Function const,
llvm::BasicBlock const, llvm::Value const, llvm::User const, llvm::Use const,
llvm::Instruction const, llvm::CallInst const, llvm::InvokeInst const,
llvm::Use const*>::CallSiteBase(llvm::Value const*)
/home/yuyichao/projects/julia/tests/llvm/deps/srccache/llvm-svn/include/llvm/IR/CallSite.h:56:0 
#13 0x000000000078c8d3
llvm::ImmutableCallSite::ImmutableCallSite(llvm::Instruction const*)
/home/yuyichao/projects/julia/tests/llvm/deps/srccache/llvm-svn/include/llvm/IR/CallSite.h:628:0
#14 0x000000000078c8d3 llvm::AAResults::getModRefInfo(llvm::Instruction*,
llvm::ImmutableCallSite)
/home/yuyichao/projects/julia/tests/llvm/deps/srccache/llvm-svn/lib/Analysis/AliasAnalysis.cpp:111:0
#15 0x000000000100aa19 isSafeToMove
/home/yuyichao/projects/julia/tests/llvm/deps/srccache/llvm-svn/lib/Transforms/Scalar/Sink.cpp:86:0 
#16 0x000000000100aa19 SinkInstruction
/home/yuyichao/projects/julia/tests/llvm/deps/srccache/llvm-svn/lib/Transforms/Scalar/Sink.cpp:150:0 
#17 0x000000000100aa19 ProcessBlock
/home/yuyichao/projects/julia/tests/llvm/deps/srccache/llvm-svn/lib/Transforms/Scalar/Sink.cpp:229:0 
#18 0x000000000100aa19 iterativelySinkInstructions(llvm::Function&,
llvm::DominatorTree&, llvm::LoopInfo&, llvm::AAResults&)
/home/yuyichao/projects/julia/tests/llvm/deps/srccache/llvm-svn/lib/Transforms/Scalar/Sink.cpp:249:0 
#19 0x0000000000ca6683 llvm::FPPassManager::runOnFunction(llvm::Function&)
/home/yuyichao/projects/julia/tests/llvm/deps/srccache/llvm-svn/lib/IR/LegacyPassManager.cpp:1526:0
#20 0x0000000000ca6a3b llvm::FPPassManager::runOnModule(llvm::Module&)
/home/yuyichao/projects/julia/tests/llvm/deps/srccache/llvm-svn/lib/IR/LegacyPassManager.cpp:1547:0 
#21 0x0000000000ca6d71 runOnModule
/home/yuyichao/projects/julia/tests/llvm/deps/srccache/llvm-svn/lib/IR/LegacyPassManager.cpp:1603:0
#22 0x0000000000ca6d71 llvm::legacy::PassManagerImpl::run(llvm::Module&)
/home/yuyichao/projects/julia/tests/llvm/deps/srccache/llvm-svn/lib/IR/LegacyPassManager.cpp:1706:0
#23 0x00000000005c3ca2 main
/home/yuyichao/projects/julia/tests/llvm/deps/srccache/llvm-svn/tools/opt/opt.cpp:674:0
#24 0x00007f9dbf60a741 __libc_start_main (/usr/lib/libc.so.6+0x20741)
#25 0x00000000005f5819 _start (usr/tools/opt+0x5f5819)
Stack dump:
0.      Program arguments: usr/tools/opt -sink bug.ll -o /dev/null 
1.      Running pass 'Function Pass Manager' on module 'bug.ll'.
2.      Running pass 'Code sinking' on function '@f'
```

x-ref <a href="https://github.com/JuliaLang/julia/issues/17427">https://github.com/JuliaLang/julia/issues/17427</a></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>