Skip to content

Commit

Permalink
[AMDGPU][AsmParser] Fix matching immediate literals.
Browse files Browse the repository at this point in the history
Prevents potential matching of literal offsets to non-literal operands.

Reviewed By: dp

Differential Revision: https://reviews.llvm.org/D142194
  • Loading branch information
kosarev committed Feb 10, 2023
1 parent 68adc02 commit f0f8ae7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 6 additions & 4 deletions llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
Expand Up @@ -347,6 +347,8 @@ class AMDGPUOperand : public MCParsedAsmOperand {
return isImm() && Imm.Type == ImmT;
}

bool isImmLiteral() const { return isImmTy(ImmTyNone); }

bool isImmModifier() const {
return isImm() && Imm.Type != ImmTyNone;
}
Expand Down Expand Up @@ -7940,7 +7942,7 @@ void AMDGPUAsmParser::cvtIntersectRay(MCInst &Inst,
//===----------------------------------------------------------------------===//

bool AMDGPUOperand::isSMRDOffset8() const {
return isImm() && isUInt<8>(getImm());
return isImmLiteral() && isUInt<8>(getImm());
}

bool AMDGPUOperand::isSMEMOffset() const {
Expand All @@ -7951,7 +7953,7 @@ bool AMDGPUOperand::isSMEMOffset() const {
bool AMDGPUOperand::isSMRDLiteralOffset() const {
// 32-bit literals are only supported on CI and we only want to use them
// when the offset is > 8-bits.
return isImm() && !isUInt<8>(getImm()) && isUInt<32>(getImm());
return isImmLiteral() && !isUInt<8>(getImm()) && isUInt<32>(getImm());
}

AMDGPUOperand::Ptr AMDGPUAsmParser::defaultSMRDOffset8() const {
Expand Down Expand Up @@ -8439,11 +8441,11 @@ bool AMDGPUOperand::isABID() const {
}

bool AMDGPUOperand::isS16Imm() const {
return isImm() && (isInt<16>(getImm()) || isUInt<16>(getImm()));
return isImmLiteral() && (isInt<16>(getImm()) || isUInt<16>(getImm()));
}

bool AMDGPUOperand::isU16Imm() const {
return isImm() && isUInt<16>(getImm());
return isImmLiteral() && isUInt<16>(getImm());
}

//===----------------------------------------------------------------------===//
Expand Down
8 changes: 8 additions & 0 deletions llvm/test/MC/AMDGPU/gfx7_err_pos.s
Expand Up @@ -36,3 +36,11 @@ v_and_b32_e64 v0, 0.159154943091895317852646485335, v1
// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: literal operands are not supported
// CHECK-NEXT:{{^}}v_and_b32_e64 v0, 0.159154943091895317852646485335, v1
// CHECK-NEXT:{{^}} ^

//==============================================================================
// cache policy is not supported for SMRD instructions

s_load_dword s5, s[2:3], glc
// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: cache policy is not supported for SMRD instructions
// CHECK-NEXT:{{^}}s_load_dword s5, s[2:3], glc
// CHECK-NEXT:{{^}} ^

0 comments on commit f0f8ae7

Please sign in to comment.