This is an archive of the discontinued LLVM Phabricator instance.

[GISel] Add (fsub +-0.0, X) -> fneg combine
ClosedPublic

Authored by Pierre-vh on Oct 21 2022, 4:24 AM.

Details

Summary

Allows for better matching of VOP3 mods.

Diff Detail

Event Timeline

Pierre-vh created this revision.Oct 21 2022, 4:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 21 2022, 4:24 AM
Pierre-vh requested review of this revision.Oct 21 2022, 4:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 21 2022, 4:24 AM
arsenm added inline comments.Oct 21 2022, 8:02 AM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
5206

Doing this for -0 is only valid with nsz: https://alive2.llvm.org/ce/z/SK2Bs9

5206

I mean +0

5211

This changes a canonicalizing operation to a non-canonicalizing operation. You need to introduce a canonicalize unless you know denormals aren't flushed and the source isn't a signaling nan. InstCombine currently has a bug where it ignores this.

The DAG also has getNegatedExpression, which may be overkill at this moment

Pierre-vh updated this revision to Diff 470088.Oct 24 2022, 2:09 AM
Pierre-vh marked 3 inline comments as done.

Comments

arsenm added inline comments.Oct 31 2022, 7:28 PM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
5201

Probably should allow undefs

5212

MI.getFlag(MachineInstr::FmNsz)

llvm/test/CodeGen/AMDGPU/GlobalISel/combine-fsub-fneg.mir
368

Test for the undef vector element case

Pierre-vh updated this revision to Diff 472548.Nov 2 2022, 2:31 AM
Pierre-vh marked 3 inline comments as done.

Comments

llvm/test/CodeGen/AMDGPU/GlobalISel/combine-fsub-fneg.mir
368

There's already a test "test_v4f32_negzero_undef_nofold". Do we want that to fold or not?
I guess so, since undef can be anything we can consider it to be identical to other other elements

I updated it and added another one for poszero.

arsenm accepted this revision.Nov 2 2022, 3:47 PM
This revision is now accepted and ready to land.Nov 2 2022, 3:47 PM
This revision was landed with ongoing or failed builds.Nov 3 2022, 1:21 AM
This revision was automatically updated to reflect the committed changes.