Skip to content

Commit 9e9971b

Browse files
committed
[PatternMatchTest] Use APInt::getAllOnes() (NFC)
Split out from #80309 to avoid assertion failures in the future.
1 parent 67e19e5 commit 9e9971b

File tree

1 file changed

+101
-101
lines changed

1 file changed

+101
-101
lines changed

llvm/unittests/IR/PatternMatch.cpp

+101-101
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ TEST_F(PatternMatchTest, SpecificIntEQ) {
7171

7272
Value *Zero = ConstantInt::get(IntTy, 0);
7373
Value *One = ConstantInt::get(IntTy, 1);
74-
Value *NegOne = ConstantInt::get(IntTy, -1);
74+
Value *NegOne = Constant::getAllOnesValue(IntTy);
7575

7676
EXPECT_TRUE(
7777
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ, APInt(BitWidth, 0))
@@ -93,15 +93,15 @@ TEST_F(PatternMatchTest, SpecificIntEQ) {
9393
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ, APInt(BitWidth, 1))
9494
.match(NegOne));
9595

96-
EXPECT_FALSE(
97-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ, APInt(BitWidth, -1))
98-
.match(Zero));
99-
EXPECT_FALSE(
100-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ, APInt(BitWidth, -1))
101-
.match(One));
102-
EXPECT_TRUE(
103-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ, APInt(BitWidth, -1))
104-
.match(NegOne));
96+
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ,
97+
APInt::getAllOnes(BitWidth))
98+
.match(Zero));
99+
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ,
100+
APInt::getAllOnes(BitWidth))
101+
.match(One));
102+
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ,
103+
APInt::getAllOnes(BitWidth))
104+
.match(NegOne));
105105
}
106106

107107
TEST_F(PatternMatchTest, SpecificIntNE) {
@@ -110,7 +110,7 @@ TEST_F(PatternMatchTest, SpecificIntNE) {
110110

111111
Value *Zero = ConstantInt::get(IntTy, 0);
112112
Value *One = ConstantInt::get(IntTy, 1);
113-
Value *NegOne = ConstantInt::get(IntTy, -1);
113+
Value *NegOne = Constant::getAllOnesValue(IntTy);
114114

115115
EXPECT_FALSE(
116116
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE, APInt(BitWidth, 0))
@@ -132,15 +132,15 @@ TEST_F(PatternMatchTest, SpecificIntNE) {
132132
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE, APInt(BitWidth, 1))
133133
.match(NegOne));
134134

135-
EXPECT_TRUE(
136-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE, APInt(BitWidth, -1))
137-
.match(Zero));
138-
EXPECT_TRUE(
139-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE, APInt(BitWidth, -1))
140-
.match(One));
141-
EXPECT_FALSE(
142-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE, APInt(BitWidth, -1))
143-
.match(NegOne));
135+
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE,
136+
APInt::getAllOnes(BitWidth))
137+
.match(Zero));
138+
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE,
139+
APInt::getAllOnes(BitWidth))
140+
.match(One));
141+
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE,
142+
APInt::getAllOnes(BitWidth))
143+
.match(NegOne));
144144
}
145145

146146
TEST_F(PatternMatchTest, SpecificIntUGT) {
@@ -149,7 +149,7 @@ TEST_F(PatternMatchTest, SpecificIntUGT) {
149149

150150
Value *Zero = ConstantInt::get(IntTy, 0);
151151
Value *One = ConstantInt::get(IntTy, 1);
152-
Value *NegOne = ConstantInt::get(IntTy, -1);
152+
Value *NegOne = Constant::getAllOnesValue(IntTy);
153153

154154
EXPECT_FALSE(
155155
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT, APInt(BitWidth, 0))
@@ -171,23 +171,23 @@ TEST_F(PatternMatchTest, SpecificIntUGT) {
171171
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT, APInt(BitWidth, 1))
172172
.match(NegOne));
173173

174-
EXPECT_FALSE(
175-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT, APInt(BitWidth, -1))
176-
.match(Zero));
177-
EXPECT_FALSE(
178-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT, APInt(BitWidth, -1))
179-
.match(One));
180-
EXPECT_FALSE(
181-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT, APInt(BitWidth, -1))
182-
.match(NegOne));
174+
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT,
175+
APInt::getAllOnes(BitWidth))
176+
.match(Zero));
177+
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT,
178+
APInt::getAllOnes(BitWidth))
179+
.match(One));
180+
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT,
181+
APInt::getAllOnes(BitWidth))
182+
.match(NegOne));
183183
}
184184

