diff --git a/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp b/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp --- a/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp +++ b/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp @@ -185,6 +185,11 @@ if (!MI.getOperand(0).isReg()) TII->commuteInstruction(MI, false, 0, 1); + // cmpk requires src0 to be a register + const MachineOperand &Src0 = MI.getOperand(0); + if (!Src0.isReg()) + return; + const MachineOperand &Src1 = MI.getOperand(1); if (!Src1.isImm()) return; diff --git a/llvm/test/CodeGen/AMDGPU/cmp_shrink.mir b/llvm/test/CodeGen/AMDGPU/cmp_shrink.mir new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/AMDGPU/cmp_shrink.mir @@ -0,0 +1,11 @@ +# RUN: llc -march=amdgcn -mcpu=gfx900 -run-pass si-shrink-instructions -verify-machineinstrs %s -o - | FileCheck -check-prefix=GCN %s + +# GCN-LABEL: name: not_shrink_icmp +# GCN: bb.0: +# GCN-NOT: S_CMPK_GT_I32 +--- +name: not_shrink_icmp +body: | + bb.0: + S_CMP_GT_I32 1, 65, implicit-def $scc +...