This is an archive of the discontinued LLVM Phabricator instance.

AMDGPU/GlobalISel: Remove redundant G_FCANONICALIZE
ClosedPublic

Authored by Petar.Avramovic on Feb 12 2021, 7:08 AM.

Details

Summary

G_FMINNUM_IEEE and G_FMAXNUM_IEEE are known to be never SNaN
and there is no need to quiet them using G_FCANONICALIZE.
Add post legalizer combine that deletes such G_FCANONICALIZE and
replaces its uses with input (G_FMINNUM_IEEE or G_FMAXNUM_IEEE) register.

Diff Detail

Event Timeline

Petar.Avramovic requested review of this revision.Feb 12 2021, 7:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 12 2021, 7:08 AM
foad added inline comments.Feb 12 2021, 7:14 AM
llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp
257

You can use standard replaceSingleDefInstWithOperand or replaceSingleDefInstWithReg instead of defining your own apply function.

Use replaceSingleDefInstWithReg.

arsenm added inline comments.Feb 12 2021, 7:41 AM
llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp
253–255

Really we should have an isCanonicalized utility function like we do in the DAG rather than special casing these two

foad added inline comments.Feb 12 2021, 8:02 AM
llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp
250

I think the C should be capital too, matchRemoveFCanonicalize. This matches buildFCanonicalize in MIRBuilder.

arsenm requested changes to this revision.Mar 30 2021, 3:31 PM

Should have isCanonicalize utility function

This revision now requires changes to proceed.Mar 30 2021, 3:31 PM

Added basic version of isCanonicalized for global-isel. Copied from sdag.

arsenm added inline comments.Mar 31 2021, 9:19 AM
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
9649

I don't think this really belongs in SITargetLowering, but I don't have a better suggestion for now

9655–9658

Duplicated / dead path for fcanonicalize. This meant G_FCONSTANT

9671

We shouldn't actually treat these generic instructions differently based on the subtarget, but I guess that's an existing problem

llvm/test/CodeGen/AMDGPU/GlobalISel/combine-fcanonicalize.mir
169

Needs tests for the G_FCONSTANT cases

foad added a comment.Apr 1 2021, 1:58 AM

Looks good to me apart from the G_FCONSTANT issues.

Fixed G_FCONSTANT and added test for it.

foad accepted this revision.Apr 1 2021, 8:10 AM

LGTM.

This revision was not accepted when it landed; it landed in state Needs Review.Apr 27 2021, 3:27 AM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.