[llvm-branch-commits] [clang] release/19.x: [X86] Use correct fp immediate types in _mm_set_ss/sd (PR #105638)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Aug 22 03:43:51 PDT 2024


https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/105638

Backport 3b49d274e6f16d1c8db5f4557eb7866a4bafffa5 6dcce422ca06601f2b00e85cc18c745ede245ca6

Requested by: @RKSimon

>From d089263a495098114432a40ddaef17ae90bf7352 Mon Sep 17 00:00:00 2001
From: Simon Pilgrim <llvm-dev at redking.me.uk>
Date: Tue, 20 Aug 2024 11:11:33 +0100
Subject: [PATCH 1/2] [X86] Add clang codegen test coverage for #104848

(cherry picked from commit 3b49d274e6f16d1c8db5f4557eb7866a4bafffa5)
---
 clang/test/CodeGen/X86/strictfp_patterns.c | 32 ++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 clang/test/CodeGen/X86/strictfp_patterns.c

diff --git a/clang/test/CodeGen/X86/strictfp_patterns.c b/clang/test/CodeGen/X86/strictfp_patterns.c
new file mode 100644
index 00000000000000..fd1ecdb262d812
--- /dev/null
+++ b/clang/test/CodeGen/X86/strictfp_patterns.c
@@ -0,0 +1,32 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 %s -O2 -emit-llvm -o - -triple x86_64-unknown-unknown -ffreestanding -ffp-exception-behavior=maytrap -Wall -Werror | FileCheck %s
+
+#include <immintrin.h>
+
+// TODO: PR104848 - ensure the _mm_set_ss/d headers don't implicity promote any integer/fp values.
+
+// CHECK-LABEL: @test_mm_set_ss(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[VECINIT_I:%.*]] = insertelement <4 x float> poison, float [[NUM:%.*]], i64 0
+// CHECK-NEXT:    [[CONV_I:%.*]] = tail call float @llvm.experimental.constrained.sitofp.f32.i32(i32 0, metadata !"round.tonearest", metadata !"fpexcept.maytrap") #[[ATTR2:[0-9]+]]
+// CHECK-NEXT:    [[VECINIT1_I:%.*]] = insertelement <4 x float> [[VECINIT_I]], float [[CONV_I]], i64 1
+// CHECK-NEXT:    [[VECINIT3_I:%.*]] = insertelement <4 x float> [[VECINIT1_I]], float [[CONV_I]], i64 2
+// CHECK-NEXT:    [[VECINIT5_I:%.*]] = insertelement <4 x float> [[VECINIT3_I]], float [[CONV_I]], i64 3
+// CHECK-NEXT:    ret <4 x float> [[VECINIT5_I]]
+//
+__m128 test_mm_set_ss(float num)
+{
+    return _mm_set_ss(num);
+}
+
+// CHECK-LABEL: @test_mm_set_sd(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[VECINIT_I:%.*]] = insertelement <2 x double> poison, double [[NUM:%.*]], i64 0
+// CHECK-NEXT:    [[CONV_I:%.*]] = tail call double @llvm.experimental.constrained.sitofp.f64.i32(i32 0, metadata !"round.tonearest", metadata !"fpexcept.maytrap") #[[ATTR2]]
+// CHECK-NEXT:    [[VECINIT1_I:%.*]] = insertelement <2 x double> [[VECINIT_I]], double [[CONV_I]], i64 1
+// CHECK-NEXT:    ret <2 x double> [[VECINIT1_I]]
+//
+__m128d test_mm_set_sd(double num)
+{
+    return _mm_set_sd(num);
+}

>From 3f9abf1b3c6a32f8a121a64de90df8563a34b920 Mon Sep 17 00:00:00 2001
From: Simon Pilgrim <llvm-dev at redking.me.uk>
Date: Tue, 20 Aug 2024 11:51:18 +0100
Subject: [PATCH 2/2] [X86] Use correct fp immediate types in _mm_set_ss/sd

Avoids implicit sint_to_fp which wasn't occurring on strict fp codegen

Fixes #104848

(cherry picked from commit 6dcce422ca06601f2b00e85cc18c745ede245ca6)
---
 clang/lib/Headers/emmintrin.h              |  2 +-
 clang/lib/Headers/xmmintrin.h              |  2 +-
 clang/test/CodeGen/X86/strictfp_patterns.c | 14 ++++----------
 3 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Headers/emmintrin.h b/clang/lib/Headers/emmintrin.h
index e85bfc47aa5cce..4dff6421350c00 100644
--- a/clang/lib/Headers/emmintrin.h
+++ b/clang/lib/Headers/emmintrin.h
@@ -1771,7 +1771,7 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_undefined_pd(void) {
 ///    lower 64 bits contain the value of the parameter. The upper 64 bits are
 ///    set to zero.
 static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_set_sd(double __w) {
-  return __extension__(__m128d){__w, 0};
+  return __extension__(__m128d){__w, 0.0};
 }
 
 /// Constructs a 128-bit floating-point vector of [2 x double], with each
diff --git a/clang/lib/Headers/xmmintrin.h b/clang/lib/Headers/xmmintrin.h
index 1ef89de9c9f562..6fb27297af9279 100644
--- a/clang/lib/Headers/xmmintrin.h
+++ b/clang/lib/Headers/xmmintrin.h
@@ -1910,7 +1910,7 @@ _mm_undefined_ps(void)
 static __inline__ __m128 __DEFAULT_FN_ATTRS
 _mm_set_ss(float __w)
 {
-  return __extension__ (__m128){ __w, 0, 0, 0 };
+  return __extension__ (__m128){ __w, 0.0f, 0.0f, 0.0f };
 }
 
 /// Constructs a 128-bit floating-point vector of [4 x float], with each
diff --git a/clang/test/CodeGen/X86/strictfp_patterns.c b/clang/test/CodeGen/X86/strictfp_patterns.c
index fd1ecdb262d812..55d85f22c3ba3d 100644
--- a/clang/test/CodeGen/X86/strictfp_patterns.c
+++ b/clang/test/CodeGen/X86/strictfp_patterns.c
@@ -3,16 +3,12 @@
 
 #include <immintrin.h>
 
-// TODO: PR104848 - ensure the _mm_set_ss/d headers don't implicity promote any integer/fp values.
+// PR104848 - ensure the _mm_set_ss/d headers don't implicity promote any integer/fp values.
 
 // CHECK-LABEL: @test_mm_set_ss(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:    [[VECINIT_I:%.*]] = insertelement <4 x float> poison, float [[NUM:%.*]], i64 0
-// CHECK-NEXT:    [[CONV_I:%.*]] = tail call float @llvm.experimental.constrained.sitofp.f32.i32(i32 0, metadata !"round.tonearest", metadata !"fpexcept.maytrap") #[[ATTR2:[0-9]+]]
-// CHECK-NEXT:    [[VECINIT1_I:%.*]] = insertelement <4 x float> [[VECINIT_I]], float [[CONV_I]], i64 1
-// CHECK-NEXT:    [[VECINIT3_I:%.*]] = insertelement <4 x float> [[VECINIT1_I]], float [[CONV_I]], i64 2
-// CHECK-NEXT:    [[VECINIT5_I:%.*]] = insertelement <4 x float> [[VECINIT3_I]], float [[CONV_I]], i64 3
-// CHECK-NEXT:    ret <4 x float> [[VECINIT5_I]]
+// CHECK-NEXT:    [[VECINIT3_I:%.*]] = insertelement <4 x float> <float poison, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00>, float [[NUM:%.*]], i64 0
+// CHECK-NEXT:    ret <4 x float> [[VECINIT3_I]]
 //
 __m128 test_mm_set_ss(float num)
 {
@@ -21,9 +17,7 @@ __m128 test_mm_set_ss(float num)
 
 // CHECK-LABEL: @test_mm_set_sd(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:    [[VECINIT_I:%.*]] = insertelement <2 x double> poison, double [[NUM:%.*]], i64 0
-// CHECK-NEXT:    [[CONV_I:%.*]] = tail call double @llvm.experimental.constrained.sitofp.f64.i32(i32 0, metadata !"round.tonearest", metadata !"fpexcept.maytrap") #[[ATTR2]]
-// CHECK-NEXT:    [[VECINIT1_I:%.*]] = insertelement <2 x double> [[VECINIT_I]], double [[CONV_I]], i64 1
+// CHECK-NEXT:    [[VECINIT1_I:%.*]] = insertelement <2 x double> <double poison, double 0.000000e+00>, double [[NUM:%.*]], i64 0
 // CHECK-NEXT:    ret <2 x double> [[VECINIT1_I]]
 //
 __m128d test_mm_set_sd(double num)



More information about the llvm-branch-commits mailing list