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

    <tr>
        <th>Summary</th>
        <td>
            [AMDGPU][LLC][LLVM] Cannot select: intrinsic %llvm.amdgcn.if
        </td>
    </tr>

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

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

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

<pre>
    Hi,all
I’m working on adding AMDGPU backend for a JIT compiler(Taichi) and in a bit of trouble now.
With O3 optimization
```
  llvm::PassManagerBuilder builder;
  builder.OptLevel = 3;
  builder.Inliner =
      llvm::createFunctionInliningPass(builder.OptLevel, 0, false);
```
I will get the code snippet of LLVM-IR
```
entry:
  %0 = tail call i32 @llvm.amdgcn.workitem.id.x()
  %1 = tail call align 4 dereferenceable(64) i8 addrspace(4)* @llvm.amdgcn.dispatch.ptr()
  %2 = getelementptr inbounds i8, i8 addrspace(4)* %1, i64 12
  %3 = bitcast i8 addrspace(4)* %2 to i32 addrspace(4)*, !amdgpu.uniform !7
  %4 = load i32, i32 addrspace(4)* %3, align 4, !tbaa !8
  %5 = getelementptr i8, i8 addrspace(4)* %1, i64 4
  %6 = bitcast i8 addrspace(4)* %5 to i16 addrspace(4)*, !amdgpu.uniform !7
  %7 = load i16, i16 addrspace(4)* %6, align 4, !range !17, !invariant.load !7
  %8 = tail call i32 @llvm.amdgcn.workgroup.id.x()
  %9 = zext i16 %7 to i32
  %10 = mul i32 %8, %9
  %11 = sub i32 %4, %10
  %12 = tail call i32 @llvm.umin.i32(i32 %11, i32 %9)
  %13 = mul nsw i32 %12, %8
  %14 = add nsw i32 %13, %0
  %15 = icmp slt i32 %14, 16777216
  %16 = call { i1, i32 } @llvm.amdgcn.if.i32(i1 %15)
  %17 = extractvalue { i1, i32 } %16, 0
  %18 = extractvalue { i1, i32 } %16, 1
  br i1 %17, label %.lr.ph, label %Flow47
```
when I use llc to generate GCN assembly(llc xxx.ll), I get this error
```
LLVM ERROR: Cannot select: intrinsic %llvm.amdgcn.if
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: llc taichi_kernel_amdgpu_llvm_ir_optimized_0005.ll
1.      Running pass 'CallGraph Pass Manager' on module 'taichi_kernel_amdgpu_llvm_ir_optimized_0005.ll'.
2.      Running pass 'AMDGPU DAG->DAG Pattern Instruction Selection' on function '@saxpy_kernel_c76_0_kernel_0_range_for'
 #0 0x000000000231b3e3 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
 #1 0x000000000231933e llvm::sys::RunSignalHandlers()
 #2 0x000000000231b76f SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f0b5bf22420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f0b5ba0100b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007f0b5b9e0859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
#6 0x0000000002297108
 #7 0x000000000218da41 
 #8 0x000000000218cf9d 
 #9 0x0000000002185c2f llvm::SelectionDAGISel::DoInstructionSelection() 
#10 0x00000000021852e0 llvm::SelectionDAGISel::CodeGenAndEmitDAG()
#11 0x000000000218457f llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) 
#12 0x00000000021822f7 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&)
#13 0x0000000000b031f4 AMDGPUDAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) 
#14 0x0000000001965a8e llvm::MachineFunctionPass::runOnFunction(llvm::Function&)
#15 0x0000000001cf6a8d llvm::FPPassManager::runOnFunction(llvm::Function&)
#16 0x0000000001623fe2 (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) CallGraphSCCPass.cpp:0:0
#17 0x0000000001cf7660 llvm::legacy::PassManagerImpl::run(llvm::Module&) 
#18 0x00000000006e749e main 
#19 0x00007f0b5b9e2083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#20 0x00000000006e25da _start 
Aborted (core dumped)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysWF1v2zoS_TXMC1GBor4f8uDEsa8XyTZIuncfDUoay9xSpEBSjXN__YKUbEuue5sW12hjmx_nnBnODEdmxvBGAtyi5A4lyxvW273St2sm4BUeAW5KVb_f_sERvWdCILJEZLFBDxTlBBVFi9-U_splg5XErK7dp8XTcv38H1yy6ivIGu-Uxgz_a_MFV6rtuACNaP6F8WrPES0wkzXmEjNccovVDlut-lIAluotGNj-y-0ef46w6ixv-V_MciWHGZSS8Z__irEQ31oULVC0eGbGPDHJGtB3PRc1aFwO7yi6Oy4fR4LPnX2EbyAwipY4urJgIwWXoN38ccq9znSVBmZh1cvKqfPLuWycCETzSxpE7zFxf3ZMGEC0ODFeGLTBb1wI3IDFdg-4UjVgI3nXgXfV4-OfT582L1e3grT63Wkb5SKaEG-eZVzgigmBeUQxiokzImBt3VQy8IdpoQ14HRwQzZ22M0B4AcAEbySOcQ0adqBBVsBKAYjmaeyOlucuJLTpWOUG3Riii0vOmpuO2WofdFZ_R0k9ZQMWBLQgbWc15rJUvawN5rlz4o9YaBL66TTGIZ1ARh6y5LZixv7Nboqt8j66Mu-AEQ2dBV0f9JLvlG7dSDYhij2RUKx2MF7LdTSvys2PDh3RbcmYe88nmMk1f3zUDfEEKP2gFxLvhTD9bS9kEy-EqZdyHc2r-t4LmskG3IcwG0e4_MY0Z9IGHvWCL_9YlDda9d31MC88wl9wsF6qt2EIhWkuDNnU9iMDTfJBXjLLmCFlTF8eV41mJSGZLqN_I7pvuQx8AOUjRhgeg8nTzXM0OumS5u24KKQj7TSWwiFAWV3Plkbj0pnAIe541XbYCHta660J0yzLaJhO1w_h5W1B2R3mZ8XZ8vI4-O5oXjhwXVg0RBAcrGaV_cZED9cwH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