Skip to content

Commit cf552a1

Browse files
committed
[LIR] Simplify processLoopStridedStore [nfc]
Just move the assertions and exits down under the existing if clauses. This improves readability.
1 parent db099f1 commit cf552a1

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,14 +1026,6 @@ bool LoopIdiomRecognize::processLoopStridedStore(
10261026
SmallPtrSetImpl<Instruction *> &Stores, const SCEVAddRecExpr *Ev,
10271027
const SCEV *BECount, bool IsNegStride, bool IsLoopMemset) {
10281028
Module *M = TheStore->getModule();
1029-
Value *SplatValue = isBytewiseValue(StoredVal, *DL);
1030-
Constant *PatternValue = nullptr;
1031-
1032-
if (!SplatValue)
1033-
PatternValue = getMemSetPatternValue(StoredVal, DL);
1034-
1035-
assert((SplatValue || PatternValue) &&
1036-
"Expected either splat value or pattern value.");
10371029

10381030
// The trip count of the loop and the base pointer of the addrec SCEV is
10391031
// guaranteed to be loop invariant, which means that it should dominate the
@@ -1095,9 +1087,6 @@ bool LoopIdiomRecognize::processLoopStridedStore(
10951087
Value *NumBytes =
10961088
Expander.expandCodeFor(NumBytesS, IntIdxTy, Preheader->getTerminator());
10971089

1098-
if (!SplatValue && !isLibFuncEmittable(M, TLI, LibFunc_memset_pattern16))
1099-
return Changed;
1100-
11011090
AAMDNodes AATags = TheStore->getAAMetadata();
11021091
for (Instruction *Store : Stores)
11031092
AATags = AATags.merge(Store->getAAMetadata());
@@ -1107,12 +1096,11 @@ bool LoopIdiomRecognize::processLoopStridedStore(
11071096
AATags = AATags.extendTo(-1);
11081097

11091098
CallInst *NewCall;
1110-
if (SplatValue) {
1099+
if (Value *SplatValue = isBytewiseValue(StoredVal, *DL)) {
11111100
NewCall = Builder.CreateMemSet(
11121101
BasePtr, SplatValue, NumBytes, MaybeAlign(StoreAlignment),
11131102
/*isVolatile=*/false, AATags.TBAA, AATags.Scope, AATags.NoAlias);
1114-
} else {
1115-
assert (isLibFuncEmittable(M, TLI, LibFunc_memset_pattern16));
1103+
} else if (isLibFuncEmittable(M, TLI, LibFunc_memset_pattern16)) {
11161104
// Everything is emitted in default address space
11171105
Type *Int8PtrTy = DestInt8PtrTy;
11181106

@@ -1123,13 +1111,14 @@ bool LoopIdiomRecognize::processLoopStridedStore(
11231111

11241112
// Otherwise we should form a memset_pattern16. PatternValue is known to be
11251113
// an constant array of 16-bytes. Plop the value into a mergable global.
1114+
Constant *PatternValue = getMemSetPatternValue(StoredVal, DL);
1115+
assert(PatternValue && "Expected pattern value.");
11261116
GlobalVariable *GV = new GlobalVariable(*M, PatternValue->getType(), true,
11271117
GlobalValue::PrivateLinkage,
11281118
PatternValue, ".memset_pattern");
11291119
GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global); // Ok to merge these.
11301120
GV->setAlignment(Align(16));
1131-
Value *PatternPtr = GV;
1132-
NewCall = Builder.CreateCall(MSP, {BasePtr, PatternPtr, NumBytes});
1121+
NewCall = Builder.CreateCall(MSP, {BasePtr, GV, NumBytes});
11331122

11341123
// Set the TBAA info if present.
11351124
if (AATags.TBAA)
@@ -1140,6 +1129,9 @@ bool LoopIdiomRecognize::processLoopStridedStore(
11401129

11411130
if (AATags.NoAlias)
11421131
NewCall->setMetadata(LLVMContext::MD_noalias, AATags.NoAlias);
1132+
} else {
1133+
// Neither a memset, nor memset_pattern16
1134+
return Changed;
11431135
}
11441136

11451137
NewCall->setDebugLoc(TheStore->getDebugLoc());

0 commit comments

Comments
 (0)