This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Add options -mamdgpu-ieee -mno-amdgpu-ieee
ClosedPublic

Authored by yaxunl on Mar 29 2020, 7:58 AM.

Details

Summary

AMDGPU backend need to know whether floating point opcodes that support exception
flag gathering quiet and propagate signaling NaN inputs per IEEE754-2008, which is
conveyed by a function attribute "amdgpu-ieee". "amdgpu-ieee"="false" turns this off.
Without this function attribute backend assumes it is on for compute functions.

-mamdgpu-ieee and -mno-amdgpu-ieee are added to Clang to control this function attribute.
By default it is on. -mno-amdgpu-ieee requires -fno-honor-nans or equivalent.

Diff Detail

Event Timeline

yaxunl created this revision.Mar 29 2020, 7:58 AM
arsenm added inline comments.Mar 30 2020, 8:22 AM
clang/include/clang/Basic/CodeGenOptions.def
422

Description is misleading. Better description would be the first line from the manual,
"Floating point opcodes that support exception flag gathering quiet and propagate sig- naling NaN inputs per IEEE 754-2008"

clang/include/clang/Driver/Options.td
3211

Ditto

clang/lib/Frontend/CompilerInvocation.cpp
1993

Add a comment explaining why to turn it off? Also should note this is only really concerns signaling nans

clang/test/CodeGenOpenCL/amdgpu-ieee.cl
21

Should also test a non-kernel function

arsenm added inline comments.Mar 30 2020, 8:33 AM
clang/test/CodeGenOpenCL/amdgpu-ieee.cl
21

I think we should also have some ISA check run lines that show the final result for minnum/maxnum lowering, as well as if output modifiers are used

yaxunl planned changes to this revision.Mar 30 2020, 8:57 AM
This comment was removed by yaxunl.
yaxunl marked 4 inline comments as done.Apr 18 2021, 7:15 AM
yaxunl added inline comments.
clang/include/clang/Basic/CodeGenOptions.def
422

will do

clang/include/clang/Driver/Options.td
3211

will do

clang/lib/Frontend/CompilerInvocation.cpp
1993

will do

clang/test/CodeGenOpenCL/amdgpu-ieee.cl
21

will do

yaxunl updated this revision to Diff 338379.Apr 18 2021, 7:22 AM
yaxunl marked 3 inline comments as done.
yaxunl edited the summary of this revision. (Show Details)

Revised by Matt's comments.

arsenm requested changes to this revision.Apr 20 2021, 9:59 AM
arsenm added inline comments.
clang/lib/Frontend/CompilerInvocation.cpp
1952

This should not be implied by no honor nans. This is an ABI changing option. We need to require that no nans FP math is enabled to use this mode correctly though

clang/test/CodeGenOpenCL/amdgpu-ieee.cl
46–49

Should also check the fast math attributes

This revision now requires changes to proceed.Apr 20 2021, 9:59 AM

The recent change https://reviews.llvm.org/D96280 caused some difficulty for this patch. I would like to have some suggestions.

Basically current FE requires any codegen or target option should be uniquely reproduced from its internal representation. The current patch does not satisfy the requirement. That's why it fails the pre-merge check.

Currently, the internal representation CodeGenOpt.EmitIEEENaNCompliantInsts is not uniquely determined by the command line options -m[no]-amdgpu-ieee. It is also determined by LangOptsRef.NoHonorNaNs. Therefore I cannot regenerate the original command line option by the value of CodeGenOpt.EmitIEEENaNCompliantInsts.

One solution I can think of, is to use -mamdgpu-ieee={default|on|off}. This way I should be able to reproduce the original command line.

Any comments? Thanks.

The recent change https://reviews.llvm.org/D96280 caused some difficulty for this patch. I would like to have some suggestions.

Basically current FE requires any codegen or target option should be uniquely reproduced from its internal representation. The current patch does not satisfy the requirement. That's why it fails the pre-merge check.

Currently, the internal representation CodeGenOpt.EmitIEEENaNCompliantInsts is not uniquely determined by the command line options -m[no]-amdgpu-ieee. It is also determined by LangOptsRef.NoHonorNaNs. Therefore I cannot regenerate the original command line option by the value of CodeGenOpt.EmitIEEENaNCompliantInsts.

