This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Fix adding modifiers when creating v_cmpx instructions.
ClosedPublic

Authored by tsymalla on Mar 25 2022, 9:35 AM.

Details

Summary

Revision https://reviews.llvm.org/D122332 added a pattern transformation
where v_cmpx instructions are introduced. However, the modifiers are
not correctly inherited from the original operands. The patch
adds the source modifiers, if they are exist, or sets them to 0.

Diff Detail

Event Timeline

tsymalla created this revision.Mar 25 2022, 9:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 25 2022, 9:35 AM
tsymalla requested review of this revision.Mar 25 2022, 9:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 25 2022, 9:35 AM
foad added a comment.Mar 25 2022, 9:49 AM

Looks OK but needs a lit test.

llvm/lib/Target/AMDGPU/SIOptimizeExecMasking.cpp
454–458

I'd slightly prefer a "getNamedImmOperandOrZero" which just returns the immediate value, instead of calling Builder.add.

456

Should probably reuse the index that you discarded on the line above, to avoid looking it up by name a second time.

tsymalla marked an inline comment as done.Mar 25 2022, 12:15 PM
tsymalla added inline comments.
llvm/lib/Target/AMDGPU/SIOptimizeExecMasking.cpp
454–458

The immediate value should only be added when the operand is found on the instruction, so the builder should only be called with 0 or the immediate value. When just returning the value, it would be required to have additional state which needs to be checked after calling the lambda to ensure a value needs to be added. This would delegate the responsibility back to the caller, but probably complicate everything.

I agree with renaming the object though.

tsymalla updated this revision to Diff 418312.Mar 25 2022, 1:22 PM

Add lit test, address review comments.

tsymalla added inline comments.Mar 25 2022, 1:32 PM
llvm/lib/Target/AMDGPU/SIOptimizeExecMasking.cpp
454–458

I refactored this. As getNamedOperand returns nullptr when Idx == -1, the behavior should be the same.

foad accepted this revision.Mar 28 2022, 4:06 AM

LGTM, thanks!

llvm/lib/Target/AMDGPU/SIOptimizeExecMasking.cpp
457

I think you might be able to simplify this to Builder.add(*Mod) but I'm not sure.

This revision is now accepted and ready to land.Mar 28 2022, 4:06 AM
This revision was landed with ongoing or failed builds.Mar 28 2022, 8:53 AM
This revision was automatically updated to reflect the committed changes.