@@ -281,18 +281,21 @@ class ValueLatticeElement {
281
281
return std::nullopt;
282
282
}
283
283
284
- ConstantRange asConstantRange (Type *Ty, bool UndefAllowed = false ) const {
285
- assert (Ty->isIntOrIntVectorTy () && " Must be integer type" );
284
+ ConstantRange asConstantRange (unsigned BW, bool UndefAllowed = false ) const {
286
285
if (isConstantRange (UndefAllowed))
287
286
return getConstantRange ();
288
287
if (isConstant ())
289
288
return getConstant ()->toConstantRange ();
290
- unsigned BW = Ty->getScalarSizeInBits ();
291
289
if (isUnknown ())
292
290
return ConstantRange::getEmpty (BW);
293
291
return ConstantRange::getFull (BW);
294
292
}
295
293
294
+ ConstantRange asConstantRange (Type *Ty, bool UndefAllowed = false ) const {
295
+ assert (Ty->isIntOrIntVectorTy () && " Must be integer type" );
296
+ return asConstantRange (Ty->getScalarSizeInBits (), UndefAllowed);
297
+ }
298
+
296
299
bool markOverdefined () {
297
300
if (isOverdefined ())
298
301
return false ;
@@ -384,7 +387,9 @@ class ValueLatticeElement {
384
387
return true ;
385
388
}
386
389
387
- assert (isUnknown () || isUndef ());
390
+ assert (isUnknown () || isUndef () || isConstant ());
391
+ assert ((!isConstant () || NewR.contains (getConstant ()->toConstantRange ())) &&
392
+ " Constant must be subset of new range" );
388
393
389
394
NumRangeExtensions = 0 ;
390
395
Tag = NewTag;
@@ -426,6 +431,16 @@ class ValueLatticeElement {
426
431
return false ;
427
432
if (RHS.isUndef ())
428
433
return false ;
434
+ // If the constant is a vector of integers, try to treat it as a range.
435
+ if (getConstant ()->getType ()->isVectorTy () &&
436
+ getConstant ()->getType ()->getScalarType ()->isIntegerTy ()) {
437
+ ConstantRange L = getConstant ()->toConstantRange ();
438
+ ConstantRange NewR = L.unionWith (
439
+ RHS.asConstantRange (L.getBitWidth (), /* UndefAllowed=*/ true ));
440
+ return markConstantRange (
441
+ std::move (NewR),
442
+ Opts.setMayIncludeUndef (RHS.isConstantRangeIncludingUndef ()));
443
+ }
429
444
markOverdefined ();
430
445
return true ;
431
446
}
@@ -444,14 +459,9 @@ class ValueLatticeElement {
444
459
return OldTag != Tag;
445
460
}
446
461
447
- if (!RHS.isConstantRange ()) {
448
- // We can get here if we've encountered a constantexpr of integer type
449
- // and merge it with a constantrange.
450
- markOverdefined ();
451
- return true ;
452
- }
453
-
454
- ConstantRange NewR = getConstantRange ().unionWith (RHS.getConstantRange ());
462
+ const ConstantRange &L = getConstantRange ();
463
+ ConstantRange NewR = L.unionWith (
464
+ RHS.asConstantRange (L.getBitWidth (), /* UndefAllowed=*/ true ));
455
465
return markConstantRange (
456
466
std::move (NewR),
457
467
Opts.setMayIncludeUndef (RHS.isConstantRangeIncludingUndef ()));
0 commit comments