[llvm] 3250305 - [LoopUnrollAnalyzer] Use computeConstantDifference()

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 27 06:53:06 PDT 2024


Author: Nikita Popov
Date: 2024-08-27T15:51:49+02:00
New Revision: 32503050066ed307e6859b3c2ee6fbfa6327ca8b

URL: https://github.com/llvm/llvm-project/commit/32503050066ed307e6859b3c2ee6fbfa6327ca8b
DIFF: https://github.com/llvm/llvm-project/commit/32503050066ed307e6859b3c2ee6fbfa6327ca8b.diff

LOG: [LoopUnrollAnalyzer] Use computeConstantDifference()

This is faster than checking for a SCEVConstant getMinusSCEV()
result. The results should be the same for non-degenerate cases.

Added: 
    

Modified: 
    llvm/lib/Analysis/LoopUnrollAnalyzer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/LoopUnrollAnalyzer.cpp b/llvm/lib/Analysis/LoopUnrollAnalyzer.cpp
index 34fbab6a11d6d1..8824cec86924f3 100644
--- a/llvm/lib/Analysis/LoopUnrollAnalyzer.cpp
+++ b/llvm/lib/Analysis/LoopUnrollAnalyzer.cpp
@@ -58,13 +58,13 @@ bool UnrolledInstAnalyzer::simplifyInstWithSCEV(Instruction *I) {
   auto *Base = dyn_cast<SCEVUnknown>(SE.getPointerBase(S));
   if (!Base)
     return false;
-  auto *Offset =
-      dyn_cast<SCEVConstant>(SE.getMinusSCEV(ValueAtIteration, Base));
+  std::optional<APInt> Offset =
+      SE.computeConstantDifference(ValueAtIteration, Base);
   if (!Offset)
     return false;
   SimplifiedAddress Address;
   Address.Base = Base->getValue();
-  Address.Offset = Offset->getAPInt();
+  Address.Offset = *Offset;
   SimplifiedAddresses[I] = Address;
   return false;
 }


        


More information about the llvm-commits mailing list