This is an archive of the discontinued LLVM Phabricator instance.

AMDGPU/SI: Re-define AMDGPUISD:CLAMP as always clamping between 0.0. and 1.0
ClosedPublic

Authored by arsenm on Aug 7 2015, 6:32 AM.

Details

Summary

We weren't actally selecting AMDGPUISD::CLAMP with a range other than
0.0 and 1.0, and this range is the only one we really care about since
we can fold it into VOP3 instructions.

Clamping to other ranges is now done with ISD::FMINNUM and ISD::FMAXNUM.

Diff Detail

Event Timeline

tstellarAMD retitled this revision from to AMDGPU/SI: Re-define AMDGPUISD:CLAMP as always clamping between 0.0. and 1.0.
tstellarAMD updated this object.
tstellarAMD added a reviewer: arsenm.
tstellarAMD added a subscriber: llvm-commits.
arsenm added inline comments.Sep 10 2015, 3:41 PM
lib/Target/AMDGPU/AMDGPUISelLowering.cpp
1020–1023

Is this the same as v_med_f32?

arsenm commandeered this revision.Feb 17 2017, 9:14 PM
arsenm edited reviewers, added: tstellarAMD; removed: arsenm.
arsenm updated this revision to Diff 89014.Feb 17 2017, 9:15 PM
arsenm added a reviewer: tstellar.

Change implementation to use max instead of add.
min/max/med3 do not flush denormals regardless of the mode,
so it is OK to use it whether or not they are enabled.

Also allow using clamp with f16, and use knowledge
of dx10_clamp.

arsenm updated this revision to Diff 89015.Feb 17 2017, 9:27 PM

Don't allow -0.0

artem.tamazov requested changes to this revision.Feb 20 2017, 3:22 AM

Change implementation to use max instead of add.
min/max/med3 do not flush denormals regardless of the mode,
so it is OK to use it whether or not they are enabled.

Starting from Gfx9, min/max/med3 do support denorm modes on data path.

This revision now requires changes to proceed.Feb 20 2017, 3:22 AM

Starting from Gfx9, min/max/med3 do support denorm modes on data path.

Actually, I do not see anything wrong wrt usage of min/max/med3 for now.
Min/max/med3 is even better than ADD because "ADD X, 0.0"does not preserve the sign of X when X==-0.0.

artem.tamazov accepted this revision.Feb 20 2017, 4:02 AM
This revision is now accepted and ready to land.Feb 20 2017, 4:02 AM

Starting from Gfx9, min/max/med3 do support denorm modes on data path.

Actually, I do not see anything wrong wrt usage of min/max/med3 for now.
Min/max/med3 is even better than ADD because "ADD X, 0.0"does not preserve the sign of X when X==-0.0.

@artem.tamazov Do you know the answer to the denormal questions I added in comments? Most importantly are denormals really not supported with clamp? And if not for f32, are they still not supported for f16/f64? Does clamp work with f64 instructions?

arsenm updated this revision to Diff 89140.Feb 20 2017, 11:44 AM

Attach newer version

artem.tamazov added a comment.EditedFeb 21 2017, 2:55 AM

@arsenm

@artem.tamazov Do you know the answer to the denormal questions I added in comments? Most importantly are denormals really not supported with clamp? And if not for f32, are they still not supported for f16/f64? Does clamp work with f64 instructions?

Unlike output modifiers (*2, *4, /2), output clamp is compatible with both denormals and IEEE mode of the shader. It is applicable to all supported floating types (f16/f32/f64 in Gfx8+, f32/f64 in Gfx7).

BTW Since Gfx8, clamp is also applicable to many integer instructions. It changes overflow behavior from wrapping to saturation. Saturation range is [-MAX_INT, MAX_INT] for signed integers and [0, MAX_UINT] for unsigned.

arsenm closed this revision.Feb 21 2017, 3:48 PM

r295788