185185
TEST_F(PatternMatchTest, SignbitZeroChecks) {
186186
Type *IntTy = IRB.getInt32Ty();
187187

188188
Value *Zero = ConstantInt::get(IntTy, 0);
189189
Value *One = ConstantInt::get(IntTy, 1);
190-
Value *NegOne = ConstantInt::get(IntTy, -1);
190+
Value *NegOne = Constant::getAllOnesValue(IntTy);
191191

192192
EXPECT_TRUE(m_Negative().match(NegOne));
193193
EXPECT_FALSE(m_NonNegative().match(NegOne));
@@ -211,7 +211,7 @@ TEST_F(PatternMatchTest, SpecificIntUGE) {
211211

212212
Value *Zero = ConstantInt::get(IntTy, 0);
213213
Value *One = ConstantInt::get(IntTy, 1);
214-
Value *NegOne = ConstantInt::get(IntTy, -1);
214+
Value *NegOne = Constant::getAllOnesValue(IntTy);
215215

216216
EXPECT_TRUE(
217217
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE, APInt(BitWidth, 0))
@@ -233,15 +233,15 @@ TEST_F(PatternMatchTest, SpecificIntUGE) {
233233
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE, APInt(BitWidth, 1))
234234
.match(NegOne));
235235

236-
EXPECT_FALSE(
237-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE, APInt(BitWidth, -1))
238-
.match(Zero));
239-
EXPECT_FALSE(
240-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE, APInt(BitWidth, -1))
241-
.match(One));
242-
EXPECT_TRUE(
243-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE, APInt(BitWidth, -1))
244-
.match(NegOne));
236+
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE,
237+
APInt::getAllOnes(BitWidth))
238+
.match(Zero));
239+
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE,
240+
APInt::getAllOnes(BitWidth))
241+
.match(One));
242+
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE,
243+
APInt::getAllOnes(BitWidth))
244+
.match(NegOne));
245245
}
246246

247247
TEST_F(PatternMatchTest, SpecificIntULT) {
@@ -250,7 +250,7 @@ TEST_F(PatternMatchTest, SpecificIntULT) {
250250

251251
Value *Zero = ConstantInt::get(IntTy, 0);
252252
Value *One = ConstantInt::get(IntTy, 1);
253-
Value *NegOne = ConstantInt::get(IntTy, -1);
253+
Value *NegOne = Constant::getAllOnesValue(IntTy);
254254

255255
EXPECT_FALSE(
256256
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT, APInt(BitWidth, 0))
@@ -272,15 +272,15 @@ TEST_F(PatternMatchTest, SpecificIntULT) {
272272
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT, APInt(BitWidth, 1))
273273
.match(NegOne));
274274

275-
EXPECT_TRUE(
276-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT, APInt(BitWidth, -1))
277-
.match(Zero));
278-
EXPECT_TRUE(
279-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT, APInt(BitWidth, -1))
280-
.match(One));
281-
EXPECT_FALSE(
282-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT, APInt(BitWidth, -1))
283-
.match(NegOne));
275+
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT,
276+
APInt::getAllOnes(BitWidth))
277+
.match(Zero));
278+
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT,
279+
APInt::getAllOnes(BitWidth))
280+
.match(One));
281+
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT,
282+
APInt::getAllOnes(BitWidth))
283+
.match(NegOne));
284284
}
285285

286286
TEST_F(PatternMatchTest, SpecificIntULE) {
@@ -289,7 +289,7 @@ TEST_F(PatternMatchTest, SpecificIntULE) {
289289

290290
Value *Zero = ConstantInt::get(IntTy, 0);
291291
Value *One = ConstantInt::get(IntTy, 1);
292-
Value *NegOne = ConstantInt::get(IntTy, -1);
292+
Value *NegOne = Constant::getAllOnesValue(IntTy);
293293

294294
EXPECT_TRUE(
295295
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE, APInt(BitWidth, 0))
@@ -311,15 +311,15 @@ TEST_F(PatternMatchTest, SpecificIntULE) {
311311
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE, APInt(BitWidth, 1))
312312
.match(NegOne));
313313

314-
EXPECT_TRUE(
315-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE, APInt(BitWidth, -1))
316-
.match(Zero));
317-
EXPECT_TRUE(
318-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE, APInt(BitWidth, -1))
319-
.match(One));
320-
EXPECT_TRUE(
321-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE, APInt(BitWidth, -1))
322-
.match(NegOne));
314+
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE,
315+
APInt::getAllOnes(BitWidth))
316+
.match(Zero));
317+
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE,
318+
APInt::getAllOnes(BitWidth))
319+
.match(One));
320+
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE,
321+
APInt::getAllOnes(BitWidth))
322+
.match(NegOne));
323323
}
324324

325325
TEST_F(PatternMatchTest, SpecificIntSGT) {
@@ -328,7 +328,7 @@ TEST_F(PatternMatchTest, SpecificIntSGT) {
328328

329329
Value *Zero = ConstantInt::get(IntTy, 0);
330330
Value *One = ConstantInt::get(IntTy, 1);
331-
Value *NegOne = ConstantInt::get(IntTy, -1);
331+
Value *NegOne = Constant::getAllOnesValue(IntTy);
332332

333333
EXPECT_FALSE(
334334
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT, APInt(BitWidth, 0))
@@ -350,15 +350,15 @@ TEST_F(PatternMatchTest, SpecificIntSGT) {
350350
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT, APInt(BitWidth, 1))
351351
.match(NegOne));
352352

353-
EXPECT_TRUE(
354-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT, APInt(BitWidth, -1))
355-
.match(Zero));
356-
EXPECT_TRUE(
357-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT, APInt(BitWidth, -1))
358-
.match(One));
359-
EXPECT_FALSE(
360-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT, APInt(BitWidth, -1))
361-
.match(NegOne));
353+
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT,
354+
APInt::getAllOnes(BitWidth))
355+
.match(Zero));
356+
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT,
357+
APInt::getAllOnes(BitWidth))
358+
.match(One));
359+
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT,
360+
APInt::getAllOnes(BitWidth))
361+
.match(NegOne));
362362
}
363363

