This is an archive of the discontinued LLVM Phabricator instance.

[X86] Add parentheses around casts in some of the X86 intrinsic headers.
ClosedPublic

Authored by craig.topper on Aug 10 2021, 10:08 AM.

Details

Summary

This covers the SSE and AVX/AVX2 headers. AVX512 has a lot more macros
due to rounding mode.

Fixes part of PR51324.

Diff Detail

Event Timeline

craig.topper requested review of this revision.Aug 10 2021, 10:08 AM
craig.topper created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptAug 10 2021, 10:08 AM

Hard to see through all of the lint noise, but seems like a mechanical fix.
Can we add a test like the one in the bug report?
https://godbolt.org/z/sPT8e9vx9

pengfei accepted this revision.Aug 10 2021, 6:16 PM

Thanks Craig. I haven't find time to work on it. I think this is a good start. LGTM.

This revision is now accepted and ready to land.Aug 10 2021, 6:16 PM
rsmith added a subscriber: rsmith.Aug 11 2021, 11:51 AM

I found a few more macro hygiene issues in these headers.

clang/lib/Headers/avx2intrin.h
22–23

Parens missing here still

1093–1094

Parens missing here still.

clang/lib/Headers/smmintrin.h
868–871

This is gross. I wonder if we can use __builtin_bit_cast here instead of a cast through a union.

876

The existing code is the wrong way to define a statement-like macro, but I can't find any documentation (anywhere!) for _MM_EXTRACT_FLOAT to confirm what the expected valid uses are. The existing formulation would not work in contexts such as:

if (1)
  _MM_EXTRACT_FLOAT(d, x, n);
else
  ...

... because the semicolon would terminate the if, and it would incorrectly work in contexts requiring braces such as:

void f(float *pd, __m128 x, int n) _MM_EXTRACT_FLOAT(*pd, x, n)

Fix two functions I missed.

Add test case to the bottom of sse41-builtins.c

Probably want to address the other cleanups in another patch; the parens fixes and test LGTM.

This revision was landed with ongoing or failed builds.Aug 13 2021, 9:46 AM
This revision was automatically updated to reflect the committed changes.