[PATCH] D108612: [X86] Building constant vector which element type is half will cause assertion fail.
LiuChen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 23 23:03:26 PDT 2021
LiuChen3 created this revision.
Herald added subscribers: pengfei, hiraditya.
LiuChen3 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Fix assertion fail when building con constant vector which element type is half.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D108612
Files:
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/build_fp16_constant_vector.ll
Index: llvm/test/CodeGen/X86/build_fp16_constant_vector.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/build_fp16_constant_vector.ll
@@ -0,0 +1,30 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+avx512fp16 | FileCheck %s --check-prefixes=CHECK-32
+; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx512fp16 | FileCheck %s --check-prefixes=CHECK-64
+
+define dso_local <32 x half> @foo(<32 x half> %a, <32 x half> %b, <32 x half> %c) {
+; CHECK-32-LABEL: foo:
+; CHECK-32: # %bb.0: # %entry
+; CHECK-32-NEXT: vbroadcastf64x4 {{.*#+}} zmm3 = [1.0E+0,1.0E+0,1.0E+0,1.0E+0,1.0E+0,1.0E+0,1.0E+0,1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0,1.0E+0,1.0E+0,1.0E+0,1.0E+0,1.0E+0,1.0E+0,1.0E+0,1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0]
+; CHECK-32-NEXT: # zmm3 = mem[0,1,2,3,0,1,2,3]
+; CHECK-32-NEXT: vfmadd213ph %zmm2, %zmm3, %zmm0
+; CHECK-32-NEXT: vfmadd213ph %zmm2, %zmm3, %zmm1
+; CHECK-32-NEXT: vaddph %zmm1, %zmm0, %zmm0
+; CHECK-32-NEXT: retl
+;
+; CHECK-64-LABEL: foo:
+; CHECK-64: # %bb.0: # %entry
+; CHECK-64-NEXT: vbroadcastf64x4 {{.*#+}} zmm3 = [1.0E+0,1.0E+0,1.0E+0,1.0E+0,1.0E+0,1.0E+0,1.0E+0,1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0,1.0E+0,1.0E+0,1.0E+0,1.0E+0,1.0E+0,1.0E+0,1.0E+0,1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0,-1.0E+0]
+; CHECK-64-NEXT: # zmm3 = mem[0,1,2,3,0,1,2,3]
+; CHECK-64-NEXT: vfmadd213ph %zmm2, %zmm3, %zmm0
+; CHECK-64-NEXT: vfmadd213ph %zmm2, %zmm3, %zmm1
+; CHECK-64-NEXT: vaddph %zmm1, %zmm0, %zmm0
+; CHECK-64-NEXT: retq
+entry:
+ %0 = tail call fast <32 x half> @llvm.fma.v32f16(<32 x half> %a, <32 x half> <half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xHBC00, half 0xHBC00, half 0xHBC00, half 0xHBC00, half 0xHBC00, half 0xHBC00, half 0xHBC00, half 0xHBC00, half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xHBC00, half 0xHBC00, half 0xHBC00, half 0xHBC00, half 0xHBC00, half 0xHBC00, half 0xHBC00, half 0xHBC00>, <32 x half> %c)
+ %1 = tail call fast <32 x half> @llvm.fma.v32f16(<32 x half> %b, <32 x half> <half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xHBC00, half 0xHBC00, half 0xHBC00, half 0xHBC00, half 0xHBC00, half 0xHBC00, half 0xHBC00, half 0xHBC00, half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xHBC00, half 0xHBC00, half 0xHBC00, half 0xHBC00, half 0xHBC00, half 0xHBC00, half 0xHBC00, half 0xHBC00>, <32 x half> %c)
+ %2 = fadd <32 x half> %0, %1
+ ret <32 x half> %2
+}
+
+declare <32 x half> @llvm.fma.v32f16(<32 x half>, <32 x half>, <32 x half>)
Index: llvm/lib/Target/X86/X86ISelLowering.cpp
===================================================================
--- llvm/lib/Target/X86/X86ISelLowering.cpp
+++ llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -9006,7 +9006,9 @@
APInt Val = SplatValue.extractBits(ScalarSize, ScalarSize * i);
Constant *Const;
if (VT.isFloatingPoint()) {
- if (ScalarSize == 32) {
+ if (ScalarSize == 16)
+ Const = ConstantFP::get(C, APFloat(APFloat::IEEEhalf(), Val));
+ else if (ScalarSize == 32) {
Const = ConstantFP::get(C, APFloat(APFloat::IEEEsingle(), Val));
} else {
assert(ScalarSize == 64 && "Unsupported floating point scalar size");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108612.368279.patch
Type: text/x-patch
Size: 3695 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210824/1c2c8346/attachment.bin>
More information about the llvm-commits
mailing list