[PATCH] D72636: Cancelling out G_MERGE_VALUES/G_UNMERGE pairs sometimes needs a copy
Daniel Sanders via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 13 11:59:46 PST 2020
dsanders created this revision.
dsanders added reviewers: bogner, aditya_nandakumar, paquette, arsenm.
Herald added a subscriber: wdng.
Herald added a project: LLVM.
Specifically, if there are register class constraints they must be
preserved. If there is at least one, then we must emit a copy unless both
vregs have the same constraint.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D72636
Files:
llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
Index: llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
===================================================================
--- llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
+++ llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
@@ -396,7 +396,15 @@
for (unsigned Idx = 0; Idx < NumDefs; ++Idx) {
Register NewDef = MergeI->getOperand(Idx + 1).getReg();
- MRI.replaceRegWith(MI.getOperand(Idx).getReg(), NewDef);
+ Register OldReg = MI.getOperand(Idx).getReg();
+ auto *OldRC = MRI.getRegClassOrNull(OldReg);
+ auto *NewRC = MRI.getRegClassOrNull(NewDef);
+ if ((!OldRC && !NewRC) || (OldRC && NewRC && OldRC == NewRC))
+ MRI.replaceRegWith(OldReg, NewDef);
+ else {
+ Builder.setInstr(MI);
+ Builder.buildInstr(TargetOpcode::COPY, {OldReg}, {NewDef});
+ }
UpdatedDefs.push_back(NewDef);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72636.237745.patch
Type: text/x-patch
Size: 964 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200113/ff5db0d5/attachment.bin>
More information about the llvm-commits
mailing list