@@ -1026,14 +1026,6 @@ bool LoopIdiomRecognize::processLoopStridedStore(
1026
1026
SmallPtrSetImpl<Instruction *> &Stores, const SCEVAddRecExpr *Ev,
1027
1027
const SCEV *BECount, bool IsNegStride, bool IsLoopMemset) {
1028
1028
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." );
1037
1029
1038
1030
// The trip count of the loop and the base pointer of the addrec SCEV is
1039
1031
// guaranteed to be loop invariant, which means that it should dominate the
@@ -1095,9 +1087,6 @@ bool LoopIdiomRecognize::processLoopStridedStore(
1095
1087
Value *NumBytes =
1096
1088
Expander.expandCodeFor (NumBytesS, IntIdxTy, Preheader->getTerminator ());
1097
1089
1098
- if (!SplatValue && !isLibFuncEmittable (M, TLI, LibFunc_memset_pattern16))
1099
- return Changed;
1100
-
1101
1090
AAMDNodes AATags = TheStore->getAAMetadata ();
1102
1091
for (Instruction *Store : Stores)
1103
1092
AATags = AATags.merge (Store->getAAMetadata ());
@@ -1107,12 +1096,11 @@ bool LoopIdiomRecognize::processLoopStridedStore(
1107
1096
AATags = AATags.extendTo (-1 );
1108
1097
1109
1098
CallInst *NewCall;
1110
- if (SplatValue) {
1099
+ if (Value * SplatValue = isBytewiseValue (StoredVal, *DL) ) {
1111
1100
NewCall = Builder.CreateMemSet (
1112
1101
BasePtr, SplatValue, NumBytes, MaybeAlign (StoreAlignment),
1113
1102
/* 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)) {
1116
1104
// Everything is emitted in default address space
1117
1105
Type *Int8PtrTy = DestInt8PtrTy;
1118
1106
@@ -1123,13 +1111,14 @@ bool LoopIdiomRecognize::processLoopStridedStore(
1123
1111
1124
1112
// Otherwise we should form a memset_pattern16. PatternValue is known to be
1125
1113
// 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." );
1126
1116
GlobalVariable *GV = new GlobalVariable (*M, PatternValue->getType (), true ,
1127
1117
GlobalValue::PrivateLinkage,
1128
1118
PatternValue, " .memset_pattern" );
1129
1119
GV->setUnnamedAddr (GlobalValue::UnnamedAddr::Global); // Ok to merge these.
1130
1120
GV->setAlignment (Align (16 ));
1131
- Value *PatternPtr = GV;
1132
- NewCall = Builder.CreateCall (MSP, {BasePtr, PatternPtr, NumBytes});
1121
+ NewCall = Builder.CreateCall (MSP, {BasePtr, GV, NumBytes});
1133
1122
1134
1123
// Set the TBAA info if present.
1135
1124
if (AATags.TBAA )
@@ -1140,6 +1129,9 @@ bool LoopIdiomRecognize::processLoopStridedStore(
1140
1129
1141
1130
if (AATags.NoAlias )
1142
1131
NewCall->setMetadata (LLVMContext::MD_noalias, AATags.NoAlias );
1132
+ } else {
1133
+ // Neither a memset, nor memset_pattern16
1134
+ return Changed;
1143
1135
}
1144
1136
1145
1137
NewCall->setDebugLoc (TheStore->getDebugLoc ());
0 commit comments