[llvm] 25d9fde - [SCCP] Skip computing intrinsics if one of its args is unknownOrUndef

luxufanxport https_proxy=http via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 10 00:56:59 PDT 2023


Author: luxufan
Date: 2023-06-10T15:48:46+08:00
New Revision: 25d9fde22e609f8637f720220810429745707b76

URL: https://github.com/llvm/llvm-project/commit/25d9fde22e609f8637f720220810429745707b76
DIFF: https://github.com/llvm/llvm-project/commit/25d9fde22e609f8637f720220810429745707b76.diff

LOG: [SCCP] Skip computing intrinsics if one of its args is unknownOrUndef

For constant range supported intrinsics, we got consantrange from args
no matter if they are unknown or undef. And the constant range computed
from unknown or undef value state is full range.

I think compute with full constant range is harmful since although we
can do mergeIn after these args value state are changed, the merge
operation of two constant ranges is union.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D152499

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/SCCPSolver.cpp
    llvm/test/Transforms/SCCP/intrinsics.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SCCPSolver.cpp b/llvm/lib/Transforms/Utils/SCCPSolver.cpp
index 66ae1c45cf409..902651ab84f68 100644
--- a/llvm/lib/Transforms/Utils/SCCPSolver.cpp
+++ b/llvm/lib/Transforms/Utils/SCCPSolver.cpp
@@ -1779,6 +1779,8 @@ void SCCPInstVisitor::handleCallResult(CallBase &CB) {
       SmallVector<ConstantRange, 2> OpRanges;
       for (Value *Op : II->args()) {
         const ValueLatticeElement &State = getValueState(Op);
+        if (State.isUnknownOrUndef())
+          return;
         OpRanges.push_back(getConstantRange(State, Op->getType()));
       }
 

diff  --git a/llvm/test/Transforms/SCCP/intrinsics.ll b/llvm/test/Transforms/SCCP/intrinsics.ll
index 6a86337a5e0a9..3fc7637ab7327 100644
--- a/llvm/test/Transforms/SCCP/intrinsics.ll
+++ b/llvm/test/Transforms/SCCP/intrinsics.ll
@@ -107,8 +107,7 @@ define i8 @umax_including_undef(i1 %c.1, i1 %c.2) {
 ; CHECK:       false:
 ; CHECK-NEXT:    br label [[EXIT]]
 ; CHECK:       exit:
-; CHECK-NEXT:    [[P_UMAX:%.*]] = call i8 @llvm.umax.i8(i8 3, i8 1)
-; CHECK-NEXT:    ret i8 [[P_UMAX]]
+; CHECK-NEXT:    ret i8 3
 ;
   br i1 %c.1, label %true, label %false
 


        


More information about the llvm-commits mailing list