[LVI] Handle commuted SPF min/max operands
authorNikita Popov <npopov@redhat.com>
Tue, 18 Jan 2022 09:42:45 +0000 (10:42 +0100)
committerNikita Popov <npopov@redhat.com>
Tue, 18 Jan 2022 09:43:00 +0000 (10:43 +0100)
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.

llvm/lib/Analysis/LazyValueInfo.cpp
llvm/test/Transforms/CorrelatedValuePropagation/basic.ll

index 10cb28a..e095cda 100644 (file)
@@ -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:
index e8cf350..a16209c 100644 (file)
@@ -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)