[llvm] cf552a1 - [LIR] Simplify processLoopStridedStore [nfc]

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Wed May 14 11:14:01 PDT 2025


Author: Philip Reames
Date: 2025-05-14T11:13:34-07:00
New Revision: cf552a1d82650f9ea4a03e0467d0ca64dbc3e5c4

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

LOG: [LIR] Simplify processLoopStridedStore [nfc]

Just move the assertions and exits down under the existing if clauses.
This improves readability.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
index 8f5d1ecba982d..817f42b31ecd6 100644
--- a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
@@ -1026,14 +1026,6 @@ bool LoopIdiomRecognize::processLoopStridedStore(
     SmallPtrSetImpl<Instruction *> &Stores, const SCEVAddRecExpr *Ev,
     const SCEV *BECount, bool IsNegStride, bool IsLoopMemset) {
   Module *M = TheStore->getModule();
-  Value *SplatValue = isBytewiseValue(StoredVal, *DL);
-  Constant *PatternValue = nullptr;
-
-  if (!SplatValue)
-    PatternValue = getMemSetPatternValue(StoredVal, DL);
-
-  assert((SplatValue || PatternValue) &&
-         "Expected either splat value or pattern value.");
 
   // The trip count of the loop and the base pointer of the addrec SCEV is
   // guaranteed to be loop invariant, which means that it should dominate the
@@ -1095,9 +1087,6 @@ bool LoopIdiomRecognize::processLoopStridedStore(
   Value *NumBytes =
       Expander.expandCodeFor(NumBytesS, IntIdxTy, Preheader->getTerminator());
 
-  if (!SplatValue && !isLibFuncEmittable(M, TLI, LibFunc_memset_pattern16))
-    return Changed;
-
   AAMDNodes AATags = TheStore->getAAMetadata();
   for (Instruction *Store : Stores)
     AATags = AATags.merge(Store->getAAMetadata());
@@ -1107,12 +1096,11 @@ bool LoopIdiomRecognize::processLoopStridedStore(
     AATags = AATags.extendTo(-1);
 
   CallInst *NewCall;
-  if (SplatValue) {
+  if (Value *SplatValue = isBytewiseValue(StoredVal, *DL)) {
     NewCall = Builder.CreateMemSet(
         BasePtr, SplatValue, NumBytes, MaybeAlign(StoreAlignment),
         /*isVolatile=*/false, AATags.TBAA, AATags.Scope, AATags.NoAlias);
-  } else {
-    assert (isLibFuncEmittable(M, TLI, LibFunc_memset_pattern16));
+  } else if (isLibFuncEmittable(M, TLI, LibFunc_memset_pattern16)) {
     // Everything is emitted in default address space
     Type *Int8PtrTy = DestInt8PtrTy;
 
@@ -1123,13 +1111,14 @@ bool LoopIdiomRecognize::processLoopStridedStore(
 
     // Otherwise we should form a memset_pattern16.  PatternValue is known to be
     // an constant array of 16-bytes.  Plop the value into a mergable global.
+    Constant *PatternValue = getMemSetPatternValue(StoredVal, DL);
+    assert(PatternValue && "Expected pattern value.");
     GlobalVariable *GV = new GlobalVariable(*M, PatternValue->getType(), true,
                                             GlobalValue::PrivateLinkage,
                                             PatternValue, ".memset_pattern");
     GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global); // Ok to merge these.
     GV->setAlignment(Align(16));
-    Value *PatternPtr = GV;
-    NewCall = Builder.CreateCall(MSP, {BasePtr, PatternPtr, NumBytes});
+    NewCall = Builder.CreateCall(MSP, {BasePtr, GV, NumBytes});
 
     // Set the TBAA info if present.
     if (AATags.TBAA)
@@ -1140,6 +1129,9 @@ bool LoopIdiomRecognize::processLoopStridedStore(
 
     if (AATags.NoAlias)
       NewCall->setMetadata(LLVMContext::MD_noalias, AATags.NoAlias);
+  } else {
+    // Neither a memset, nor memset_pattern16
+    return Changed;
   }
 
   NewCall->setDebugLoc(TheStore->getDebugLoc());


        


More information about the llvm-commits mailing list