@@ -225,34 +225,43 @@ void LoopVersioning::annotateLoopWithNoAlias() {
225
225
}
226
226
}
227
227
228
- void LoopVersioning::annotateInstWithNoAlias (Instruction *VersionedInst,
229
- const Instruction *OrigInst) {
228
+ std::pair<MDNode *, MDNode *>
229
+ LoopVersioning::getNoAliasMetadataFor ( const Instruction *OrigInst) const {
230
230
if (!AnnotateNoAlias)
231
- return ;
231
+ return { nullptr , nullptr } ;
232
232
233
233
LLVMContext &Context = VersionedLoop->getHeader ()->getContext ();
234
234
const Value *Ptr = isa<LoadInst>(OrigInst)
235
235
? cast<LoadInst>(OrigInst)->getPointerOperand ()
236
236
: cast<StoreInst>(OrigInst)->getPointerOperand ();
237
237
238
+ MDNode *AliasScope = nullptr ;
239
+ MDNode *NoAlias = nullptr ;
238
240
// Find the group for the pointer and then add the scope metadata.
239
241
auto Group = PtrToGroup.find (Ptr );
240
242
if (Group != PtrToGroup.end ()) {
241
- VersionedInst->setMetadata (
242
- LLVMContext::MD_alias_scope,
243
- MDNode::concatenate (
244
- VersionedInst->getMetadata (LLVMContext::MD_alias_scope),
245
- MDNode::get (Context, GroupToScope[Group->second ])));
243
+ AliasScope = MDNode::concatenate (
244
+ OrigInst->getMetadata (LLVMContext::MD_alias_scope),
245
+ MDNode::get (Context, GroupToScope.lookup (Group->second )));
246
246
247
247
// Add the no-alias metadata.
248
248
auto NonAliasingScopeList = GroupToNonAliasingScopeList.find (Group->second );
249
249
if (NonAliasingScopeList != GroupToNonAliasingScopeList.end ())
250
- VersionedInst->setMetadata (
251
- LLVMContext::MD_noalias,
252
- MDNode::concatenate (
253
- VersionedInst->getMetadata (LLVMContext::MD_noalias),
254
- NonAliasingScopeList->second ));
250
+ NoAlias =
251
+ MDNode::concatenate (OrigInst->getMetadata (LLVMContext::MD_noalias),
252
+ NonAliasingScopeList->second );
255
253
}
254
+ return {AliasScope, NoAlias};
255
+ }
256
+
257
+ void LoopVersioning::annotateInstWithNoAlias (Instruction *VersionedInst,
258
+ const Instruction *OrigInst) {
259
+ const auto &[AliasScopeMD, NoAliasMD] = getNoAliasMetadataFor (OrigInst);
260
+ if (AliasScopeMD)
261
+ VersionedInst->setMetadata (LLVMContext::MD_alias_scope, AliasScopeMD);
262
+
263
+ if (NoAliasMD)
264
+ VersionedInst->setMetadata (LLVMContext::MD_noalias, NoAliasMD);
256
265
}
257
266
258
267
namespace {
0 commit comments