This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU][AsmParser] Forbid TFE modifiers for MBUF stores.
ClosedPublic

Authored by kosarev on Nov 11 2022, 5:40 AM.

Diff Detail

Event Timeline

kosarev created this revision.Nov 11 2022, 5:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 11 2022, 5:40 AM
kosarev requested review of this revision.Nov 11 2022, 5:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 11 2022, 5:40 AM
dp added a comment.Nov 11 2022, 6:27 AM

Could you add a test to check the reported error position? Unfortunately, AsmMatcher often fails to report the location of offending operand. Moving the check to validator may improve diagnostic by using getImmLoc.

Joe_Nash added inline comments.Nov 11 2022, 6:37 AM
llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
3280

I would prefer dynamic_cast, for safe downcasting.

foad added inline comments.Nov 11 2022, 6:45 AM
llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
3280

LLVM is generally built with -fno-rtti so I don't think you can use dynamic_cast (can you?).

Joe_Nash added inline comments.Nov 11 2022, 6:47 AM
llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
3280

Good point, I don't know if it's available. LLVM dyn_cast may also be an option.

arsenm added inline comments.Nov 11 2022, 7:26 AM
llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
3280

the llvm pseudo-RTTI doesn't just happen and isn't implemented for AMDGPUOperand

Could you add a test to check the reported error position? Unfortunately, AsmMatcher often fails to report the location of offending operand. Moving the check to validator may improve diagnostic by using getImmLoc.

The currently reported position is the beginning of the first operand and in the current design there seems to be no way to do better, which looks a somewhat severe problem to me and I'd be happy to improve it, but that feels well beyond the scope of this patch, doesn't it.

llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
3280

I understand dyn_cast<> is normally used where we have to discriminate between several possibilities with static_cast<> being the standard solution when we know the dynamic type.

Moving the check to validator may improve diagnostic by using getImmLoc.

Sorry, missed that part. Will try it.

dp added a comment.Nov 11 2022, 7:39 AM

The currently reported position is the beginning of the first operand and in the current design there seems to be no way to do better

If AsmMatcher cannot report error position, why do not move the check to AMDGPUAsmParser::validateInstruction then?

If AsmMatcher cannot report error position, why do not move the check to AMDGPUAsmParser::validateInstruction then?

Yes, I think the patch actually misuses checkEarlyTargetMatchPredicate(), which looks more like a mean to exclude unrelated instructions from viable candidates (and that's why there supposed to be no diagnostic output). Here, in contrast, we already know it that the chosen instruction is the right one, but don't want it be used, so validation should be the right point for the check, though that will require introducing another relation table, it seems.

kosarev updated this revision to Diff 474784.Nov 11 2022, 9:00 AM

Reworked as suggested and added a test on error position.

dp accepted this revision.Nov 11 2022, 11:51 AM

LGTM.

llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
4607

Maybe "is not enabled with" would be better?

This revision is now accepted and ready to land.Nov 11 2022, 11:51 AM
dp added inline comments.Nov 11 2022, 1:24 PM
llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
4604

With getImmLoc this loop may be reduced to the following code:

auto Loc = getImmLoc(AMDGPUOperand::ImmTyTFE, Operands);
if (Loc != getInstLoc(Operands)) {
  Error(Loc, "...");
  return false;
}
kosarev updated this revision to Diff 475155.Nov 14 2022, 8:08 AM

Reworked to use getInstLoc() and rebased.

dp accepted this revision.Nov 14 2022, 8:12 AM

Still LGTM.

This revision was landed with ongoing or failed builds.Nov 14 2022, 8:19 AM
This revision was automatically updated to reflect the committed changes.