This is an archive of the discontinued LLVM Phabricator instance.

[SPIR] Add support for __arithmetic_fence builtin for SPIR target.
ClosedPublic

Authored by zahiraam on Jan 25 2023, 2:21 PM.

Details

Summary

__arithmetic_fence enforces ordering on expression evaluation when fast math is enabled.
In fast math mode some floating-point optimizations are performed such as reassociation and distribution.

For example, the compiler may transform (a+b)+c into a+(b+c). Although these two expressions are
equivalent in integer arithmetic, they may not be in floating-point arithmetic. The builtin tells the compiler that
the expression in parenthesis can’t be re-associated or distributed.
__arithmetic_fence(a+b)+c is not equivalent to a+(b+c).

This patch adds the support of the builtin to SPIR target.

Diff Detail

Event Timeline

zahiraam created this revision.Jan 25 2023, 2:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 25 2023, 2:21 PM
zahiraam requested review of this revision.Jan 25 2023, 2:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 25 2023, 2:21 PM
bader added a comment.Jan 25 2023, 2:26 PM

"[SPIR-V] Add support for arithmetic_fence builtin for SYCL targets." -> "[SPIR] Add support for arithmetic_fence builtin for SPIR target."

clang/test/CodeGen/arithmetic-fence-builtin.c
16
74

What is different for SPIR target here?

clang/test/Sema/arithmetic-fence-builtin.c
5
zahiraam retitled this revision from [SPIR-V] Add support for __arithmetic_fence builtin for SYCL targets. to [SPIR] Add support for __arithmetic_fence builtin for SPIR targets..Jan 26 2023, 4:48 AM
zahiraam retitled this revision from [SPIR] Add support for __arithmetic_fence builtin for SPIR targets. to [SPIR] Add support for __arithmetic_fence builtin for SPIR target..
zahiraam updated this revision to Diff 492410.Jan 26 2023, 5:41 AM
zahiraam marked 3 inline comments as done.
zahiraam edited the summary of this revision. (Show Details)
bader added inline comments.Jan 26 2023, 8:21 AM
clang/test/CodeGen/arithmetic-fence-builtin.c
74

Why is this check removed for SPIR target?

zahiraam updated this revision to Diff 492483.Jan 26 2023, 9:20 AM
zahiraam added inline comments.
clang/test/CodeGen/arithmetic-fence-builtin.c
74

The RUN at line 16 with -DFAST would generate a warning: "#pragma float_control is not supported on this target". That's why I separated that check from the others.

74

Added.

bader accepted this revision.Jan 26 2023, 9:27 AM

LGTM. Thanks!

This revision is now accepted and ready to land.Jan 26 2023, 9:27 AM

LGTM. Thanks!

Thanks.

This revision was landed with ongoing or failed builds.Jan 26 2023, 11:18 AM
This revision was automatically updated to reflect the committed changes.