This is an archive of the discontinued LLVM Phabricator instance.

`G_ATOMICRMW_NAND` failure in legalizer
AcceptedPublic

Authored by niwinanto on Jun 9 2023, 7:37 AM.

Details

Summary

Legalizer fails to widen output type for G_ATOMICRMW_NAND.

Diff Detail

Event Timeline

niwinanto created this revision.Jun 9 2023, 7:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 9 2023, 7:37 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
niwinanto requested review of this revision.Jun 9 2023, 7:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 9 2023, 7:37 AM
arsenm added a comment.Jun 9 2023, 7:39 AM

Needs testcase

Needs testcase

I am not sure how to trigger this error. I don't see any targets legalizing G_ATOMICRMW_NAND. Only AMD GPU has G_ATOMICRMW_NAND in legalizerInfo, but it is lowered. In our use case we are legalizing it and facing this issue.

arsenm added a comment.Jun 9 2023, 9:28 AM

Needs testcase

I am not sure how to trigger this error. I don't see any targets legalizing G_ATOMICRMW_NAND. Only AMD GPU has G_ATOMICRMW_NAND in legalizerInfo, but it is lowered. In our use case we are legalizing it and facing this issue.

You didn't post any patch context so I'm not sure what you're specifically handling here. You just need a mir test with G_ATOMICRMW_NAND and/or an IR test with atomicrmw nand with the appropriate type

Needs testcase

I am not sure how to trigger this error. I don't see any targets legalizing G_ATOMICRMW_NAND. Only AMD GPU has G_ATOMICRMW_NAND in legalizerInfo, but it is lowered. In our use case we are legalizing it and facing this issue.

You didn't post any patch context so I'm not sure what you're specifically handling here. You just need a mir test with G_ATOMICRMW_NAND and/or an IR test with atomicrmw nand with the appropriate type

Apologies, I could not explain correctly.

For example

%0 = atomicrmw nand ptr @sc, i8 1 seq_cst, align 1

to

%0:_(s8) = G_ATOMICRMW_NAND %1(p0), %2 :: (load store seq_cst (s8) on @s    c)

In our use case, s8 for G_ATOMICRMW_NAND is not supported. Hence, trying to widen it to s32.
However, LegalizerHelper::widenScalar(...) does not handle G_ATOMICRMW_NAND, but other G_ATOMICRMW*.

Why I cannot add test/ trigger this error, no other target legalize G_ATOMICRMW_NAND, hence I cannot invoke LegalizerHelper::widenScalar(...).

arsenm added a comment.Jun 9 2023, 9:54 AM

Needs testcase

I am not sure how to trigger this error. I don't see any targets legalizing G_ATOMICRMW_NAND. Only AMD GPU has G_ATOMICRMW_NAND in legalizerInfo, but it is lowered. In our use case we are legalizing it and facing this issue.

You didn't post any patch context so I'm not sure what you're specifically handling here. You just need a mir test with G_ATOMICRMW_NAND and/or an IR test with atomicrmw nand with the appropriate type

Apologies, I could not explain correctly.

For example

%0 = atomicrmw nand ptr @sc, i8 1 seq_cst, align 1

to

%0:_(s8) = G_ATOMICRMW_NAND %1(p0), %2 :: (load store seq_cst (s8) on @s    c)

In our use case, s8 for G_ATOMICRMW_NAND is not supported. Hence, trying to widen it to s32.
However, LegalizerHelper::widenScalar(...) does not handle G_ATOMICRMW_NAND, but other G_ATOMICRMW*.

Why I cannot add test/ trigger this error, no other target legalize G_ATOMICRMW_NAND, hence I cannot invoke LegalizerHelper::widenScalar(...).

I think ppc or mips would use this, plus there's always unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp

Needs testcase

I am not sure how to trigger this error. I don't see any targets legalizing G_ATOMICRMW_NAND. Only AMD GPU has G_ATOMICRMW_NAND in legalizerInfo, but it is lowered. In our use case we are legalizing it and facing this issue.

You didn't post any patch context so I'm not sure what you're specifically handling here. You just need a mir test with G_ATOMICRMW_NAND and/or an IR test with atomicrmw nand with the appropriate type

Apologies, I could not explain correctly.

For example

%0 = atomicrmw nand ptr @sc, i8 1 seq_cst, align 1

to

%0:_(s8) = G_ATOMICRMW_NAND %1(p0), %2 :: (load store seq_cst (s8) on @s    c)

In our use case, s8 for G_ATOMICRMW_NAND is not supported. Hence, trying to widen it to s32.
However, LegalizerHelper::widenScalar(...) does not handle G_ATOMICRMW_NAND, but other G_ATOMICRMW*.

Why I cannot add test/ trigger this error, no other target legalize G_ATOMICRMW_NAND, hence I cannot invoke LegalizerHelper::widenScalar(...).

I think ppc or mips would use this, plus there's always unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp

I was not aware of unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp let me have a look at this.

niwinanto updated this revision to Diff 530049.Jun 9 2023, 12:14 PM

Added testcase.

arsenm added inline comments.Jun 9 2023, 2:29 PM
llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
4197

Ideally would have some defs for it

4198

can just specify the return type here

4211

This should really fail with use of undefined value

niwinanto added inline comments.Jun 10 2023, 12:51 AM
llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
4197

Yes, but I don't find any def for MachineMemOperand and this is how other tests are also using it.

4198

You meant auto MIBAtomicRMWNand to MachineInstrBuilder MIBAtomicRMWNand, or?

4211

I don't really get this. What do you mean?

niwinanto updated this revision to Diff 530187.Jun 10 2023, 2:32 AM

Updated with full diff for more patch context.

arsenm added inline comments.Jun 10 2023, 4:40 AM
llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
4197

MachineMemOperand is not a value. I'm talking about Addr and Val, which are undefined registers here

4198

auto Nand = B.buildAtomicRMW(LLT::scalar(32))

4207

Also check the inputs

4211

You didn't define the input registers for the instruction

niwinanto updated this revision to Diff 530200.Jun 10 2023, 6:20 AM

Feedback addressed for test case.

niwinanto marked 7 inline comments as done.Jun 10 2023, 6:25 AM
niwinanto added inline comments.
llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
4198

I don't get the issue with buildAtomicRMWNand

arsenm added inline comments.Jun 10 2023, 8:10 AM
llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
4198

You do not need to pre-create the register. You can pass the type like you did with buildConstant above

niwinanto marked an inline comment as done.

More feedback addressed.

niwinanto marked an inline comment as done.Jun 10 2023, 10:36 AM
niwinanto added inline comments.
llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
4198

Thanks for explaining. Now I got it.

arsenm accepted this revision.Jun 10 2023, 10:43 AM
arsenm added inline comments.
llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
4197

Oh, looks like all of these wrappers around specific atomicrmws were never updated

This revision is now accepted and ready to land.Jun 10 2023, 10:43 AM
niwinanto marked an inline comment as done.Jun 23 2023, 3:17 PM

@arsenm thank you for reviewing this. I do not have the commit access, could you please commit for me.
Niwin Anto <niwin.anto@hightec-rt.com>