From 72e0846ef87d0d3b5960238bc47fc0cc6f04d848 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sun, 4 Apr 2021 10:52:22 +0200 Subject: [PATCH] [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. --- llvm/lib/Analysis/LazyValueInfo.cpp | 10 ---------- llvm/test/Transforms/CorrelatedValuePropagation/and.ll | 6 ++---- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index c1a8d3d..75fef34 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -801,22 +801,12 @@ Optional 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 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(); diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/and.ll b/llvm/test/Transforms/CorrelatedValuePropagation/and.ll index 0fd2955..195dd8b 100644 --- a/llvm/test/Transforms/CorrelatedValuePropagation/and.ll +++ b/llvm/test/Transforms/CorrelatedValuePropagation/and.ll @@ -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 -- 2.7.4