This is an archive of the discontinued LLVM Phabricator instance.

Turn off fp reassociation in IA intrinsic header files.
AbandonedPublic

Authored by kbsmith1 on Jul 28 2021, 2:16 PM.

Details

Summary

This change uses #pragma float_control and
pragma clang fp reassociate(off) directives to turn off
floating point fast-math reassociation flags for IA intrinsics
that happen to be implemented using LLVM IR's regular FP
operations.

This change was done to prevent reassociation from happening
across separate intrinsic calls, an optimization that looks like something
an intrinsic programmer would not expect.

Diff Detail

Event Timeline

kbsmith1 requested review of this revision.Jul 28 2021, 2:16 PM
kbsmith1 created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJul 28 2021, 2:16 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
kbsmith1 edited the summary of this revision. (Show Details)Jul 28 2021, 2:19 PM

Patch description states what the change is, but not why the change is what it is.
I don't think this is a good direction to second-guess the user's intentions.

kbsmith1 edited the summary of this revision. (Show Details)Jul 28 2021, 2:58 PM

Patch description states what the change is, but not why the change is what it is.
I don't think this is a good direction to second-guess the user's intentions.

I added the reason for the change to the description. I think when a user programs
t = _mm_add_ps(a, b);
t = _mm_sub_ps(t, b);

that they truly did want those intrinsics evaluated like they were written, even with
fast math flags. This change to the intrinsic headers makes programming with intrinsics
more accurately reflect what the user wrote, even when fast math flags are used.

craig.topper added inline comments.Jul 28 2021, 11:38 PM
clang/lib/Headers/emmintrin.h
13

inrinsics->intrinsics

clang/lib/Headers/xmmintrin.h
13

inrinsics->intrinsics

RKSimon requested changes to this revision.Jul 29 2021, 3:11 AM

I really don't support this change - -ffast-math should be allowed to perform aggressive folds and it makes no sense to make an exception for common intrinsics like these.

We should just ensure the intrinsics are suitably documented to warn that they are affected by fast math flags like any other operation.

An alternative, if you have specific (and common) use cases, would be to add an opt-in command line switch that disables fast math flags on intrinsics.

This revision now requires changes to proceed.Jul 29 2021, 3:11 AM
kbsmith1 abandoned this revision.Aug 2 2021, 3:19 PM

Doesn't seem to have community support, abandoning.