diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index 886dbf976f4514..10cb28a0b37d4a 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -795,6 +795,13 @@ void LazyValueInfoImpl::intersectAssumeOrGuardBlockValueConstantRange( } } +static ConstantRange getConstantRangeOrFull(const ValueLatticeElement &Val, + Type *Ty, const DataLayout &DL) { + if (Val.isConstantRange()) + return Val.getConstantRange(); + return ConstantRange::getFull(DL.getTypeSizeInBits(Ty)); +} + Optional LazyValueInfoImpl::solveBlockValueSelect( SelectInst *SI, BasicBlock *BB) { // Recurse on our inputs if needed @@ -810,9 +817,11 @@ Optional LazyValueInfoImpl::solveBlockValueSelect( return None; ValueLatticeElement &FalseVal = *OptFalseVal; - if (TrueVal.isConstantRange() && FalseVal.isConstantRange()) { - const ConstantRange &TrueCR = TrueVal.getConstantRange(); - const ConstantRange &FalseCR = FalseVal.getConstantRange(); + if (TrueVal.isConstantRange() || FalseVal.isConstantRange()) { + const ConstantRange &TrueCR = + getConstantRangeOrFull(TrueVal, SI->getType(), DL); + const ConstantRange &FalseCR = + getConstantRangeOrFull(FalseVal, SI->getType(), DL); Value *LHS = nullptr; Value *RHS = nullptr; SelectPatternResult SPR = matchSelectPattern(SI, LHS, RHS); @@ -879,13 +888,7 @@ Optional LazyValueInfoImpl::getRangeFor(Value *V, Optional OptVal = getBlockValue(V, BB, CxtI); if (!OptVal) return None; - - ValueLatticeElement &Val = *OptVal; - if (Val.isConstantRange()) - return Val.getConstantRange(); - - const unsigned OperandBitWidth = DL.getTypeSizeInBits(V->getType()); - return ConstantRange::getFull(OperandBitWidth); + return getConstantRangeOrFull(*OptVal, V->getType(), DL); } Optional LazyValueInfoImpl::solveBlockValueCast( diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/basic.ll b/llvm/test/Transforms/CorrelatedValuePropagation/basic.ll index 2110cf4b3847e4..e8cf350216611a 100644 --- a/llvm/test/Transforms/CorrelatedValuePropagation/basic.ll +++ b/llvm/test/Transforms/CorrelatedValuePropagation/basic.ll @@ -649,8 +649,7 @@ define i1 @umin_lhs_overdefined_rhs_range(i32 %a, i32 %b) { ; CHECK-NEXT: call void @llvm.assume(i1 [[ASSUME]]) ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[A:%.*]], [[B]] ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 [[A]], i32 [[B]] -; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i32 [[SEL]], 42 -; CHECK-NEXT: ret i1 [[CMP2]] +; CHECK-NEXT: ret i1 true ; %assume = icmp ult i32 %b, 42 call void @llvm.assume(i1 %assume)