<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/55100>55100</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            opt crashing with ScalarEvolutionExpander.cpp:2772: void llvm::SCEVExpanderCleaner::cleanup(): Assertion [...] "removed instruction should only be used by instructions inserted during expansion"' failed
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          mikaelholmen
      </td>
    </tr>
</table>

<pre>
    llvm commit: 34e2df21fdb
Reproduce with:
`opt -passes='loop-vectorize<interleave-forced-only;no-vectorize-forced-only>' -o /dev/null bbi-69005.ll`

Result:
opt: ../lib/Transforms/Utils/ScalarEvolutionExpander.cpp:2772: void llvm::SCEVExpanderCleaner::cleanup(): Assertion `all_of(I->users(), [&InsertedSet](Value *U) { return InsertedSet.contains(cast<Instruction>(U)); }) && "removed instruction should only be used by instructions inserted " "during expansion"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: build-all/bin/opt -passes=loop-vectorize<interleave-forced-only;no-vectorize-forced-only> -o /dev/null /home/uabelho/bbi-69005.ll
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
build-all/bin/opt(_ZN4llvm3sys15PrintStackTraceERNS_11raw_ostreamEi+0x23)[0x2cb69f3]
build-all/bin/opt(_ZN4llvm3sys17RunSignalHandlersEv+0xee)[0x2cb466e]
build-all/bin/opt[0x2cb6d76]
/lib64/libpthread.so.0(+0xf630)[0x7ff3868ea630]
/lib64/libc.so.6(gsignal+0x37)[0x7ff384031387]
/lib64/libc.so.6(abort+0x148)[0x7ff384032a78]
/lib64/libc.so.6(+0x2f1a6)[0x7ff38402a1a6]
/lib64/libc.so.6(+0x2f252)[0x7ff38402a252]
build-all/bin/opt[0x2dda146]
build-all/bin/opt[0x2eb4de3]
build-all/bin/opt(_ZN4llvm17LoopVectorizePass11processLoopEPNS_4LoopE+0x6323)[0x2eb40a3]
build-all/bin/opt(_ZN4llvm17LoopVectorizePass7runImplERNS_8FunctionERNS_15ScalarEvolutionERNS_8LoopInfoERNS_19TargetTransformInfoERNS_13DominatorTreeERNS_18BlockFrequencyInfoEPNS_17TargetLibraryInfoERNS_12DemandedBitsERNS_9AAResultsERNS_15AssumptionCacheERSt8functionIFRKNS_14LoopAccessInfoERNS_4LoopEEERNS_25OptimizationRemarkEmitterEPNS_18ProfileSummaryInfoE+0x1d2)[0x2eb5742]
build-all/bin/opt(_ZN4llvm17LoopVectorizePass3runERNS_8FunctionERNS_15AnalysisManagerIS1_JEEE+0x678)[0x2eb6208]
build-all/bin/opt[0x2ff5a1d]
build-all/bin/opt(_ZN4llvm11PassManagerINS_8FunctionENS_15AnalysisManagerIS1_JEEEJEE3runERS1_RS3_+0x205)[0x2460b45]
build-all/bin/opt[0xb0281d]
build-all/bin/opt(_ZN4llvm27ModuleToFunctionPassAdaptor3runERNS_6ModuleERNS_15AnalysisManagerIS1_JEEE+0x29a)[0x2464f4a]
build-all/bin/opt[0xb025fd]
build-all/bin/opt(_ZN4llvm11PassManagerINS_6ModuleENS_15AnalysisManagerIS1_JEEEJEE3runERS1_RS3_+0x208)[0x245fcd8]
build-all/bin/opt(_ZN4llvm15runPassPipelineENS_9StringRefERNS_6ModuleEPNS_13TargetMachineEPNS_21TargetLibraryInfoImplEPNS_14ToolOutputFileES8_S8_S0_NS_8ArrayRefIS0_EENS9_INS_10PassPluginEEENS_8opt_tool10OutputKindENSD_12VerifierKindEbbbbb+0x3f9f)[0x78686f]
build-all/bin/opt(main+0x3fad)[0x7975bd]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7ff38401d555]
build-all/bin/opt[0x7811b0]
Abort

This starts happening with 138fcc5f76:
 IRBuilder] Migrate icmp-folding to value-based FoldICmp.

 Depends on D116935.

 Reviewed By: nikic, lebedev.ri

 Differential Revision: https://reviews.llvm.org/D116969
[bbi-69005.ll.gz](https://github.com/llvm/llvm-project/files/8562404/bbi-69005.ll.gz)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9WN1y4jgTfRpyo4Ky5V8uuIBAatlNdlKQSdW3N5RsyaCNbHklmVnm6b9uGQjJTE3Yn9oUYEvqPn3U6pZaKTQ_TJTa16TUdS3dIJqSKBaUVzSseDEI5oNguhKt0bwrBfki3Q5E-u5BGujWkWHLrBV2EM0HNFNat8O9KJ028qsYRLeyccIowfZiWGlTCj7UjToMolmjX-XeDi0Ahww1GdA7Lvbw23RKkaKQw3QcBMlIKbB8pHDkZzvlzryAFE5jNAJVJQv4fTKssWCjttD47KTC57pkipnFXqvOSd0s_mxZw4UZlW0L6jTLKKLsteQEHYTw0XR9u3g-Sd7CtBph-oESG107oPmAjlFxCk4xCEyALVNqoysYXA5hfh2M2KMkvSWDZDag6bJBecHXwg0ScGX-zFQnwAnTzyBHBtmMGOE605ALyVGpG8dkg2glszDvWxh1pivRsndl_tmbAU4zAJl7LJrCBx7UiFrvBSfyVYnYne4UJ7gWpBAEyHJSHC5FLDY8BcTAL--MbLZEoGcsWqYUF7FiUgk-6pfl8X4xXS-I7QqIM8JI0W1hRq02jjhNds61Fl1J7-CzhTjrCphdjWuI3u8fQwjE3yFqoCmt7QSuI4HFAEKl6rggbidIaZjdkYKVL86wUhzNrx10EN7V7TlQAhgaPxq9NawmzGy7WjQOSQA3qfgQVg3wCwnTuXsb6f9KmH8b4_Dc6VrAo2OFUDuN5i_j_t1MfD7qzhF7qAutSMNqYQElF43tjCAH3ZEdcPIBPOyFgIcBd-GYIY_Tp5-INsQK510nmr00ukE_kD0zGLr3988Pm_X_Hmaf7pe_LVYbVIFuXLNWw7TxBfYNH_Q9v-86D0htfvs1RiKRPdgweYSIcX4qT7hKi9Wv600YGvZloyHQBKsXckBnwZ80Qu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