Skip to content

Commit 9e68557

Browse files
committed
[LVI] Handle commuted SPF min/max operands
We need to check that the operands of the min/max are the operands of the select, but we don't care which order they are in.
1 parent d15823e commit 9e68557

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

llvm/lib/Analysis/LazyValueInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,8 @@ Optional<ValueLatticeElement> LazyValueInfoImpl::solveBlockValueSelect(
828828
// Is this a min specifically of our two inputs? (Avoid the risk of
829829
// ValueTracking getting smarter looking back past our immediate inputs.)
830830
if (SelectPatternResult::isMinOrMax(SPR.Flavor) &&
831-
LHS == SI->getTrueValue() && RHS == SI->getFalseValue()) {
831+
((LHS == SI->getTrueValue() && RHS == SI->getFalseValue()) ||
832+
(RHS == SI->getTrueValue() && LHS == SI->getFalseValue()))) {
832833
ConstantRange ResultCR = [&]() {
833834
switch (SPR.Flavor) {
834835
default:

llvm/test/Transforms/CorrelatedValuePropagation/basic.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,7 @@ define i1 @umin_rhs_overdefined_lhs_range(i32 %a, i32 %b) {
665665
; CHECK-NEXT: call void @llvm.assume(i1 [[ASSUME]])
666666
; CHECK-NEXT: [[CMP:%.*]] = icmp uge i32 [[A:%.*]], [[B]]
667667
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 [[B]], i32 [[A]]
668-
; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i32 [[SEL]], 42
669-
; CHECK-NEXT: ret i1 [[CMP2]]
668+
; CHECK-NEXT: ret i1 true
670669
;
671670
%assume = icmp ult i32 %b, 42
672671
call void @llvm.assume(i1 %assume)

0 commit comments

Comments
 (0)