[LVI] Don't bail on overdefined value in select

Even if one of the operands is overdefined, we may still produce
a non-overdefined result, e.g. due to a min/max operation. This
matches our handling elsewhere, e.g. for binary operators.

The slot poisoning comment refers to a much older LVI cache
implementation.
This commit is contained in:
Nikita Popov 2021-04-04 10:52:22 +02:00
parent 3ac2541b5c
commit 72e0846ef8
2 changed files with 2 additions and 14 deletions

View File

@ -801,22 +801,12 @@ Optional<ValueLatticeElement> LazyValueInfoImpl::solveBlockValueSelect(
return None;
ValueLatticeElement &TrueVal = *OptTrueVal;
// If we hit overdefined, don't ask more queries. We want to avoid poisoning
// extra slots in the table if we can.
if (TrueVal.isOverdefined())
return ValueLatticeElement::getOverdefined();
Optional<ValueLatticeElement> OptFalseVal =
getBlockValue(SI->getFalseValue(), BB);
if (!OptFalseVal)
return None;
ValueLatticeElement &FalseVal = *OptFalseVal;
// If we hit overdefined, don't ask more queries. We want to avoid poisoning
// extra slots in the table if we can.
if (FalseVal.isOverdefined())
return ValueLatticeElement::getOverdefined();
if (TrueVal.isConstantRange() && FalseVal.isConstantRange()) {
const ConstantRange &TrueCR = TrueVal.getConstantRange();
const ConstantRange &FalseCR = FalseVal.getConstantRange();

View File

@ -129,8 +129,7 @@ define i32 @min_and(i32 %a) {
; CHECK-LABEL: @min_and(
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[A:%.*]], 127
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 [[A]], i32 127
; CHECK-NEXT: [[AND:%.*]] = and i32 [[SEL]], 127
; CHECK-NEXT: ret i32 [[AND]]
; CHECK-NEXT: ret i32 [[SEL]]
;
%cmp = icmp ult i32 %a, 127
%sel = select i1 %cmp, i32 %a, i32 127
@ -142,8 +141,7 @@ define i32 @min_and_comm(i32 %a) {
; CHECK-LABEL: @min_and_comm(
; CHECK-NEXT: [[CMP:%.*]] = icmp uge i32 [[A:%.*]], 127
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 127, i32 [[A]]
; CHECK-NEXT: [[AND:%.*]] = and i32 [[SEL]], 127
; CHECK-NEXT: ret i32 [[AND]]
; CHECK-NEXT: ret i32 [[SEL]]
;
%cmp = icmp uge i32 %a, 127
%sel = select i1 %cmp, i32 127, i32 %a