[PATCH] D108375: [GlobalISel] Support ConstantAsMetadata in IRTranslator
Aleksandr Bezzubikov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 15 16:58:20 PDT 2021
zuban32 updated this revision to Diff 372840.
zuban32 added a comment.
Herald added subscribers: kerbowa, nhaehnle, jvesely.
Rebased, added a test.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D108375/new/
https://reviews.llvm.org/D108375
Files:
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-metadata.ll
Index: llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-metadata.ll
===================================================================
--- llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-metadata.ll
+++ llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-metadata.ll
@@ -7,12 +7,17 @@
; CHECK: bb.1 (%ir-block.0):
; CHECK: liveins: $sgpr30_sgpr31
; CHECK: [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
- ; CHECK: [[INT:%[0-9]+]]:_(s32) = G_INTRINSIC intrinsic(@llvm.amdgcn.reloc.constant), !0
- ; CHECK: $vgpr0 = COPY [[INT]](s32)
+ ; CHECK: [[INT0:%[0-9]+]]:_(s32) = G_INTRINSIC intrinsic(@llvm.amdgcn.reloc.constant), !0
+ ; We cannot have any specific metadata check here as ConstantAsMetadata is printed as <raw_ptr_val>
+ ; CHECK: [[INT1:%[0-9]+]]:_(s32) = G_INTRINSIC intrinsic(@llvm.amdgcn.reloc.constant), <0x{{[0-9a-f]+}}>
+ ; CHECK: [[SUM:%[0-9]+]]:_(s32) = G_ADD [[INT0]], [[INT1]]
+ ; CHECK: $vgpr0 = COPY [[SUM]](s32)
; CHECK: [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
; CHECK: S_SETPC_B64_return [[COPY1]], implicit $vgpr0
- %val = call i32 @llvm.amdgcn.reloc.constant(metadata !0)
- ret i32 %val
+ %val0 = call i32 @llvm.amdgcn.reloc.constant(metadata !0)
+ %val1 = call i32 @llvm.amdgcn.reloc.constant(metadata i32 4)
+ %res = add i32 %val0, %val1
+ ret i32 %res
}
declare i32 @llvm.amdgcn.reloc.constant(metadata) #0
Index: llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -2371,10 +2371,15 @@
} else {
MIB.addFPImm(cast<ConstantFP>(Arg.value()));
}
- } else if (auto MD = dyn_cast<MetadataAsValue>(Arg.value())) {
- auto *MDN = dyn_cast<MDNode>(MD->getMetadata());
- if (!MDN) // This was probably an MDString.
- return false;
+ } else if (auto *MDVal = dyn_cast<MetadataAsValue>(Arg.value())) {
+ auto *MD = MDVal->getMetadata();
+ auto *MDN = dyn_cast<MDNode>(MD);
+ if (!MDN) {
+ if (auto *ConstMD = dyn_cast<ConstantAsMetadata>(MD))
+ MDN = MDNode::get(MF->getFunction().getContext(), ConstMD);
+ else // This was probably an MDString.
+ return false;
+ }
MIB.addMetadata(MDN);
} else {
ArrayRef<Register> VRegs = getOrCreateVRegs(*Arg.value());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108375.372840.patch
Type: text/x-patch
Size: 2406 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210915/441e4463/attachment.bin>
More information about the llvm-commits
mailing list