[llvm] 84df226 - [CVP] Don't use undef ranges in willNotOverflow()

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 12 02:54:43 PST 2023


Author: Nikita Popov
Date: 2023-12-12T11:54:33+01:00
New Revision: 84df226c4a2fd1852ca5c1f52fb4463da9555913

URL: https://github.com/llvm/llvm-project/commit/84df226c4a2fd1852ca5c1f52fb4463da9555913
DIFF: https://github.com/llvm/llvm-project/commit/84df226c4a2fd1852ca5c1f52fb4463da9555913.diff

LOG: [CVP] Don't use undef ranges in willNotOverflow()

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
    llvm/test/Transforms/CorrelatedValuePropagation/overflows.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
index 669bdf50ba6e6e..8bc05be97dae11 100644
--- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -393,8 +393,10 @@ static bool processSwitch(SwitchInst *I, LazyValueInfo *LVI,
 
 // See if we can prove that the given binary op intrinsic will not overflow.
 static bool willNotOverflow(BinaryOpIntrinsic *BO, LazyValueInfo *LVI) {
-  ConstantRange LRange = LVI->getConstantRangeAtUse(BO->getOperandUse(0));
-  ConstantRange RRange = LVI->getConstantRangeAtUse(BO->getOperandUse(1));
+  ConstantRange LRange =
+      LVI->getConstantRangeAtUse(BO->getOperandUse(0), /*UndefAllowed*/ false);
+  ConstantRange RRange =
+      LVI->getConstantRangeAtUse(BO->getOperandUse(1), /*UndefAllowed*/ false);
   ConstantRange NWRegion = ConstantRange::makeGuaranteedNoWrapRegion(
       BO->getBinaryOp(), RRange, BO->getNoWrapKind());
   return NWRegion.contains(LRange);

diff  --git a/llvm/test/Transforms/CorrelatedValuePropagation/overflows.ll b/llvm/test/Transforms/CorrelatedValuePropagation/overflows.ll
index 7424da32e32fd0..669527ed88fa2f 100644
--- a/llvm/test/Transforms/CorrelatedValuePropagation/overflows.ll
+++ b/llvm/test/Transforms/CorrelatedValuePropagation/overflows.ll
@@ -1150,7 +1150,6 @@ out:
   ret i1 %ret
 }
 
-; FIXME: This is a miscompile.
 define i8 @uadd_sat_undef_range(i8 %x) {
 ; CHECK-LABEL: @uadd_sat_undef_range(
 ; CHECK-NEXT:  entry:
@@ -1164,8 +1163,8 @@ define i8 @uadd_sat_undef_range(i8 %x) {
 ; CHECK-NEXT:    br label [[JOIN]]
 ; CHECK:       join:
 ; CHECK-NEXT:    [[PHI:%.*]] = phi i8 [ 1, [[CASE1]] ], [ 2, [[CASE2]] ], [ undef, [[ENTRY:%.*]] ]
-; CHECK-NEXT:    [[RES1:%.*]] = add nuw i8 [[PHI]], 100
-; CHECK-NEXT:    ret i8 [[RES1]]
+; CHECK-NEXT:    [[RES:%.*]] = call i8 @llvm.uadd.sat.i8(i8 [[PHI]], i8 100)
+; CHECK-NEXT:    ret i8 [[RES]]
 ;
 entry:
   switch i8 %x, label %join [


        


More information about the llvm-commits mailing list