Fix test failures introduced by PR #113697 (#116941)
[llvm-project.git] / llvm / unittests / ADT / FloatingPointMode.cpp
blobb87507625542ed43f10f32340a5956f65b992d4c
1 //===- llvm/unittest/ADT/FloatingPointMode.cpp ----------------------------===//
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 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/FloatingPointMode.h"
10 #include "gtest/gtest.h"
12 using namespace llvm;
14 namespace {
16 TEST(FloatingPointModeTest, ParseDenormalFPAttributeComponent) {
17 EXPECT_EQ(DenormalMode::IEEE, parseDenormalFPAttributeComponent("ieee"));
18 EXPECT_EQ(DenormalMode::IEEE, parseDenormalFPAttributeComponent(""));
19 EXPECT_EQ(DenormalMode::PreserveSign,
20 parseDenormalFPAttributeComponent("preserve-sign"));
21 EXPECT_EQ(DenormalMode::PositiveZero,
22 parseDenormalFPAttributeComponent("positive-zero"));
23 EXPECT_EQ(DenormalMode::Dynamic,
24 parseDenormalFPAttributeComponent("dynamic"));
25 EXPECT_EQ(DenormalMode::Invalid, parseDenormalFPAttributeComponent("foo"));
28 TEST(FloatingPointModeTest, DenormalAttributeName) {
29 EXPECT_EQ("ieee", denormalModeKindName(DenormalMode::IEEE));
30 EXPECT_EQ("preserve-sign", denormalModeKindName(DenormalMode::PreserveSign));
31 EXPECT_EQ("positive-zero", denormalModeKindName(DenormalMode::PositiveZero));
32 EXPECT_EQ("dynamic", denormalModeKindName(DenormalMode::Dynamic));
33 EXPECT_EQ("", denormalModeKindName(DenormalMode::Invalid));
36 TEST(FloatingPointModeTest, ParseDenormalFPAttribute) {
37 EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE),
38 parseDenormalFPAttribute("ieee"));
39 EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE),
40 parseDenormalFPAttribute("ieee,ieee"));
41 EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE),
42 parseDenormalFPAttribute("ieee,"));
43 EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE),
44 parseDenormalFPAttribute(""));
45 EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE),
46 parseDenormalFPAttribute(","));
48 EXPECT_EQ(DenormalMode(DenormalMode::PreserveSign, DenormalMode::PreserveSign),
49 parseDenormalFPAttribute("preserve-sign"));
50 EXPECT_EQ(DenormalMode(DenormalMode::PreserveSign, DenormalMode::PreserveSign),
51 parseDenormalFPAttribute("preserve-sign,"));
52 EXPECT_EQ(DenormalMode(DenormalMode::PreserveSign, DenormalMode::PreserveSign),
53 parseDenormalFPAttribute("preserve-sign,preserve-sign"));
55 EXPECT_EQ(DenormalMode(DenormalMode::PositiveZero, DenormalMode::PositiveZero),
56 parseDenormalFPAttribute("positive-zero"));
57 EXPECT_EQ(DenormalMode(DenormalMode::PositiveZero, DenormalMode::PositiveZero),
58 parseDenormalFPAttribute("positive-zero,positive-zero"));
60 EXPECT_EQ(DenormalMode(DenormalMode::Dynamic, DenormalMode::Dynamic),
61 parseDenormalFPAttribute("dynamic"));
62 EXPECT_EQ(DenormalMode(DenormalMode::Dynamic, DenormalMode::Dynamic),
63 parseDenormalFPAttribute("dynamic,dynamic"));
65 EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::PositiveZero),
66 parseDenormalFPAttribute("ieee,positive-zero"));
67 EXPECT_EQ(DenormalMode(DenormalMode::PositiveZero, DenormalMode::IEEE),
68 parseDenormalFPAttribute("positive-zero,ieee"));
70 EXPECT_EQ(DenormalMode(DenormalMode::PreserveSign, DenormalMode::IEEE),
71 parseDenormalFPAttribute("preserve-sign,ieee"));
72 EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::PreserveSign),
73 parseDenormalFPAttribute("ieee,preserve-sign"));
75 EXPECT_EQ(DenormalMode(DenormalMode::Dynamic, DenormalMode::PreserveSign),
76 parseDenormalFPAttribute("dynamic,preserve-sign"));
77 EXPECT_EQ(DenormalMode(DenormalMode::PreserveSign, DenormalMode::Dynamic),
78 parseDenormalFPAttribute("preserve-sign,dynamic"));
80 EXPECT_EQ(DenormalMode(DenormalMode::Invalid, DenormalMode::Invalid),
81 parseDenormalFPAttribute("foo"));
82 EXPECT_EQ(DenormalMode(DenormalMode::Invalid, DenormalMode::Invalid),
83 parseDenormalFPAttribute("foo,foo"));
84 EXPECT_EQ(DenormalMode(DenormalMode::Invalid, DenormalMode::Invalid),
85 parseDenormalFPAttribute("foo,bar"));
88 TEST(FloatingPointModeTest, RenderDenormalFPAttribute) {
89 EXPECT_EQ(DenormalMode(DenormalMode::Invalid, DenormalMode::Invalid),
90 parseDenormalFPAttribute("foo"));
92 EXPECT_EQ("ieee,ieee",
93 DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE).str());
94 EXPECT_EQ(",",
95 DenormalMode(DenormalMode::Invalid, DenormalMode::Invalid).str());
97 EXPECT_EQ(
98 "preserve-sign,preserve-sign",
99 DenormalMode(DenormalMode::PreserveSign, DenormalMode::PreserveSign).str());
101 EXPECT_EQ(
102 "positive-zero,positive-zero",
103 DenormalMode(DenormalMode::PositiveZero, DenormalMode::PositiveZero).str());
105 EXPECT_EQ(
106 "ieee,preserve-sign",
107 DenormalMode(DenormalMode::IEEE, DenormalMode::PreserveSign).str());
109 EXPECT_EQ(
110 "preserve-sign,ieee",
111 DenormalMode(DenormalMode::PreserveSign, DenormalMode::IEEE).str());
113 EXPECT_EQ(
114 "preserve-sign,positive-zero",
115 DenormalMode(DenormalMode::PreserveSign, DenormalMode::PositiveZero).str());
117 EXPECT_EQ("dynamic,dynamic",
118 DenormalMode(DenormalMode::Dynamic, DenormalMode::Dynamic).str());
119 EXPECT_EQ("ieee,dynamic",
120 DenormalMode(DenormalMode::IEEE, DenormalMode::Dynamic).str());
121 EXPECT_EQ("dynamic,ieee",
122 DenormalMode(DenormalMode::Dynamic, DenormalMode::IEEE).str());
125 TEST(FloatingPointModeTest, DenormalModeIsSimple) {
126 EXPECT_TRUE(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE).isSimple());
127 EXPECT_FALSE(DenormalMode(DenormalMode::IEEE,
128 DenormalMode::Invalid).isSimple());
129 EXPECT_FALSE(DenormalMode(DenormalMode::PreserveSign,
130 DenormalMode::PositiveZero).isSimple());
131 EXPECT_FALSE(DenormalMode(DenormalMode::PreserveSign, DenormalMode::Dynamic)
132 .isSimple());
133 EXPECT_FALSE(DenormalMode(DenormalMode::Dynamic, DenormalMode::PreserveSign)
134 .isSimple());
137 TEST(FloatingPointModeTest, DenormalModeIsValid) {
138 EXPECT_TRUE(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE).isValid());
139 EXPECT_FALSE(DenormalMode(DenormalMode::IEEE, DenormalMode::Invalid).isValid());
140 EXPECT_FALSE(DenormalMode(DenormalMode::Invalid, DenormalMode::IEEE).isValid());
141 EXPECT_FALSE(DenormalMode(DenormalMode::Invalid,
142 DenormalMode::Invalid).isValid());
145 TEST(FloatingPointModeTest, DenormalModeConstructor) {
146 EXPECT_EQ(DenormalMode(DenormalMode::Invalid, DenormalMode::Invalid),
147 DenormalMode::getInvalid());
148 EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE),
149 DenormalMode::getIEEE());
150 EXPECT_EQ(DenormalMode::getIEEE(), DenormalMode::getDefault());
151 EXPECT_EQ(DenormalMode(DenormalMode::Dynamic, DenormalMode::Dynamic),
152 DenormalMode::getDynamic());
153 EXPECT_EQ(DenormalMode(DenormalMode::PreserveSign, DenormalMode::PreserveSign),
154 DenormalMode::getPreserveSign());
155 EXPECT_EQ(DenormalMode(DenormalMode::PositiveZero, DenormalMode::PositiveZero),
156 DenormalMode::getPositiveZero());
159 TEST(FloatingPointModeTest, DenormalModeMerge) {
160 EXPECT_EQ(
161 DenormalMode::getInvalid(),
162 DenormalMode::getInvalid().mergeCalleeMode(DenormalMode::getInvalid()));
163 EXPECT_EQ(DenormalMode::getIEEE(), DenormalMode::getInvalid().mergeCalleeMode(
164 DenormalMode::getIEEE()));
165 EXPECT_EQ(DenormalMode::getInvalid(), DenormalMode::getIEEE().mergeCalleeMode(
166 DenormalMode::getInvalid()));
168 EXPECT_EQ(DenormalMode::getIEEE(), DenormalMode::getIEEE().mergeCalleeMode(
169 DenormalMode::getDynamic()));
170 EXPECT_EQ(DenormalMode::getPreserveSign(),
171 DenormalMode::getPreserveSign().mergeCalleeMode(
172 DenormalMode::getDynamic()));
173 EXPECT_EQ(DenormalMode::getPositiveZero(),
174 DenormalMode::getPositiveZero().mergeCalleeMode(
175 DenormalMode::getDynamic()));
176 EXPECT_EQ(
177 DenormalMode::getDynamic(),
178 DenormalMode::getDynamic().mergeCalleeMode(DenormalMode::getDynamic()));
180 EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::PreserveSign),
181 DenormalMode(DenormalMode::IEEE, DenormalMode::PreserveSign)
182 .mergeCalleeMode(
183 DenormalMode(DenormalMode::IEEE, DenormalMode::Dynamic)));
185 EXPECT_EQ(DenormalMode(DenormalMode::PreserveSign, DenormalMode::IEEE),
186 DenormalMode(DenormalMode::PreserveSign, DenormalMode::IEEE)
187 .mergeCalleeMode(
188 DenormalMode(DenormalMode::Dynamic, DenormalMode::IEEE)));
190 EXPECT_EQ(
191 DenormalMode(DenormalMode::PositiveZero, DenormalMode::PreserveSign),
192 DenormalMode(DenormalMode::PositiveZero, DenormalMode::PreserveSign)
193 .mergeCalleeMode(
194 DenormalMode(DenormalMode::Dynamic, DenormalMode::Dynamic)));
196 EXPECT_EQ(
197 DenormalMode(DenormalMode::PositiveZero, DenormalMode::PreserveSign),
198 DenormalMode(DenormalMode::PositiveZero, DenormalMode::PreserveSign)
199 .mergeCalleeMode(
200 DenormalMode(DenormalMode::PositiveZero, DenormalMode::Dynamic)));
202 EXPECT_EQ(
203 DenormalMode(DenormalMode::PositiveZero, DenormalMode::PreserveSign),
204 DenormalMode(DenormalMode::PositiveZero, DenormalMode::PreserveSign)
205 .mergeCalleeMode(
206 DenormalMode(DenormalMode::Dynamic, DenormalMode::PreserveSign)));
208 // Test some invalid / undefined behavior cases
209 EXPECT_EQ(
210 DenormalMode::getPreserveSign(),
211 DenormalMode::getIEEE().mergeCalleeMode(DenormalMode::getPreserveSign()));
212 EXPECT_EQ(
213 DenormalMode::getPreserveSign(),
214 DenormalMode::getIEEE().mergeCalleeMode(DenormalMode::getPreserveSign()));
215 EXPECT_EQ(
216 DenormalMode::getIEEE(),
217 DenormalMode::getPreserveSign().mergeCalleeMode(DenormalMode::getIEEE()));
218 EXPECT_EQ(
219 DenormalMode::getIEEE(),
220 DenormalMode::getPreserveSign().mergeCalleeMode(DenormalMode::getIEEE()));
223 TEST(FloatingPointModeTest, DenormalModePredicates) {
224 EXPECT_TRUE(DenormalMode::getPreserveSign().inputsAreZero());
225 EXPECT_TRUE(DenormalMode::getPositiveZero().inputsAreZero());
226 EXPECT_FALSE(DenormalMode::getIEEE().inputsAreZero());
227 EXPECT_FALSE(DenormalMode::getDynamic().inputsAreZero());