These are two independent options. -mno-amdgpu-ieee should require no-nans-fp-math to be used by the driver. The -m flag is an ABI changing option, and we don't implement the semantics required to make it work without knowing there are no signaling nans

One solution I can think of, is to use -mamdgpu-ieee={default|on|off}. This way I should be able to reproduce the original command line.

The default should only be on. Why is this not a problem for every other -m/-mno flag?

clang/include/clang/Basic/CodeGenOptions.def
429–430

This should explain this is setting a bit in the expected default floating point mode register

yaxunl marked an inline comment as done.Apr 20 2021, 10:16 AM
yaxunl added inline comments.
clang/lib/Frontend/CompilerInvocation.cpp
1952

OK I plan to make changes about this. However I need to clarify about when should we add function attribute amdgpu-ieee=false:

  1. when neither -mamdgpu-ieee nor -mno-amdgpu-ieee is specified, we will add func attr amdgpu-ieee=false if LangOptsRef.NoHonorNaNs is true
  1. when -mamdgpu-ieee or -mno-amdgpu-ieee is specified, we will add func attr amdgpu-ieee=false solely based on these two options, disregarding LangOptsRef.NoHonorNaNs

Is that correct?

arsenm added inline comments.Apr 20 2021, 10:19 AM
clang/lib/Frontend/CompilerInvocation.cpp
1952
  1. You should only add the attribute "amdgpu-ieee"="false" if and only if -mno-amdgpu-ieee is used. This is entirely orthogonal to NoHonorNaNs. The default is amdgpu-ieee=true, and there's no need to explicitly mark the function
  2. It is an error to use -mno-amdgpu-ieee without NoHonorNaNs because we do not implement the legalization required to manually quiet signaling nans. We cannot silently drop the use of of this
yaxunl marked 2 inline comments as done.Apr 20 2021, 11:49 AM
yaxunl added inline comments.
clang/lib/Frontend/CompilerInvocation.cpp
1952

I can add diagnostics in clang -cc1 when -mno-amdgpu-ieee is used without NoHonorNaNs. I cannot diagnose it in clang driver because there are multiple driver options affecting NoHonorNaNs and they could override each other.

yaxunl updated this revision to Diff 338975.Apr 20 2021, 1:21 PM
yaxunl marked 4 inline comments as done.
yaxunl edited the summary of this revision. (Show Details)

revised by Matt's comments

arsenm added inline comments.Apr 20 2021, 5:35 PM
clang/include/clang/Basic/DiagnosticDriverKinds.td
132–133

This seems like a confusing message. Equivalent of what?

clang/include/clang/Driver/Options.td
3182

s/Setting a bit/Sets the IEEE bit/

clang/test/CodeGenOpenCL/amdgpu-ieee.cl
21

Typo Hornor

yaxunl updated this revision to Diff 339092.Apr 20 2021, 9:19 PM
yaxunl marked 3 inline comments as done.

revised by Matt's comments

clang/include/clang/Basic/DiagnosticDriverKinds.td
132–133

will fix

clang/include/clang/Driver/Options.td
3182

will do

clang/test/CodeGenOpenCL/amdgpu-ieee.cl
21

will fix

arsenm added inline comments.Apr 29 2021, 7:06 PM
clang/include/clang/Basic/DiagnosticDriverKinds.td
133–135

e.g. and a list of flags seems weird for an error message. How about "only allowed with relaxed NaN handling"?

yaxunl marked an inline comment as done.Apr 30 2021, 7:32 AM
yaxunl added inline comments.
clang/include/clang/Basic/DiagnosticDriverKinds.td
133–135

sounds good. will do. I think users should be able to look up clang options which relax NaN handling.

yaxunl updated this revision to Diff 341900.Apr 30 2021, 7:42 AM
yaxunl marked an inline comment as done.

revised by Matt's comments

arsenm accepted this revision.Apr 30 2021, 4:37 PM
arsenm added inline comments.
clang/include/clang/Driver/Options.td
3185

Maybe also note this is an ABI changing option

This revision is now accepted and ready to land.Apr 30 2021, 4:37 PM
yaxunl marked an inline comment as done.Apr 30 2021, 7:56 PM
yaxunl added inline comments.
clang/include/clang/Driver/Options.td
3185

will do

yaxunl updated this revision to Diff 342111.Apr 30 2021, 8:25 PM
yaxunl marked an inline comment as done.

updated help text and test

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMay 1 2021, 6:04 AM