This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Don't require swz operand for non-return Atomics.
Needs ReviewPublic

Authored by MJDSys on Nov 14 2020, 5:56 PM.

Details

Reviewers
rampitec
foad
Summary

When legalizing operands for instructions that are not atmoics with
a return, do not assume the swz operand is present.

This avoids an assert in the openmm test suite.

Diff Detail

Event Timeline

MJDSys created this revision.Nov 14 2020, 5:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 14 2020, 5:56 PM
MJDSys requested review of this revision.Nov 14 2020, 5:56 PM

Needs test.

Hi @rampitec,

I've tried writing a test for this change, but I've been having trouble (I'm new to LLVM so I might be missing the obvious answer). From what I can see, I thought the correct option would be to create a MIR test, using the same instruction that I saw when investigating the original problem. I started by copying and modifying an existing test in fix-sgpr-copies.mir:

# Test to ensure non-return buffer atomics work
# GCN-LABEL: name: non-return-buffer-atomic
# GCN: S_CSELECT_B64 -1, 0, implicit undef $scc
# GCN: V_CNDMASK
---
name: non-return-buffer-atomic
tracksRegLiveness: true

body:               |
  bb.0:
  %1:vreg_64 = IMPLICIT_DEF
  %2:vreg_128 = IMPLICIT_DEF
  BUFFER_ATOMIC_OR_X2_OFFSET %1, %2, 0, 0, 0, implicit $exec
---

However, when I try running the test I get an assert happening, with LLVM complaining the machine code is incorrect due to an illegal virtual register. I got stuck here as I'm trying to create an instruction with an incorrect register to have the code fix it (same as what is done in the failing pass). I'm not sure how to proceed, do you have any suggestion/pointers? Or an alternate test I can use as a template? Note: I'm aware the expected output of the test was incorrect, I was first wanting to verify the test output manually before making it work during a normal test run.

Thanks,

Matthew

Needs test.

Hi @rampitec,

I've tried writing a test for this change, but I've been having trouble (I'm new to LLVM so I might be missing the obvious answer). From what I can see, I thought the correct option would be to create a MIR test, using the same instruction that I saw when investigating the original problem. I started by copying and modifying an existing test in fix-sgpr-copies.mir:

legalizeOperands() works as a part of the instruction selection so you cannot use mir test anyway. You need to write an .ll test (presumably calling an intrinsic to emit this atomic). You can start with code from llvm.amdgcn.buffer.atomic.ll.