[llvm] d15823e - [LVI] Compute SPF range even if one operands is overdefined
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 18 01:40:56 PST 2022
Author: Nikita Popov
Date: 2022-01-18T10:40:49+01:00
New Revision: d15823e3006bd3c5f19388e5cb6bc0cdcba9c2b2
URL: https://github.com/llvm/llvm-project/commit/d15823e3006bd3c5f19388e5cb6bc0cdcba9c2b2
DIFF: https://github.com/llvm/llvm-project/commit/d15823e3006bd3c5f19388e5cb6bc0cdcba9c2b2.diff
LOG: [LVI] Compute SPF range even if one operands is overdefined
If we have a constant range for one operand but not the other,
we can generally still compute a useful results for SPF min/max.
Added:
Modified:
llvm/lib/Analysis/LazyValueInfo.cpp
llvm/test/Transforms/CorrelatedValuePropagation/basic.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp
index 886dbf976f45..10cb28a0b37d 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<ValueLatticeElement> LazyValueInfoImpl::solveBlockValueSelect(
SelectInst *SI, BasicBlock *BB) {
// Recurse on our inputs if needed
@@ -810,9 +817,11 @@ Optional<ValueLatticeElement> 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<ConstantRange> LazyValueInfoImpl::getRangeFor(Value *V,
Optional<ValueLatticeElement> 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<ValueLatticeElement> LazyValueInfoImpl::solveBlockValueCast(
diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/basic.ll b/llvm/test/Transforms/CorrelatedValuePropagation/basic.ll
index 2110cf4b3847..e8cf35021661 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)
More information about the llvm-commits
mailing list