[mlir] Always create a list of alias scopes when emitting LLVM IR

Previously, the translation to LLVM IR would emit IR that directly uses
a scope metadata node in case only one scope was in use in alias.scopes
or noalias metadata. It should always be a list of scopes. The verifier
change in 8700f2bd36 enforced this and
broke the test. Fix the translation to always create a list of scopes
using a new metadata node, update and reenable the respective test.

Fixes PR51919.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D110140
This commit is contained in:
Alex Zinenko 2021-09-21 11:39:43 +02:00
parent b81e26c7f4
commit bdaf038266
2 changed files with 10 additions and 13 deletions

View File

@ -944,11 +944,7 @@ void ModuleTranslation::setAliasScopeMetadata(Operation *op,
SmallVector<llvm::Metadata *> scopeMDs;
for (SymbolRefAttr scopeRef : scopes.getAsRange<SymbolRefAttr>())
scopeMDs.push_back(getAliasScope(*op, scopeRef));
llvm::MDNode *unionMD = nullptr;
if (scopeMDs.size() == 1)
unionMD = llvm::cast<llvm::MDNode>(scopeMDs.front());
else if (scopeMDs.size() >= 2)
unionMD = llvm::MDNode::get(module->getContext(), scopeMDs);
llvm::MDNode *unionMD = llvm::MDNode::get(module->getContext(), scopeMDs);
inst->setMetadata(module->getMDKindID(llvmMetadataName), unionMD);
};

View File

@ -1,6 +1,4 @@
// RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
// This is failing the LLVM verifier after 8700f2bd36bb9b
// XFAIL: *
// CHECK: @global_aligned32 = private global i64 42, align 32
"llvm.mlir.global"() ({}) {sym_name = "global_aligned32", type = i64, value = 42 : i64, linkage = #llvm.linkage<private>, alignment = 32} : () -> ()
@ -1649,15 +1647,18 @@ module {
// Function
// CHECK-LABEL: aliasScope
// CHECK: store {{.*}}, !alias.scope ![[SCOPE1:[0-9]+]], !noalias ![[SCOPES23:[0-9]+]]
// CHECK: store {{.*}}, !alias.scope ![[SCOPE2:[0-9]+]], !noalias ![[SCOPES13:[0-9]+]]
// CHECK: load {{.*}}, !alias.scope ![[SCOPE3:[0-9]+]], !noalias ![[SCOPES12:[0-9]+]]
// CHECK: store {{.*}}, !alias.scope ![[SCOPES1:[0-9]+]], !noalias ![[SCOPES23:[0-9]+]]
// CHECK: store {{.*}}, !alias.scope ![[SCOPES2:[0-9]+]], !noalias ![[SCOPES13:[0-9]+]]
// CHECK: load {{.*}}, !alias.scope ![[SCOPES3:[0-9]+]], !noalias ![[SCOPES12:[0-9]+]]
// Metadata
// CHECK-DAG: ![[DOMAIN:[0-9]+]] = distinct !{![[DOMAIN]], !"The domain"}
// CHECK-DAG: ![[SCOPE1]] = distinct !{![[SCOPE1]], ![[DOMAIN]], !"The first scope"}
// CHECK-DAG: ![[SCOPE2]] = distinct !{![[SCOPE2]], ![[DOMAIN]]}
// CHECK-DAG: ![[SCOPE3]] = distinct !{![[SCOPE3]], ![[DOMAIN]]}
// CHECK-DAG: ![[SCOPE1:[0-9]+]] = distinct !{![[SCOPE1]], ![[DOMAIN]], !"The first scope"}
// CHECK-DAG: ![[SCOPE2:[0-9]+]] = distinct !{![[SCOPE2]], ![[DOMAIN]]}
// CHECK-DAG: ![[SCOPE3:[0-9]+]] = distinct !{![[SCOPE3]], ![[DOMAIN]]}
// CHECK-DAG: ![[SCOPES1]] = !{![[SCOPE1]]}
// CHECK-DAG: ![[SCOPES2]] = !{![[SCOPE2]]}
// CHECK-DAG: ![[SCOPES3]] = !{![[SCOPE3]]}
// CHECK-DAG: ![[SCOPES12]] = !{![[SCOPE1]], ![[SCOPE2]]}
// CHECK-DAG: ![[SCOPES13]] = !{![[SCOPE1]], ![[SCOPE3]]}
// CHECK-DAG: ![[SCOPES23]] = !{![[SCOPE2]], ![[SCOPE3]]}