364364
TEST_F(PatternMatchTest, SpecificIntSGE) {
@@ -367,7 +367,7 @@ TEST_F(PatternMatchTest, SpecificIntSGE) {
367367

368368
Value *Zero = ConstantInt::get(IntTy, 0);
369369
Value *One = ConstantInt::get(IntTy, 1);
370-
Value *NegOne = ConstantInt::get(IntTy, -1);
370+
Value *NegOne = Constant::getAllOnesValue(IntTy);
371371

372372
EXPECT_TRUE(
373373
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE, APInt(BitWidth, 0))
@@ -389,15 +389,15 @@ TEST_F(PatternMatchTest, SpecificIntSGE) {
389389
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE, APInt(BitWidth, 1))
390390
.match(NegOne));
391391

392-
EXPECT_TRUE(
393-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE, APInt(BitWidth, -1))
394-
.match(Zero));
395-
EXPECT_TRUE(
396-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE, APInt(BitWidth, -1))
397-
.match(One));
398-
EXPECT_TRUE(
399-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE, APInt(BitWidth, -1))
400-
.match(NegOne));
392+
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE,
393+
APInt::getAllOnes(BitWidth))
394+
.match(Zero));
395+
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE,
396+
APInt::getAllOnes(BitWidth))
397+
.match(One));
398+
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE,
399+
APInt::getAllOnes(BitWidth))
400+
.match(NegOne));
401401
}
402402

403403
TEST_F(PatternMatchTest, SpecificIntSLT) {
@@ -406,7 +406,7 @@ TEST_F(PatternMatchTest, SpecificIntSLT) {
406406

407407
Value *Zero = ConstantInt::get(IntTy, 0);
408408
Value *One = ConstantInt::get(IntTy, 1);
409-
Value *NegOne = ConstantInt::get(IntTy, -1);
409+
Value *NegOne = Constant::getAllOnesValue(IntTy);
410410

411411
EXPECT_FALSE(
412412
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT, APInt(BitWidth, 0))
@@ -428,15 +428,15 @@ TEST_F(PatternMatchTest, SpecificIntSLT) {
428428
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT, APInt(BitWidth, 1))
429429
.match(NegOne));
430430

431-
EXPECT_FALSE(
432-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT, APInt(BitWidth, -1))
433-
.match(Zero));
434-
EXPECT_FALSE(
435-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT, APInt(BitWidth, -1))
436-
.match(One));
437-
EXPECT_FALSE(
438-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT, APInt(BitWidth, -1))
439-
.match(NegOne));
431+
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT,
432+
APInt::getAllOnes(BitWidth))
433+
.match(Zero));
434+
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT,
435+
APInt::getAllOnes(BitWidth))
436+
.match(One));
437+
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT,
438+
APInt::getAllOnes(BitWidth))
439+
.match(NegOne));
440440
}
441441

442442
TEST_F(PatternMatchTest, SpecificIntSLE) {
@@ -445,7 +445,7 @@ TEST_F(PatternMatchTest, SpecificIntSLE) {
445445

446446
Value *Zero = ConstantInt::get(IntTy, 0);
447447
Value *One = ConstantInt::get(IntTy, 1);
448-
Value *NegOne = ConstantInt::get(IntTy, -1);
448+
Value *NegOne = Constant::getAllOnesValue(IntTy);
449449

450450
EXPECT_TRUE(
451451
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE, APInt(BitWidth, 0))
@@ -467,15 +467,15 @@ TEST_F(PatternMatchTest, SpecificIntSLE) {
467467
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE, APInt(BitWidth, 1))
468468
.match(NegOne));
469469

470-
EXPECT_FALSE(
471-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE, APInt(BitWidth, -1))
472-
.match(Zero));
473-
EXPECT_FALSE(
474-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE, APInt(BitWidth, -1))
475-
.match(One));
476-
EXPECT_TRUE(
477-
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE, APInt(BitWidth, -1))
478-
.match(NegOne));
470+
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE,
471+
APInt::getAllOnes(BitWidth))
472+
.match(Zero));
473+
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE,
474+
APInt::getAllOnes(BitWidth))
475+
.match(One));
476+
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE,
477+
APInt::getAllOnes(BitWidth))
478+
.match(NegOne));
479479
}
480480

481481
TEST_F(PatternMatchTest, Unless) {

0 commit comments

Comments
 (0)