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

    <tr>
        <th>Summary</th>
        <td>
            opt -passes='require<ir-similarity>' crashes with Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    llvm commit: e1567e771b89

reproduce with:
opt -passes='require<ir-similarity>' -o /dev/null bbi-68950.ll

Result:
opt: ../include/llvm/Support/Casting.h:269: typename cast_retty<X, Y *>::ret_type llvm::cast(Y *) [X = llvm::Instruction, Y = llvm::Value]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' 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=require<ir-similarity> -o /dev/null /home/uabelho/bbi-68950.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)[0x2cb71b3]
build-all/bin/opt(_ZN4llvm3sys17RunSignalHandlersEv+0xee)[0x2cb4e2e]
build-all/bin/opt[0x2cb7536]
/lib64/libpthread.so.0(+0xf630)[0x7f0ae724c630]
/lib64/libc.so.6(gsignal+0x37)[0x7f0ae4993387]
/lib64/libc.so.6(abort+0x148)[0x7f0ae4994a78]
/lib64/libc.so.6(+0x2f1a6)[0x7f0ae498c1a6]
/lib64/libc.so.6(+0x2f252)[0x7f0ae498c252]
build-all/bin/opt(_ZN4llvm12IRSimilarity21IRSimilarityCandidate27createCanonicalRelationFromERS1_RNS_8DenseMapIjNS_8DenseSetIjNS_12DenseMapInfoIjvEEEES6_NS_6detail12DenseMapPairIjS7_EEEESC_+0x11e6)[0x1b85ed6]
build-all/bin/opt(_ZN4llvm12IRSimilarity22IRSimilarityIdentifier14findCandidatesERSt6vectorIPNS0_17IRInstructionDataESaIS4_EERS2_IjSaIjEE+0xa51)[0x1b86f31]
build-all/bin/opt(_ZN4llvm12IRSimilarity22IRSimilarityIdentifier14findSimilarityERNS_6ModuleE+0xec)[0x1b87dac]
build-all/bin/opt(_ZN4llvm20IRSimilarityAnalysis3runERNS_6ModuleERNS_15AnalysisManagerIS1_JEEE+0x181)[0x1b88381]
build-all/bin/opt[0x2fdcb40]
build-all/bin/opt(_ZN4llvm15AnalysisManagerINS_6ModuleEJEE13getResultImplEPNS_11AnalysisKeyERS1_+0x20e)[0x2462e9e]
build-all/bin/opt[0x2fe9a78]
build-all/bin/opt[0x2fe98bd]
build-all/bin/opt(_ZN4llvm11PassManagerINS_6ModuleENS_15AnalysisManagerIS1_JEEEJEE3runERS1_RS3_+0x208)[0x2460758]
build-all/bin/opt(_ZN4llvm15runPassPipelineENS_9StringRefERNS_6ModuleEPNS_13TargetMachineEPNS_21TargetLibraryInfoImplEPNS_14ToolOutputFileES8_S8_S0_NS_8ArrayRefIS0_EENS9_INS_10PassPluginEEENS_8opt_tool10OutputKindENSD_12VerifierKindEbbbbb+0x3f9f)[0x78692f]
build-all/bin/opt(main+0x3fad)[0x79767d]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7f0ae497f555]
build-all/bin/opt[0x781270]
Abort

This starts happening with a919d3d888
    [IROutliner] Ensure that incoming blocks of PHINodes are included in the unique numbering gneration for phi nodes for each exit path
    
    Issue: https://github.com/llvm/llvm-project/issues/54431
    
    PHINodes that need to be generated to accommodate a PHINode outside the region due to different output paths need to have their own numbering to determine the number of output schemes required to properly handle all the outlined regions. This numbering was previously only determined by the order and values of the incoming values, as well as the parent block of the PHINode. This adds the incoming blocks to the calculation of a hash value for these PHINodes as well, and the supporting infrastructure to give each block in a region a corresponding canonical numbering.
    
    Reviewer: paquette
    
    Differential Revision: https://reviews.llvm.org/D122207

[bbi-68950.ll.gz](https://github.com/llvm/llvm-project/files/8569121/bbi-68950.ll.gz)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9WF1z47YO_TXOCyceibK-HvyQTZxZ3yZbj53ZafuioSTIZlYWVZJy6v31BShbUTZpk_bOvR7HtkgCPDgAQSC5Ko_zuj7sWaH2e2knwRUDP4xiiGM_T9KJdzPxrvpPDa1WZVcAe5J2hyv7YdVadtkKY8BMgpsJjzX83kkNk-Ba6ksj97IWWtrjJFjgJLtUbMJvSzjgZ9PVNctzeRklaehN63q83RpMV9vxNgRuOkU52RR1VwL-Iuj4tenaVmmLv66FsbLZTgkfj1ISsccWGrEHVuBcpsESlutfJvya_YpYrggY7hKggTajxcxpdUMkMuFJv46nbBJ--oWhmaMly8ZY3RVWquak8sX0V1F3MAlvCMkVkqRpIZtEnjTCwSBaElzl1PMI3_jF3cbB9UNPW0KTQm-7PTSWqYohA2rfCivzGpyBE-6jFBFcCVlDOe1ZW90trjYLZrocncsEy7stQz8iV8wqtrO2NQST3-J7i17t8ikqfiaWvi7R7Y9QELvSmA7dzG-ZaEp2cgOzO-RWC7NjuSi-WS0KOG2_sTjAym7fDn70cCpdabXVYj-YRCAQm6zLS4FRwG9ziWTevgytv46r10GF3zu1pwjpRA71TpHOV4H2DM-FtOosM8d9rmpG8WJQSwKN6TSwo-rYThz60LjsF8nvoJEDmtNsdfXwmSnNDFjHBzQHqVXj_HUQmhx-d_f1Ptv8ev_p57vlb4t1RiI4TI5olWycR_AE8nTg6k1GEFT225cZAQnM0fjhSqOwM-WBqF-sv2wy39fiKVMYmSD2Cznhn7w_eEC6Q_pV5Hi6A4rKj-8Tr7tmI7eNqD-j82vQZnFwegFGemfA4R29ZwRhEA0rKdRkHs3679buEHc5NWrqueBHiSoKvPM-ceUJiPmsoLG3VRQkjIcp2RqH2ekI4hcaZmkaBEn8ngaRu9S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