[llvm] ddf7cc2 - [SROA] Remove unnecessary IsStorePastEnd handling (NFCI)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 19 07:53:34 PDT 2023


Author: Nikita Popov
Date: 2023-09-19T16:53:24+02:00
New Revision: ddf7cc27f7230164ce888d814ebecd0f266f60c5

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

LOG: [SROA] Remove unnecessary IsStorePastEnd handling (NFCI)

Unlike the load case, stores past the end of the alloca are
removed by SROA as undefined behavior. As such, there is no need
to handle this case when rewriting stores.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index 7beed0a0e11aa7d..891f5349bd9b2b0 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -2891,26 +2891,10 @@ class llvm::sroa::AllocaSliceRewriter
     if (IntTy && V->getType()->isIntegerTy())
       return rewriteIntegerStore(V, SI, AATags);
 
-    const bool IsStorePastEnd =
-        DL.getTypeStoreSize(V->getType()).getFixedValue() > SliceSize;
     StoreInst *NewSI;
     if (NewBeginOffset == NewAllocaBeginOffset &&
         NewEndOffset == NewAllocaEndOffset &&
-        (canConvertValue(DL, V->getType(), NewAllocaTy) ||
-         (IsStorePastEnd && NewAllocaTy->isIntegerTy() &&
-          V->getType()->isIntegerTy()))) {
-      // If this is an integer store past the end of slice (and thus the bytes
-      // past that point are irrelevant or this is unreachable), truncate the
-      // value prior to storing.
-      if (auto *VITy = dyn_cast<IntegerType>(V->getType()))
-        if (auto *AITy = dyn_cast<IntegerType>(NewAllocaTy))
-          if (VITy->getBitWidth() > AITy->getBitWidth()) {
-            if (DL.isBigEndian())
-              V = IRB.CreateLShr(V, VITy->getBitWidth() - AITy->getBitWidth(),
-                                 "endian_shift");
-            V = IRB.CreateTrunc(V, AITy, "load.trunc");
-          }
-
+        canConvertValue(DL, V->getType(), NewAllocaTy)) {
       V = convertValue(DL, IRB, V, NewAllocaTy);
       Value *NewPtr =
           getPtrToNewAI(SI.getPointerAddressSpace(), SI.isVolatile());


        


More information about the llvm-commits mailing list