This is an archive of the discontinued LLVM Phabricator instance.

AMDGPU: Teach fneg combines that select has source modifiers
ClosedPublic

Authored by arsenm on Jan 23 2023, 4:27 PM.

Details

Reviewers
sebastian-ne
rampitec
foad
Pierre-vh
arsenm
Group Reviewers
Restricted Project
Summary

We do match source modifiers for f32 typed selects already, but the
combiner code was never informed of this.

A long time ago the documentation lied and stated that source
modifiers don't work for v_cndmask_b32 when they in fact do. We had a
bunch fo code operating under the assumption that they don't support
source modifiers, so we tried to move fnegs around to work around
this.

Gets a few small improvements here and there. The main hazard to watch
out for is infinite loops in the combiner since we try to move fnegs
up and down the DAG. For now, don't fold fneg directly into select.
The generic combiner does this for a restricted set of cases
when getNegatedExpression obviously shows an improvement for both
operands. It turns out to be trickier to avoid infinite looping the
combiner in conjunction with pulling out source modifiers, so
leave this for a later commit.

Diff Detail

Event Timeline

arsenm created this revision.Jan 23 2023, 4:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 23 2023, 4:27 PM
arsenm requested review of this revision.Jan 23 2023, 4:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 23 2023, 4:27 PM
Herald added a subscriber: wdng. · View Herald Transcript

Do we have/want something like this in GISel?

llvm/test/CodeGen/AMDGPU/fmin_fmax_legacy.amdgcn.ll
1

It would be nice for those tests to be autogenerated to make them easier to update, make review easier and increase our testing coverage.
Is there a reason why we have some manual tests like these?

In any case it's not for this diff but I've been wondering about this. If I have some time maybe I can make diffs to autogenerate a few of them because it can be a bit annoying sometimes

arsenm added a comment.Feb 3 2023, 3:05 AM

Do we have/want something like this in GISel?

Of course, but the base set of source modifier combines haven't been ported yet

llvm/test/CodeGen/AMDGPU/fmin_fmax_legacy.amdgcn.ll
1

Manual test checks are the original way to do it, generating checks is much newer. Blindly generating checks feels a bit dangerous since it's easy to not actually look at the diffs.

Plus generated tests break more frequently, partially because update_llc_test_checks doesn't support matching registers into variables like the x86 one

I personally don't have anymore comments, but I'll leave it up to someone with more experience to approve this as there's quite a bit of changes in the codegen and I'm not familiar with all instructions involved

arsenm planned changes to this revision.Feb 8 2023, 3:14 AM

I found a case that infinite loops the combiner

arsenm updated this revision to Diff 497507.Feb 14 2023, 5:52 PM
arsenm edited the summary of this revision. (Show Details)

Don't do the custom / aggressive fold of fneg into select, since it seems tricky to not infinite loop the combiner with foldFreeOpFromSelect. We don't fully lose this, since the generic combiner does fold selects with cheap getNegatedExpression, which doesn't consider free source modifiers. Leave this for a later change

arsenm accepted this revision.Feb 19 2023, 4:13 PM

Last revision just dropped a piece. 28d8889d272590856e7e270aff66de080225d501

This revision is now accepted and ready to land.Feb 19 2023, 4:13 PM
arsenm closed this revision.Feb 19 2023, 4:13 PM