<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 --- - InstCombine: Calls RAUW on GEPi replacing value with itself"
   href="https://llvm.org/bugs/show_bug.cgi?id=30402">30402</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>InstCombine: Calls RAUW on GEPi replacing value with itself
          </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>Transformation Utilities
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>simonas+llvm.org@kazlauskas.me
          </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>Created <span class=""><a href="attachment.cgi?id=17270" name="attach_17270" title="The IR which causes abort in instcombine with opt -O3">attachment 17270</a> <a href="attachment.cgi?id=17270&action=edit" title="The IR which causes abort in instcombine with opt -O3">[details]</a></span>
The IR which causes abort in instcombine with opt -O3

Attached IR causes `opt -O3`/`opt -O2` assert with 

opt: ../lib/IR/Value.cpp:373: void llvm::Value::replaceAllUsesWith(llvm::Value
*): Assertion `!contains(New, this) && "this->replaceAllUsesWith(expr(this)) is
NOT valid!"' failed.

This IR has been minimised IR rustc output and works just fine with LLVM 3.8
(both opt and through rustc), but fails with LLVM 3.9 or trunk (both opt and
rustc).

A short debugger session quickly shows the cause:

(gdb) bt
#0  0x00007ffff4d7304f in raise () from /usr/lib/libc.so.6
#1  0x00007ffff4d7447a in abort () from /usr/lib/libc.so.6
#2  0x00007ffff4d6bea7 in __assert_fail_base () from /usr/lib/libc.so.6
#3  0x00007ffff4d6bf52 in __assert_fail () from /usr/lib/libc.so.6
#4  0x00007ffff60ee54e in llvm::Value::replaceAllUsesWith (this=0x6851a0,
New=0x6851a0) at ../lib/IR/Value.cpp:372
#5  0x00007ffff681818b in rewriteGEPAsOffset (Start=<optimized out>,
Base=<optimized out>, DL=..., Explored=...) at
../lib/Transforms/InstCombine/InstCombineCompares.cpp:839
#6  transformToIndexedCompare (GEPLHS=<optimized out>, RHS=<optimized out>,
Cond=<optimized out>, DL=...) at
../lib/Transforms/InstCombine/InstCombineCompares.cpp:911
#7  0x00007ffff682bcc0 in llvm::InstCombiner::visitICmpInst (this=<optimized
out>, I=...) at ../lib/Transforms/InstCombine/InstCombineCompares.cpp:3732
#8  0x00007ffff67ca6db in llvm::InstCombiner::run (this=<optimized out>) at
../lib/Transforms/InstCombine/InstructionCombining.cpp:2912
#9  0x00007ffff67cc001 in combineInstructionsOverFunction (F=..., Worklist=...,
AA=<optimized out>, AC=..., TLI=..., DT=..., ExpensiveCombines=<optimized out>,
LI=<optimized out>)
    at ../lib/Transforms/InstCombine/InstructionCombining.cpp:3141
#10 0x00007ffff67cc5ea in llvm::InstructionCombiningPass::runOnFunction
(this=<optimized out>, F=...) at
../lib/Transforms/InstCombine/InstructionCombining.cpp:3197
#11 0x00007ffff60b3d14 in llvm::FPPassManager::runOnFunction (this=<optimized
out>, F=...) at ../lib/IR/LegacyPassManager.cpp:1526
#12 0x00007ffff60b3f5b in llvm::FPPassManager::runOnModule (this=<optimized
out>, M=...) at ../lib/IR/LegacyPassManager.cpp:1547
#13 0x00007ffff60b434a in (anonymous namespace)::MPPassManager::runOnModule
(this=<optimized out>, M=...) at ../lib/IR/LegacyPassManager.cpp:1603
#14 llvm::legacy::PassManagerImpl::run (this=<optimized out>, M=...) at
../lib/IR/LegacyPassManager.cpp:1706
#15 0x0000000000422f2a in main (argc=<optimized out>, argv=<optimized out>) at
../tools/opt/opt.cpp:679
(gdb) frame 4
#4  0x00007ffff60ee54e in llvm::Value::replaceAllUsesWith (this=0x6851a0,
New=0x6851a0) at ../lib/IR/Value.cpp:372
372      assert(!contains(New, this) &&
(gdb) call this->dump()
i64* getelementptr inbounds (i64, i64* @ref8151, i64 1)
(gdb) call New->dump()
i64* getelementptr inbounds (i64, i64* @ref8151, i64 1)

That is, RAUW is called with the same `this` and `New` ValueRef, which, to the
best of my knowledge, is invalid.</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>