Skip to content

Commit

Permalink
[LVI] Handle commuted SPF min/max operands
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikic committed Jan 18, 2022
1 parent d15823e commit 9e68557
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
3 changes: 2 additions & 1 deletion llvm/lib/Analysis/LazyValueInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,8 @@ Optional<ValueLatticeElement> LazyValueInfoImpl::solveBlockValueSelect(
// Is this a min specifically of our two inputs? (Avoid the risk of
// ValueTracking getting smarter looking back past our immediate inputs.)
if (SelectPatternResult::isMinOrMax(SPR.Flavor) &&
LHS == SI->getTrueValue() && RHS == SI->getFalseValue()) {
((LHS == SI->getTrueValue() && RHS == SI->getFalseValue()) ||
(RHS == SI->getTrueValue() && LHS == SI->getFalseValue()))) {
ConstantRange ResultCR = [&]() {
switch (SPR.Flavor) {
default:
Expand Down
3 changes: 1 addition & 2 deletions llvm/test/Transforms/CorrelatedValuePropagation/basic.ll
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,7 @@ define i1 @umin_rhs_overdefined_lhs_range(i32 %a, i32 %b) {
; CHECK-NEXT: call void @llvm.assume(i1 [[ASSUME]])
; CHECK-NEXT: [[CMP:%.*]] = icmp uge i32 [[A:%.*]], [[B]]
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 [[B]], i32 [[A]]
; 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)
Expand Down

0 comments on commit 9e68557

Please sign in to comment.