[clang] [clang] handle fp options in __builtin_convertvector (PR #125522)

Jakub Ficek via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 5 10:45:59 PST 2025


ficol wrote:

> > > Are fp options (already) handled in constant evaluation?
> > 
> > 
> > I think they are, there are tests for it in https://github.com/llvm/llvm-project/blob/main/clang/test/AST/const-fpfeatures.c and https://github.com/llvm/llvm-project/blob/main/clang/test/AST/const-fpfeatures.cpp
> 
> They don't seem to test vectors though, does `__builtin_convertvector` also handle the new fp options when evaluated at compile time?

It seems to work. I tested it with:

```
typedef float  vector2float  __attribute__((__vector_size__(8)));
typedef double  vector2double  __attribute__((__vector_size__(16)));
const vector2float a = {1.0F + 0x0.000001p0F, 1.0F + 0x0.000002p0F};
const vector2double b = __builtin_convertvector(a, vector2double);
const float c = 1.0F + 0x0.000001p0F;
#pragma STDC FENV_ROUND FE_UPWARD
const vector2float d = {1.0F + 0x0.000001p0F, 1.0F + 0x0.000002p0F};
const vector2double e = __builtin_convertvector(d, vector2double);
const vector2double f = __builtin_convertvector(a, vector2double);
const float g = 1.0F + 0x0.000001p0F;
const double h = g;
const double i = c;
```
and it produces:
```
@a = constant <2 x float> <float 1.000000e+00, float 0x3FF0000020000000>, align 8
@b = constant <2 x double> <double 1.000000e+00, double 0x3FF0000020000000>, align 16
@c = constant float 1.000000e+00, align 4
@d = constant <2 x float> splat (float 0x3FF0000020000000), align 8
@e = constant <2 x double> splat (double 0x3FF0000020000000), align 16
@f = constant <2 x double> <double 1.000000e+00, double 0x3FF0000020000000>, align 16
@g = constant float 0x3FF0000020000000, align 4
@h = constant double 0x3FF0000020000000, align 8
@i = constant double 1.000000e+00, align 8
```
Although, it feels a little bit weird that e and f evaluate to different values but it behaves the same way for h and i with scalar cast.


https://github.com/llvm/llvm-project/pull/125522


More information about the cfe-commits mailing list