[x86] fix assert with horizontal math + broadcast of vector (PR43402)
[llvm-core.git] / lib / Target / X86 / X86InstrFMA3Info.h
blob7fa6f5917862d5d18bd3f0a11c6793cc7b47a8fa
1 //===- X86InstrFMA3Info.h - X86 FMA3 Instruction Information ----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains the implementation of the classes providing information
10 // about existing X86 FMA3 opcodes, classifying and grouping them.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_X86_UTILS_X86INSTRFMA3INFO_H
15 #define LLVM_LIB_TARGET_X86_UTILS_X86INSTRFMA3INFO_H
17 #include "X86.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include <cassert>
20 #include <cstdint>
21 #include <set>
23 namespace llvm {
25 /// This class is used to group {132, 213, 231} forms of FMA opcodes together.
26 /// Each of the groups has either 3 opcodes, Also, each group has an attributes
27 /// field describing it.
28 struct X86InstrFMA3Group {
29 /// An array holding 3 forms of FMA opcodes.
30 uint16_t Opcodes[3];
32 /// This bitfield specifies the attributes associated with the created
33 /// FMA groups of opcodes.
34 uint16_t Attributes;
36 enum {
37 Form132,
38 Form213,
39 Form231,
42 enum : uint16_t {
43 /// This bit must be set in the 'Attributes' field of FMA group if such
44 /// group of FMA opcodes consists of FMA intrinsic opcodes.
45 Intrinsic = 0x1,
47 /// This bit must be set in the 'Attributes' field of FMA group if such
48 /// group of FMA opcodes consists of AVX512 opcodes accepting a k-mask and
49 /// passing the elements from the 1st operand to the result of the operation
50 /// when the correpondings bits in the k-mask are unset.
51 KMergeMasked = 0x2,
53 /// This bit must be set in the 'Attributes' field of FMA group if such
54 /// group of FMA opcodes consists of AVX512 opcodes accepting a k-zeromask.
55 KZeroMasked = 0x4,
58 /// Returns the 132 form of FMA opcode.
59 unsigned get132Opcode() const {
60 return Opcodes[Form132];
63 /// Returns the 213 form of FMA opcode.
64 unsigned get213Opcode() const {
65 return Opcodes[Form213];
68 /// Returns the 231 form of FMA opcode.
69 unsigned get231Opcode() const {
70 return Opcodes[Form231];
73 /// Returns true iff the group of FMA opcodes holds intrinsic opcodes.
74 bool isIntrinsic() const { return (Attributes & Intrinsic) != 0; }
76 /// Returns true iff the group of FMA opcodes holds k-merge-masked opcodes.
77 bool isKMergeMasked() const {
78 return (Attributes & KMergeMasked) != 0;
81 /// Returns true iff the group of FMA opcodes holds k-zero-masked opcodes.
82 bool isKZeroMasked() const { return (Attributes &KZeroMasked) != 0; }
84 /// Returns true iff the group of FMA opcodes holds any of k-masked opcodes.
85 bool isKMasked() const {
86 return (Attributes & (KMergeMasked | KZeroMasked)) != 0;
89 bool operator<(const X86InstrFMA3Group &RHS) const {
90 return Opcodes[0] < RHS.Opcodes[0];
94 /// Returns a reference to a group of FMA3 opcodes to where the given
95 /// \p Opcode is included. If the given \p Opcode is not recognized as FMA3
96 /// and not included into any FMA3 group, then nullptr is returned.
97 const X86InstrFMA3Group *getFMA3Group(unsigned Opcode, uint64_t TSFlags);
99 } // end namespace llvm
101 #endif // LLVM_LIB_TARGET_X86_UTILS_X86INSTRFMA3INFO_H