[llvm] 2c61f9c - [CVP] Fix use after scope

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 8 07:53:57 PST 2023


Author: Nikita Popov
Date: 2023-11-08T16:53:47+01:00
New Revision: 2c61f9cab51b4e358e4c86343cbcfa6ffa8504a2

URL: https://github.com/llvm/llvm-project/commit/2c61f9cab51b4e358e4c86343cbcfa6ffa8504a2
DIFF: https://github.com/llvm/llvm-project/commit/2c61f9cab51b4e358e4c86343cbcfa6ffa8504a2.diff

LOG: [CVP] Fix use after scope

Store the result of ConstantRange::sdiv() in a variable, as
getSingleElement() will return a pointer to the APInt it contains.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
index d58ea126f294b60..ece22428e3cbdce 100644
--- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -911,7 +911,8 @@ static bool processSDiv(BinaryOperator *SDI, const ConstantRange &LCR,
   assert(!SDI->getType()->isVectorTy());
 
   // Check whether the division folds to a constant.
-  if (const APInt *Elem = LCR.sdiv(RCR).getSingleElement()) {
+  ConstantRange DivCR = LCR.sdiv(RCR);
+  if (const APInt *Elem = DivCR.getSingleElement()) {
     SDI->replaceAllUsesWith(ConstantInt::get(SDI->getType(), *Elem));
     SDI->eraseFromParent();
     return true;


        


More information about the llvm-commits mailing list