[llvm] 9e68557 - [LVI] Handle commuted SPF min/max operands

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 18 01:44:05 PST 2022


Author: Nikita Popov
Date: 2022-01-18T10:43:00+01:00
New Revision: 9e68557e6437a7cb997cf571542b3638839dcaa0

URL: https://github.com/llvm/llvm-project/commit/9e68557e6437a7cb997cf571542b3638839dcaa0
DIFF: https://github.com/llvm/llvm-project/commit/9e68557e6437a7cb997cf571542b3638839dcaa0.diff

LOG: [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.

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 10cb28a0b37d..e095cdaff5bf 100644
--- a/llvm/lib/Analysis/LazyValueInfo.cpp
+++ b/llvm/lib/Analysis/LazyValueInfo.cpp
@@ -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:

diff  --git a/llvm/test/Transforms/CorrelatedValuePropagation/basic.ll b/llvm/test/Transforms/CorrelatedValuePropagation/basic.ll
index e8cf35021661..a16209c1422a 100644
--- a/llvm/test/Transforms/CorrelatedValuePropagation/basic.ll
+++ b/llvm/test/Transforms/CorrelatedValuePropagation/basic.ll
@@ -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)


        


More information about the llvm-commits mailing list