Skip to content

Commit d14f2a6

Browse files
committed
[AMDGPU] Allow multiple uses of the same literal in SOP2/SOPC
AMDGPUAsmParser::validateSOPLiteral already knew about this but SIInstrInfo::verifyInstruction did not. Differential Revision: https://reviews.llvm.org/D125976
1 parent a136a00 commit d14f2a6

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4366,16 +4366,11 @@ bool SIInstrInfo::verifyInstruction(const MachineInstr &MI,
43664366
if (isSOP2(MI) || isSOPC(MI)) {
43674367
const MachineOperand &Src0 = MI.getOperand(Src0Idx);
43684368
const MachineOperand &Src1 = MI.getOperand(Src1Idx);
4369-
unsigned Immediates = 0;
43704369

4371-
if (!Src0.isReg() &&
4372-
!isInlineConstant(Src0, Desc.OpInfo[Src0Idx].OperandType))
4373-
Immediates++;
4374-
if (!Src1.isReg() &&
4375-
!isInlineConstant(Src1, Desc.OpInfo[Src1Idx].OperandType))
4376-
Immediates++;
4377-
4378-
if (Immediates > 1) {
4370+
if (!Src0.isReg() && !Src1.isReg() &&
4371+
!isInlineConstant(Src0, Desc.OpInfo[Src0Idx].OperandType) &&
4372+
!isInlineConstant(Src1, Desc.OpInfo[Src1Idx].OperandType) &&
4373+
!Src0.isIdenticalTo(Src1)) {
43794374
ErrInfo = "SOP2/SOPC instruction requires too many immediate constants";
43804375
return false;
43814376
}

llvm/test/CodeGen/AMDGPU/verify-duplicate-literal.mir

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,19 @@ body: |
2626
; CHECK: $vgpr0 = V_FMA_F32_e64 0, $vgpr0, 0, 1077936128, 0, 1077936128, 0, 0, implicit $mode, implicit $exec
2727
$vgpr0 = V_FMA_F32_e64 0, $vgpr0, 0, 1077936128, 0, 1077936128, 0, 0, implicit $mode, implicit $exec
2828
...
29+
30+
---
31+
name: use_duplicate_literal_sop2
32+
tracksRegLiveness: true
33+
body: |
34+
bb.0:
35+
$sgpr0 = S_ADD_U32 12345, 12345, implicit-def $scc
36+
...
37+
38+
---
39+
name: use_duplicate_literal_sopc
40+
tracksRegLiveness: true
41+
body: |
42+
bb.0:
43+
S_CMP_LG_U32 305419896, 305419896, implicit-def $scc
44+
...

0 commit comments

Comments
 (0)