diff --git a/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp b/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp index 783181980342..ac3c7eb541ae 100644 --- a/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp +++ b/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp @@ -345,6 +345,7 @@ void SIFoldOperands::foldOperand( // Don't fold into target independent nodes. Target independent opcodes // don't have defined register classes. if (UseDesc.isVariadic() || + UseOp.isImplicit() || UseDesc.OpInfo[UseOpIdx].RegClass == -1) return; } diff --git a/llvm/test/CodeGen/AMDGPU/fold-implicit-operand.mir b/llvm/test/CodeGen/AMDGPU/fold-implicit-operand.mir new file mode 100644 index 000000000000..4dec859f0bad --- /dev/null +++ b/llvm/test/CodeGen/AMDGPU/fold-implicit-operand.mir @@ -0,0 +1,14 @@ +# RUN: llc -march=amdgcn -run-pass si-fold-operands -verify-machineinstrs -o - %s | FileCheck %s +--- +# Make sure there is no crash when trying to fold an immediate into an +# implicit use + +# CHECK: %0:vgpr_32 = V_MOV_B32_e32 0, implicit $exec +# CHECK-NEXT: S_ENDPGM implicit %0 +name: fold_imm_implicit_operand +body: | + bb.0: + %0:vgpr_32 = V_MOV_B32_e32 0, implicit $exec + S_ENDPGM implicit %0 + +...