Skip to content

Commit a5509d6

Browse files
authored
[clang] fp options fix for __builtin_convertvector (#134102)
Add missing CGFPOptionsRAII for fptoi and itofp cases
1 parent 4c09ae0 commit a5509d6

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,12 +1969,16 @@ Value *ScalarExprEmitter::VisitConvertVectorExpr(ConvertVectorExpr *E) {
19691969
bool InputSigned = SrcEltType->isSignedIntegerOrEnumerationType();
19701970
if (isa<llvm::IntegerType>(DstEltTy))
19711971
Res = Builder.CreateIntCast(Src, DstTy, InputSigned, "conv");
1972-
else if (InputSigned)
1973-
Res = Builder.CreateSIToFP(Src, DstTy, "conv");
1974-
else
1975-
Res = Builder.CreateUIToFP(Src, DstTy, "conv");
1972+
else {
1973+
CodeGenFunction::CGFPOptionsRAII FPOptions(CGF, E);
1974+
if (InputSigned)
1975+
Res = Builder.CreateSIToFP(Src, DstTy, "conv");
1976+
else
1977+
Res = Builder.CreateUIToFP(Src, DstTy, "conv");
1978+
}
19761979
} else if (isa<llvm::IntegerType>(DstEltTy)) {
19771980
assert(SrcEltTy->isFloatingPointTy() && "Unknown real conversion");
1981+
CodeGenFunction::CGFPOptionsRAII FPOptions(CGF, E);
19781982
if (DstEltType->isSignedIntegerOrEnumerationType())
19791983
Res = Builder.CreateFPToSI(Src, DstTy, "conv");
19801984
else

clang/test/CodeGen/pragma-fenv_access.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,39 @@ vector4float func_21(vector4double x) {
251251
}
252252
// CHECK-LABEL: @func_21
253253
// STRICT: call <4 x float> @llvm.experimental.constrained.fptrunc.v4f32.v4f64(<4 x double> {{.*}}, metadata !"round.upward", metadata !"fpexcept.strict")
254+
255+
typedef short vector8short __attribute__((__vector_size__(16)));
256+
typedef double vector8double __attribute__((__vector_size__(64)));
257+
vector8double func_24(vector8short x) {
258+
#pragma STDC FENV_ROUND FE_TOWARDZERO
259+
return __builtin_convertvector(x, vector8double);
260+
}
261+
// CHECK-LABEL: @func_24
262+
// STRICT: call <8 x double> @llvm.experimental.constrained.sitofp.v8f64.v8i16(<8 x i16> {{.*}}, metadata !"round.towardzero", metadata !"fpexcept.strict")
263+
264+
typedef unsigned int vector16uint __attribute__((__vector_size__(64)));
265+
typedef double vector16double __attribute__((__vector_size__(128)));
266+
vector16double func_25(vector16uint x) {
267+
#pragma STDC FENV_ROUND FE_DOWNWARD
268+
return __builtin_convertvector(x, vector16double);
269+
}
270+
// CHECK-LABEL: @func_25
271+
// STRICT: call <16 x double> @llvm.experimental.constrained.uitofp.v16f64.v16i32(<16 x i32> {{.*}}, metadata !"round.downward", metadata !"fpexcept.strict")
272+
273+
typedef float vector2float __attribute__((__vector_size__(8)));
274+
typedef char vector2char __attribute__((__vector_size__(2)));
275+
vector2char func_22(vector2float x) {
276+
#pragma float_control(except, off)
277+
return __builtin_convertvector(x, vector2char);
278+
}
279+
// CHECK-LABEL: @func_22
280+
// STRICT: call <2 x i8> @llvm.experimental.constrained.fptosi.v2i8.v2f32(<2 x float> {{.*}}, metadata !"fpexcept.ignore")
281+
282+
typedef float vector3float __attribute__((__vector_size__(12)));
283+
typedef unsigned long long vector3ulong __attribute__((__vector_size__(24)));
284+
vector3ulong func_23(vector3float x) {
285+
#pragma float_control(except, off)
286+
return __builtin_convertvector(x, vector3ulong);
287+
}
288+
// CHECK-LABEL: @func_23
289+
// STRICT: call <3 x i64> @llvm.experimental.constrained.fptoui.v3i64.v3f32(<3 x float> {{.*}}, metadata !"fpexcept.ignore")

0 commit comments

Comments
 (0)